plugin.video.torrenter/resources/searchers/RiperAM.py

145 lines
12 KiB
Python
Raw Normal View History

2015-01-09 14:11:21 +03:00
# -*- coding: utf-8 -*-
'''
Torrenter plugin for XBMC
Copyright (C) 2012 Vadim Skorba
vadim.skorba@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import urllib
import re
import sys
import SearcherABC
class RiperAM(SearcherABC.SearcherABC):
'''
Weight of source with this searcher provided.
Will be multiplied on default weight.
Default weight is seeds number
'''
sourceWeight = 1
'''
Relative (from root directory of plugin) path to image
will shown as source image at result listing
'''
searchIcon = '/resources/searchers/icons/RiperAM.png'
'''
Flag indicates is this source - magnet links source or not.
Used for filtration of sources in case of old library (setting selected).
Old libraries won't to convert magnet as torrent file to the storage
'''
@property
def isMagnetLinkSource(self):
return True
'''
Main method should be implemented for search process.
Receives keyword and have to return dictionary of proper tuples:
filesList.append((
int(weight),# Calculated global weight of sources
int(seeds),# Seeds count
str(title),# Title will be shown
str(link),# Link to the torrent/magnet
str(image),# Path/URL to image shown at the list
))
'''
def search(self, keyword):
filesList = []
2015-06-03 22:45:54 +03:00
url = "http://www.riper.am/search.php?sr=topics&sf=titleonly&fp=1&tracker_search=torrent&keywords=" + urllib.quote_plus(keyword)
#keyword) + "&terms=all&fp=1&author=&fid%5B%5D=238&fid%5B%5D=368&fid%5B%5D=425&fid%5B%5D=50&fid%5B%5D=52&fid%5B%5D=424&fid%5B%5D=51&fid%5B%5D=371&fid%5B%5D=251&fid%5B%5D=349&fid%5B%5D=350&fid%5B%5D=351&fid%5B%5D=352&fid%5B%5D=239&fid%5B%5D=420&fid%5B%5D=12&fid%5B%5D=13&fid%5B%5D=423&fid%5B%5D=16&fid%5B%5D=17&fid%5B%5D=18&fid%5B%5D=46&fid%5B%5D=15&fid%5B%5D=14&fid%5B%5D=240&fid%5B%5D=19&fid%5B%5D=216&fid%5B%5D=363&fid%5B%5D=118&fid%5B%5D=153&fid%5B%5D=632&fid%5B%5D=319&fid%5B%5D=183&fid%5B%5D=178&fid%5B%5D=364&fid%5B%5D=267&fid%5B%5D=365&fid%5B%5D=353&fid%5B%5D=710&fid%5B%5D=266&fid%5B%5D=268&fid%5B%5D=160&fid%5B%5D=20&fid%5B%5D=210&fid%5B%5D=969&fid%5B%5D=707&fid%5B%5D=685&fid%5B%5D=1004&fid%5B%5D=1028&fid%5B%5D=711&fid%5B%5D=736&fid%5B%5D=550&fid%5B%5D=601&fid%5B%5D=979&fid%5B%5D=692&fid%5B%5D=1038&fid%5B%5D=48&fid%5B%5D=555&fid%5B%5D=781&fid%5B%5D=790&fid%5B%5D=791&fid%5B%5D=509&fid%5B%5D=803&fid%5B%5D=994&fid%5B%5D=735&fid%5B%5D=992&fid%5B%5D=748&fid%5B%5D=771&fid%5B%5D=656&fid%5B%5D=501&fid%5B%5D=980&fid%5B%5D=1002&fid%5B%5D=964&fid%5B%5D=746&fid%5B%5D=976&fid%5B%5D=958&fid%5B%5D=719&fid%5B%5D=1006&fid%5B%5D=798&fid%5B%5D=768&fid%5B%5D=984&fid%5B%5D=732&fid%5B%5D=376&fid%5B%5D=152&fid%5B%5D=628&fid%5B%5D=563&fid%5B%5D=565&fid%5B%5D=562&fid%5B%5D=797&fid%5B%5D=983&fid%5B%5D=774&fid%5B%5D=989&fid%5B%5D=354&fid%5B%5D=640&fid%5B%5D=684&fid%5B%5D=1024&fid%5B%5D=961&fid%5B%5D=639&fid%5B%5D=703&fid%5B%5D=1013&fid%5B%5D=1040&fid%5B%5D=131&fid%5B%5D=727&fid%5B%5D=1015&fid%5B%5D=641&fid%5B%5D=686&fid%5B%5D=644&fid%5B%5D=760&fid%5B%5D=373&fid%5B%5D=654&fid%5B%5D=779&fid%5B%5D=372&fid%5B%5D=957&fid%5B%5D=1016&fid%5B%5D=766&fid%5B%5D=687&fid%5B%5D=991&fid%5B%5D=272&fid%5B%5D=761&fid%5B%5D=653&fid%5B%5D=551&fid%5B%5D=645&fid%5B%5D=986&fid%5B%5D=795&fid%5B%5D=750&fid%5B%5D=635&fid%5B%5D=962&fid%5B%5D=683&fid%5B%5D=708&fid%5B%5D=978&fid%5B%5D=997&fid%5B%5D=1026&fid%5B%5D=787&fid%5B%5D=773&fid%5B%5D=671&fid%5B%5D=1019&fid%5B%5D=1023&fid%5B%5D=225&fid%5B%5D=799&fid%5B%5D=788&fid%5B%5D=680&fid%5B%5D=794&fid%5B%5D=972&fid%5B%5D=359&fid%5B%5D=756&fid%5B%5D=1000&fid%5B%5D=552&fid%5B%5D=706&fid%5B%5D=1003&fid%5B%5D=630&fid%5B%5D=966&fid%5B%5D=226&fid%5B%5D=960&fid%5B%5D=995&fid%5B%5D=699&fid%5B%5D=714&fid%5B%5D=755&fid%5B%5D=358&fid%5B%5D=642&fid%5B%5D=1039&fid%5B%5D=360&fid%5B%5D=981&fid%5B%5D=977&fid%5B%5D=681&fid%5B%5D=675&fid%5B%5D=988&fid%5B%5D=355&fid%5B%5D=1025&fid%5B%5D=973&fid%5B%5D=445&fid%5B%5D=678&fid%5B%5D=970&fid%5B%5D=733&fid%5B%5D=505&fid%5B%5D=646&fid%5B%5D=1031&fid%5B%5D=990&fid%5B%5D=691&fid%5B%5D=1033&fid%5B%5D=690&fid%5B%5D=1030&fid%5B%5D=804&fid%5B%5D=780&fid%5B%5D=778&fid%5B%5D=805&fid%5B%5D=500&fid%5B%5D=743&fid%5B%5D=21&fid%5B%5D=185&fid%5B%5D=463&fid%5B%5D=633&fid%5B%5D=772&fid%5B%5D=606&fid%5B%5D=789&fid%5B%5D=162&fid%5B%5D=151&fid%5B%5D=22&fid%5B%5D=198&fid%5B%5D=232&fid%5B%5D=245&fid%5B%5D=246&fid%5B%5D=592&fid%5B%5D=594&fid%5B%5D=591&fid%5B%5D=595&fid%5B%5D=596&fid%5B%5D=597&fid%5B%5D=242&fid%5B%5D=164&fid%5B%5D=167&fid%5B%5D=165&fid%5B%5D=166&fid%5B%5D=241&fid%5B%5D=23&fid%5B%5D=446&fid%5B%5D=366&fid%5B%5D=553&fid%5B%5D=693&fid%5B%5D=229&fid%5B%5D=967&fid%5B%5D=975&fid%5B%5D=491&fid%5B%5D=516&fid%5B%5D=1032&fid%5B%5D=528&fid%5B%5D=577&fid%5B%5D=770&fid%5B%5D=478&fid%5B%5D=534&fid%5B%5D=540&fid%5B%5D=674&fid%5B%5D=1010&fid%5B%5D=471&fid%5B%5D=593&fid%5B%5D=538&fid%5B%5D=744&fid%5B%5D=561&fid%5B%5D=526&fid%5B%5D=605&fid%5B%5D=713&fid%5B%5D=344&fid%5B%5D=459&fid%5B%5D=959&fid%5B%5D=191&fid%5B%5D=519&fid%5B%5D=527&fid%5B%5D=460&fid%5B%5D=190&fid%5B%5D=659&fid%5B%5D=477&fid%5B%5D=255&fid%5B%5D=256&fid%5B%5D=634&fid%5B%5D=574&fid%5B%5D=764&fid%5B%5D=637&fid%5B%5D=33&fid%5B%5D=270&fid%5B%5D=450&fid%5B%5D=514&fid%5B%5D=658&fid%5B%5D=209&fid%5B%5D=530&fid%5B%5D=800&fid%5B%5D=475&fid%5B%5D=517&fid%5B%5D=548&fid%5B%5D=740&fid%5B%5D=741&fid%5B%5D=737&fid%5B%5D=587&fid%5B%5D=718&fid%5B%5D=1011&fid%5B%5D=456&fid%5B%5D=682&fid%5B%5D=469&fid%5B%5D=479&fid%5B%5D=480&fid%5B%5D=696&fid%5B%5D=996&fid%5B%5D=189&fid%5B%5D=1027&fid%5B%5D=541&fid%5B%5D=785&fid%5B%5D=668&fid%5B%5D=560&fid%5B%5D=752&fid%5B%5D=533&fid%5B%5
2015-01-09 14:11:21 +03:00
headers = [('User-Agent',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36'),
('Referer', 'http://www.riper.am/'), ]
#('Cookie',str(sys.modules[ "__main__" ].__settings__.getSetting("rutor-auth")))]
response = self.makeRequest(url, headers=headers)
if None != response and 0 < len(response):
2015-06-03 22:45:54 +03:00
self.cookieJar.save(ignore_discard=True)
self.check_login(response)
print response
2015-01-09 14:11:21 +03:00
dat = re.compile(
r'<a href="\.(/download/.+?)".+?<font size="3pt">(.+?)</font></a>.+?Размер: <b>(.+?)</b>.+?" title="Сидеров"><b>(\d+?)</b>.+?title="Личеров"><b>(\d+?)</b></span></dd>',
re.DOTALL | re.I).findall(response)
if dat:
for (link, title, size, seeds, leechers) in dat:
torrentTitle = title
size = self.stripHtml(size)
link = 'http://www.riper.am' + link
image = sys.modules["__main__"].__root__ + self.searchIcon
filesList.append((
int(int(self.sourceWeight) * int(seeds)),
int(seeds), int(leechers), size,
self.unescape(self.stripHtml(torrentTitle)),
self.__class__.__name__ + '::' + link,
image,
))
return filesList
def getTorrentFile(self, label):
if re.search('/download/', label):
return label
elif label.startswith('http'):
return self.getByLink(label)
else:
return self.getByLabel(label)
def getByLink(self, label):
response = self.makeRequest(label)
if None != response and 0 < len(response):
link = re.compile('(/download/file\.php\?id=\d+)',
re.DOTALL | re.MULTILINE).findall(response)[0]
2015-06-03 22:45:54 +03:00
return 'http://www.riper.am' + link
def login(self):
data = {
'password': 'torrenter',
'username': 'torrenter-plugin',
'remember':'1',
'autologin':'on',
#'redirect':'./ucp.php?mode=login',
'sid':'593f325609a91bf52ed8c424cd0ef270',
'redirect':'index.php',
'login':urllib.quote_plus('Вход')
}
headers = [('User-Agent',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36'),
('Referer', 'http://www.riper.am/'), ]
x=self.makeRequest(
'http://www.riper.am/ucp.php?mode=login',data=data, headers=headers)
if re.search('{"status":"OK"',x):
print 'LOGGED RiperAM'
self.cookieJar.save(ignore_discard=True)
for cookie in self.cookieJar:
if cookie.name == 'phpbb_63646738_sid' and cookie.domain=='.riper.am':
return 'phpbb_63646738_sid=' + cookie.value
return False
def check_login(self, response=None):
if None != response and 0 < len(response):
#print response
if re.compile('ucp.php\?mode=login" title="Вход"').search(response):
print 'RiperAM Not logged!'
self.login()
return False
print 'RiperAM logged!'
return True