Refactor code to be PEP8 compliant

This commit is contained in:
Chocobo1 2018-09-16 14:22:10 +08:00
parent 14bdd68899
commit 56092813ce
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
14 changed files with 268 additions and 203 deletions

View File

@ -1,6 +1,6 @@
#VERSION: 1.03
#AUTHORS: Charles Worthing
#CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
#VERSION: 1.04
# AUTHORS: Charles Worthing
# CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@ -27,10 +27,11 @@
# POSSIBILITY OF SUCH DAMAGE.
from HTMLParser import HTMLParser
#qBt
# qBt
from novaprinter import prettyPrinter
from helpers import download_file, retrieve_url
class btdb(object):
""" Search engine class """
url = 'https://btdb.to'
@ -46,9 +47,9 @@ class btdb(object):
HTMLParser.__init__(self)
self.results = results
self.url = url
self.current_item = {} # One torrent result
self.current_item = {} # One torrent result
self.add_query = True
self.torrent_info_index = 0 # Count of the meta data encountered
self.torrent_info_index = 0 # Count of the meta data encountered
self.torrent_info_array = []
self.meta_data_grabbing = 0
self.meta_data_array = []
@ -85,15 +86,15 @@ class btdb(object):
if link.startswith("magnet:"):
self.magnet_link = link
def handle_endtag(self, tag):
def handle_endtag(self, tag):
if tag == "script":
return
if tag == "div":
if self.meta_data_grabbing > 0:
self.torrent_no_files = self.meta_data_array[2] # Not used
self.torrent_date_added = self.meta_data_array[4] # Not used
self.torrent_popularity = self.meta_data_array[6] # Not used
self.torrent_no_files = self.meta_data_array[2] # Not used
self.torrent_date_added = self.meta_data_array[4] # Not used
self.torrent_popularity = self.meta_data_array[6] # Not used
self.current_item["size"] = self.meta_data_array[0]
self.current_item["name"] = self.torrent_name

View File

@ -1,6 +1,6 @@
#VERSION: 1.00
#AUTHORS: nindogo
#CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
#VERSION: 1.01
# AUTHORS: nindogo
# CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
try:
# python3
@ -13,6 +13,7 @@ except ImportError:
from novaprinter import prettyPrinter
from helpers import retrieve_url
class eztv(object):
name = "EZTV"
url = 'https://eztv.ag'
@ -45,13 +46,16 @@ class eztv(object):
self.current_item['desc_link'] = self.url + params.get('href')
self.current_item['name'] = params.get('title').split(' (')[0]
if tag == self.TD and params.get('class') == 'forum_thread_post_end' and params.get('align') == 'center':
if (tag == self.TD
and params.get('class') == 'forum_thread_post_end'
and params.get('align') == 'center'):
prettyPrinter(self.current_item)
self.in_table_row = False
def handle_data(self, data):
data = data.replace(',', '')
if self.in_table_row and (data.endswith('MB') or data.endswith('GB') or data.endswith('KB')):
if (self.in_table_row
and (data.endswith('MB') or data.endswith('GB') or data.endswith('KB'))):
self.current_item['size'] = data
if self.in_table_row and (data.isalnum() or data == '-'):
@ -65,13 +69,14 @@ class eztv(object):
self.in_table_row = False
def search(self, what, cat='all'):
query = self.url + '/search/' + what.replace('%20','-')
query = self.url + '/search/' + what.replace('%20', '-')
eztv_html = retrieve_url(query)
eztv_parser = self.MyHtmlParser(self.url)
eztv_parser.feed(eztv_html)
eztv_parser.close()
if __name__ == '__main__':
eztv_se = eztv()
eztv_se.search('Acre', 'all')

View File

@ -1,6 +1,6 @@
#VERSION: 2.02
#AUTHORS: Christophe Dumez (chris@qbittorrent.org)
# Douman (custparasite@gmx.se)
#VERSION: 2.03
# AUTHORS: Christophe Dumez (chris@qbittorrent.org)
# Douman (custparasite@gmx.se)
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@ -26,16 +26,17 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from novaprinter import prettyPrinter
from helpers import retrieve_url, download_file
from HTMLParser import HTMLParser
from re import compile as re_compile
class legittorrents(object):
url = 'http://www.legittorrents.info'
name = 'Legit Torrents'
supported_categories = {'all': '0', 'movies': '1', 'tv': '13', 'music': '2', 'games': '3', 'anime': '5', 'books': '6'}
supported_categories = {'all': '0', 'movies': '1', 'tv': '13',
'music': '2', 'games': '3', 'anime': '5', 'books': '6'}
def download_torrent(self, info):
print(download_file(info))
@ -55,13 +56,14 @@ class legittorrents(object):
if tag == "a":
link = params["href"]
if link.startswith("index") and "title" in params:
#description link
# description link
self.current_item["name"] = params["title"][14:]
self.current_item["desc_link"] = "/".join((self.url, link))
elif link.startswith("download"):
self.current_item["link"] = "/".join((self.url, link))
elif tag == "td":
if "width" in params and params["width"] == "30" and not "leech" in self.current_item:
if ("width" in params and params["width"] == "30"
and "leech" not in self.current_item):
self.save_item_key = "leech" if "seeds" in self.current_item else "seeds"
elif tag == "tr":
@ -84,11 +86,12 @@ class legittorrents(object):
def search(self, what, cat='all'):
""" Performs search """
query = "".join((self.url, "/index.php?page=torrents&search=", what, "&category=", self.supported_categories.get(cat, '0'), "&active=1"))
query = "".join((self.url, "/index.php?page=torrents&search=", what, "&category=",
self.supported_categories.get(cat, '0'), "&active=1"))
get_table = re_compile('(?s)<table\sclass="lista".*>(.*)</table>')
get_table = re_compile(r'(?s)<table\sclass="lista".*>(.*)</table>')
data = get_table.search(retrieve_url(query)).group(0)
#extract first ten pages of next results
# extract first ten pages of next results
next_pages = re_compile('(?m)<option value="(.*)">[0-9]+</option>')
next_pages = ["".join((self.url, page)) for page in next_pages.findall(data)[:10]]

View File

@ -1,8 +1,8 @@
#VERSION: 2.15
#AUTHORS: Fabien Devaux (fab@gnux.info)
#CONTRIBUTORS: Christophe Dumez (chris@qbittorrent.org)
# Arthur (custparasite@gmx.se)
# Diego de las Heras (ngosang@hotmail.es)
#VERSION: 2.16
# AUTHORS: Fabien Devaux (fab@gnux.info)
# CONTRIBUTORS: Christophe Dumez (chris@qbittorrent.org)
# Arthur (custparasite@gmx.se)
# Diego de las Heras (ngosang@hotmail.es)
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@ -29,15 +29,17 @@
# POSSIBILITY OF SUCH DAMAGE.
from HTMLParser import HTMLParser
#qBt
# qBt
from novaprinter import prettyPrinter
from helpers import download_file, retrieve_url
class piratebay(object):
""" Search engine class """
url = 'https://thepiratebay.org'
name = 'The Pirate Bay'
supported_categories = {'all': '0', 'music': '100', 'movies': '200', 'games': '400', 'software': '300'}
supported_categories = {'all': '0', 'music': '100', 'movies': '200',
'games': '400', 'software': '300'}
def download_torrent(self, info):
""" Downloader """
@ -51,7 +53,7 @@ class piratebay(object):
self.url = url
self.current_item = None
self.save_item = None
self.result_table = False #table with results is found
self.result_table = False # table with results is found
self.result_tbody = False
self.add_query = True
self.result_query = False
@ -93,12 +95,14 @@ class piratebay(object):
def handle_starttag(self, tag, attrs):
""" Parser's start tag handler """
if self.current_item:
dispatcher = getattr(self, "_".join(("handle_start_tag", tag)), self.handle_start_tag_default)
dispatcher = getattr(self,
"_".join(("handle_start_tag", tag)),
self.handle_start_tag_default)
dispatcher(attrs)
elif self.result_tbody:
if tag == "tr":
self.current_item = {"engine_url" : self.url}
self.current_item = {"engine_url": self.url}
elif tag == "table":
self.result_table = "searchResult" == attrs[0][1]
@ -141,7 +145,8 @@ class piratebay(object):
temp_data = data.split()
if "Size" in temp_data:
indx = temp_data.index("Size")
self.current_item[self.save_item] = temp_data[indx + 1] + " " + temp_data[indx + 2]
self.current_item[self.save_item] = (temp_data[indx + 1] + " "
+ temp_data[indx + 2])
elif self.save_item == "name":
# names with special characters like '&' are splitted in several pieces
@ -153,10 +158,9 @@ class piratebay(object):
self.current_item[self.save_item] = data
self.save_item = None
def search(self, what, cat='all'):
""" Performs search """
#prepare query. 7 is filtering by seeders
# prepare query. 7 is filtering by seeders
cat = cat.lower()
query = "/".join((self.url, "search", what, "0", "7", self.supported_categories[cat]))

View File

@ -1,23 +1,24 @@
#VERSION: 2.0
#AUTHORS: Douman (custparasite@gmx.se)
#CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
#VERSION: 2.1
# AUTHORS: Douman (custparasite@gmx.se)
# CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
from novaprinter import prettyPrinter
from helpers import retrieve_url, download_file
from re import compile as re_compile
from HTMLParser import HTMLParser
class torlock(object):
url = "https://www.torlock.com"
name = "TorLock"
supported_categories = {'all' : 'all',
'anime' : 'anime',
'software' : 'software',
'games' : 'game',
'movies' : 'movie',
'music' : 'music',
'tv' : 'television',
'books' : 'ebooks'}
supported_categories = {'all': 'all',
'anime': 'anime',
'software': 'software',
'games': 'game',
'movies': 'movie',
'music': 'music',
'tv': 'television',
'books': 'ebooks'}
def download_torrent(self, info):
print(download_file(info))
@ -27,14 +28,14 @@ class torlock(object):
def __init__(self, url):
HTMLParser.__init__(self)
self.url = url
self.article_found = False #true when <article> with results is found
self.article_found = False # true when <article> with results is found
self.item_found = False
self.item_bad = False #set to True for malicious links
self.current_item = None #dict for found item
self.item_name = None #key's name in current_item dict
self.parser_class = {"ts" : "size",
"tul" : "seeds",
"tdl" : "leech"}
self.item_bad = False # set to True for malicious links
self.current_item = None # dict for found item
self.item_name = None # key's name in current_item dict
self.parser_class = {"ts": "size",
"tul": "seeds",
"tdl": "leech"}
def handle_starttag(self, tag, attrs):
params = dict(attrs)
@ -50,7 +51,8 @@ class torlock(object):
link = params["href"]
if link.startswith("/torrent"):
self.current_item["desc_link"] = "".join((self.url, link))
self.current_item["link"] = "".join((self.url, "/tor/", link.split('/')[2], ".torrent"))
self.current_item["link"] = "".join((self.url, "/tor/",
link.split('/')[2], ".torrent"))
self.current_item["engine_url"] = self.url
self.item_found = True
self.item_name = "name"
@ -81,13 +83,15 @@ class torlock(object):
query = query.replace("%20", "-")
parser = self.MyHtmlParser(self.url)
page = "".join((self.url, "/", self.supported_categories[cat], "/torrents/", query, ".html?sort=seeds&page=1"))
page = "".join((self.url, "/", self.supported_categories[cat],
"/torrents/", query, ".html?sort=seeds&page=1"))
html = retrieve_url(page)
parser.feed(html)
counter = 1
additional_pages = re_compile("/{0}/torrents/{1}.html\?sort=seeds&page=[0-9]+".format(self.supported_categories[cat], query))
list_searches = additional_pages.findall(html)[:-1] #last link is next(i.e. second)
additional_pages = re_compile(r"/{0}/torrents/{1}.html\?sort=seeds&page=[0-9]+"
.format(self.supported_categories[cat], query))
list_searches = additional_pages.findall(html)[:-1] # last link is next(i.e. second)
for page in map(lambda link: "".join((self.url, link)), list_searches):
html = retrieve_url(page)
parser.feed(html)

View File

@ -1,6 +1,6 @@
btdb: 1.03
eztv: 1.00
legittorrents: 2.02
piratebay: 2.15
torlock: 2.0
zooqle: 1.12
btdb: 1.04
eztv: 1.01
legittorrents: 2.03
piratebay: 2.16
torlock: 2.1
zooqle: 1.13

View File

@ -1,6 +1,6 @@
#VERSION: 1.12
#AUTHORS: Kanishk Singh (https://github.com/ArionMiles/)
#CONTRIBUTORS: affaff (https://github.com/affaff)
#VERSION: 1.13
# AUTHORS: Kanishk Singh (https://github.com/ArionMiles/)
# CONTRIBUTORS: affaff (https://github.com/affaff)
# Copyright (c) 2017 Kanishk Singh
@ -25,11 +25,12 @@
from xml.dom import minidom
from novaprinter import prettyPrinter
user_agent = 'Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0'
headers = {'User-Agent': user_agent}
from io import StringIO
import gzip
user_agent = 'Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0'
headers = {'User-Agent': user_agent}
try:
from urllib2 import urlopen, Request, URLError
except ImportError:
@ -38,7 +39,7 @@ except ImportError:
def retrieve_url_nodecode(url):
""" Return the content of the url page as a string """
req = Request(url, headers = headers)
req = Request(url, headers=headers)
try:
response = urlopen(req)
except URLError as errno:
@ -56,50 +57,63 @@ def retrieve_url_nodecode(url):
return dat
return dat
class zooqle(object):
""" Search engine class """
url = 'https://zooqle.com'
name = 'Zooqle'
supported_categories = {'all' : 'all',
'movies' : 'Movies',
'tv' : 'TV',
'music' : 'Music',
'games' : 'Games',
'anime' : 'Anime',
'software' : 'Apps',
'books' : 'Books'}
supported_categories = {'all': 'all',
'movies': 'Movies',
'tv': 'TV',
'music': 'Music',
'games': 'Games',
'anime': 'Anime',
'software': 'Apps',
'books': 'Books'}
def search(self, what, cat="all"):
""" Performs search """
page = 1
while page < 11:
query = "".join((self.url, "/search?q=", what, "+category%3A", self.supported_categories[cat], "&fmt=rss"))
if( page>1 ):
query = query + "&pg=" + str (page)
query = "".join((self.url, "/search?q=", what,
"+category%3A", self.supported_categories[cat], "&fmt=rss"))
if page > 1:
query = query + "&pg=" + str(page)
response = retrieve_url_nodecode(query)
xmldoc = minidom.parseString(response)
itemlist = xmldoc.getElementsByTagName('item')
if( len(itemlist ) ==0):
if len(itemlist) == 0:
return
for item in itemlist:
zooqle_dict = zooqle_dict = {"engine_url" : self.url}
zooqle_dict['name'] = item.getElementsByTagName('title')[0].childNodes[0].data
zooqle_dict["size"] = item.getElementsByTagName('enclosure')[0].attributes['length'].childNodes[0].data
if( zooqle_dict["size"]=='0'):
zooqle_dict["link"] = item.getElementsByTagName('torrent:magnetURI')[0].childNodes[0].data
zooqle_dict = zooqle_dict = {"engine_url": self.url}
zooqle_dict['name'] = (item.getElementsByTagName('title')[0]
.childNodes[0].data)
zooqle_dict["size"] = (item.getElementsByTagName('enclosure')[0]
.attributes['length'].childNodes[0].data)
if zooqle_dict["size"] == '0':
zooqle_dict["link"] = (item.getElementsByTagName('torrent:magnetURI')[0]
.childNodes[0].data)
else:
zooqle_dict["link"] = item.getElementsByTagName('enclosure')[0].attributes['url'].value
zooqle_dict["desc_link"] = item.getElementsByTagName('link')[0].childNodes[0].data
zooqle_dict["leech"] = item.getElementsByTagName('torrent:peers')[0].childNodes[0].data
zooqle_dict["link"] = (item.getElementsByTagName('enclosure')[0]
.attributes['url'].value)
zooqle_dict["desc_link"] = (item.getElementsByTagName('link')[0]
.childNodes[0].data)
zooqle_dict["leech"] = (item.getElementsByTagName('torrent:peers')[0]
.childNodes[0].data)
if not zooqle_dict["leech"].isdigit():
zooqle_dict["leech"] = ''
zooqle_dict["seeds"] = item.getElementsByTagName('torrent:seeds')[0].childNodes[0].data
zooqle_dict["seeds"] = (item.getElementsByTagName('torrent:seeds')[0]
.childNodes[0].data)
if not zooqle_dict["seeds"].isdigit():
zooqle_dict["seeds"] = ''
prettyPrinter(zooqle_dict)
totalResultVal = xmldoc.getElementsByTagName('opensearch:totalResults')[0].childNodes[0].data
startIndex = xmldoc.getElementsByTagName('opensearch:startIndex')[0].childNodes[0].data
itemsPerPage = xmldoc.getElementsByTagName('opensearch:itemsPerPage')[0].childNodes[0].data
if( ( int(startIndex) + int(itemsPerPage) > int( totalResultVal ))):
totalResultVal = (xmldoc.getElementsByTagName('opensearch:totalResults')[0]
.childNodes[0].data)
startIndex = (xmldoc.getElementsByTagName('opensearch:startIndex')[0]
.childNodes[0].data)
itemsPerPage = (xmldoc.getElementsByTagName('opensearch:itemsPerPage')[0]
.childNodes[0].data)
if (int(startIndex) + int(itemsPerPage)) > int(totalResultVal):
return
page += 1
return

View File

@ -1,6 +1,6 @@
#VERSION: 1.03
#AUTHORS: Charles Worthing
#CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
#VERSION: 1.04
# AUTHORS: Charles Worthing
# CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@ -27,10 +27,11 @@
# POSSIBILITY OF SUCH DAMAGE.
from html.parser import HTMLParser
#qBt
# qBt
from novaprinter import prettyPrinter
from helpers import download_file, retrieve_url
class btdb(object):
""" Search engine class """
url = 'https://btdb.to'
@ -46,9 +47,9 @@ class btdb(object):
HTMLParser.__init__(self)
self.results = results
self.url = url
self.current_item = {} # One torrent result
self.current_item = {} # One torrent result
self.add_query = True
self.torrent_info_index = 0 # Count of the meta data encountered
self.torrent_info_index = 0 # Count of the meta data encountered
self.torrent_info_array = []
self.meta_data_grabbing = 0
self.meta_data_array = []
@ -85,15 +86,14 @@ class btdb(object):
if link.startswith("magnet:"):
self.magnet_link = link
def handle_endtag(self, tag):
def handle_endtag(self, tag):
if tag == "script":
return
if tag == "div":
if self.meta_data_grabbing > 0:
self.torrent_no_files = self.meta_data_array[2] # Not used
self.torrent_date_added = self.meta_data_array[4] # Not used
self.torrent_popularity = self.meta_data_array[6] # Not used
self.torrent_no_files = self.meta_data_array[2] # Not used
self.torrent_date_added = self.meta_data_array[4] # Not used
self.torrent_popularity = self.meta_data_array[6] # Not used
self.current_item["size"] = self.meta_data_array[0]
self.current_item["name"] = self.torrent_name

View File

@ -1,6 +1,6 @@
#VERSION: 1.00
#AUTHORS: nindogo
#CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
#VERSION: 1.01
# AUTHORS: nindogo
# CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
try:
# python3
@ -13,6 +13,7 @@ except ImportError:
from novaprinter import prettyPrinter
from helpers import retrieve_url
class eztv(object):
name = "EZTV"
url = 'https://eztv.ag'
@ -32,26 +33,32 @@ class eztv(object):
def handle_starttag(self, tag, attrs):
params = dict(attrs)
if (params.get('class') == 'forum_header_border' and params.get('name') == 'hover'):
if (params.get('class') == 'forum_header_border'
and params.get('name') == 'hover'):
self.in_table_row = True
self.current_item = {}
self.current_item['leech'] = -1
self.current_item['engine_url'] = self.url
if tag == self.A and self.in_table_row and params.get('class') == 'magnet':
if (tag == self.A
and self.in_table_row and params.get('class') == 'magnet'):
self.current_item['link'] = params.get('href')
if tag == self.A and self.in_table_row and params.get('class') == 'epinfo':
if (tag == self.A
and self.in_table_row and params.get('class') == 'epinfo'):
self.current_item['desc_link'] = self.url + params.get('href')
self.current_item['name'] = params.get('title').split(' (')[0]
if tag == self.TD and params.get('class') == 'forum_thread_post_end' and params.get('align') == 'center':
if (tag == self.TD
and params.get('class') == 'forum_thread_post_end'
and params.get('align') == 'center'):
prettyPrinter(self.current_item)
self.in_table_row = False
def handle_data(self, data):
data = data.replace(',', '')
if self.in_table_row and (data.endswith('MB') or data.endswith('GB') or data.endswith('KB')):
if (self.in_table_row
and (data.endswith('MB') or data.endswith('GB') or data.endswith('KB'))):
self.current_item['size'] = data
if self.in_table_row and (data.isalnum() or data == '-'):
@ -65,13 +72,14 @@ class eztv(object):
self.in_table_row = False
def search(self, what, cat='all'):
query = self.url + '/search/' + what.replace('%20','-')
query = self.url + '/search/' + what.replace('%20', '-')
eztv_html = retrieve_url(query)
eztv_parser = self.MyHtmlParser(self.url)
eztv_parser.feed(eztv_html)
eztv_parser.close()
if __name__ == '__main__':
eztv_se = eztv()
eztv_se.search('Acre', 'all')

View File

@ -1,6 +1,6 @@
#VERSION: 2.02
#AUTHORS: Christophe Dumez (chris@qbittorrent.org)
# Douman (custparasite@gmx.se)
#VERSION: 2.03
# AUTHORS: Christophe Dumez (chris@qbittorrent.org)
# Douman (custparasite@gmx.se)
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@ -26,16 +26,18 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from novaprinter import prettyPrinter
from helpers import retrieve_url, download_file
from html.parser import HTMLParser
from re import compile as re_compile
class legittorrents(object):
url = 'http://www.legittorrents.info'
name = 'Legit Torrents'
supported_categories = {'all': '0', 'movies': '1', 'tv': '13', 'music': '2', 'games': '3', 'anime': '5', 'books': '6'}
supported_categories = {'all': '0', 'movies': '1', 'tv': '13',
'music': '2', 'games': '3', 'anime': '5',
'books': '6'}
def download_torrent(self, info):
print(download_file(info))
@ -55,13 +57,14 @@ class legittorrents(object):
if tag == "a":
link = params["href"]
if link.startswith("index") and "title" in params:
#description link
# description link
self.current_item["name"] = params["title"][14:]
self.current_item["desc_link"] = "/".join((self.url, link))
elif link.startswith("download"):
self.current_item["link"] = "/".join((self.url, link))
elif tag == "td":
if "width" in params and params["width"] == "30" and not "leech" in self.current_item:
if ("width" in params
and params["width"] == "30" and "leech" not in self.current_item):
self.save_item_key = "leech" if "seeds" in self.current_item else "seeds"
elif tag == "tr":
@ -84,11 +87,12 @@ class legittorrents(object):
def search(self, what, cat='all'):
""" Performs search """
query = "".join((self.url, "/index.php?page=torrents&search=", what, "&category=", self.supported_categories.get(cat, '0'), "&active=1"))
query = "".join((self.url, "/index.php?page=torrents&search=", what, "&category=",
self.supported_categories.get(cat, '0'), "&active=1"))
get_table = re_compile('(?s)<table\sclass="lista".*>(.*)</table>')
get_table = re_compile(r'(?s)<table\sclass="lista".*>(.*)</table>')
data = get_table.search(retrieve_url(query)).group(0)
#extract first ten pages of next results
# extract first ten pages of next results
next_pages = re_compile('(?m)<option value="(.*)">[0-9]+</option>')
next_pages = ["".join((self.url, page)) for page in next_pages.findall(data)[:10]]

View File

@ -1,8 +1,8 @@
#VERSION: 2.15
#AUTHORS: Fabien Devaux (fab@gnux.info)
#CONTRIBUTORS: Christophe Dumez (chris@qbittorrent.org)
# Arthur (custparasite@gmx.se)
# Diego de las Heras (ngosang@hotmail.es)
#VERSION: 2.16
# AUTHORS: Fabien Devaux (fab@gnux.info)
# CONTRIBUTORS: Christophe Dumez (chris@qbittorrent.org)
# Arthur (custparasite@gmx.se)
# Diego de las Heras (ngosang@hotmail.es)
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@ -29,15 +29,17 @@
# POSSIBILITY OF SUCH DAMAGE.
from html.parser import HTMLParser
#qBt
# qBt
from novaprinter import prettyPrinter
from helpers import download_file, retrieve_url
class piratebay(object):
""" Search engine class """
url = 'https://thepiratebay.org'
name = 'The Pirate Bay'
supported_categories = {'all': '0', 'music': '100', 'movies': '200', 'games': '400', 'software': '300'}
supported_categories = {'all': '0', 'music': '100', 'movies': '200',
'games': '400', 'software': '300'}
def download_torrent(self, info):
""" Downloader """
@ -51,7 +53,7 @@ class piratebay(object):
self.url = url
self.current_item = None
self.save_item = None
self.result_table = False #table with results is found
self.result_table = False # table with results is found
self.result_tbody = False
self.add_query = True
self.result_query = False
@ -93,12 +95,14 @@ class piratebay(object):
def handle_starttag(self, tag, attrs):
""" Parser's start tag handler """
if self.current_item:
dispatcher = getattr(self, "_".join(("handle_start_tag", tag)), self.handle_start_tag_default)
dispatcher = getattr(self,
"_".join(("handle_start_tag", tag)),
self.handle_start_tag_default)
dispatcher(attrs)
elif self.result_tbody:
if tag == "tr":
self.current_item = {"engine_url" : self.url}
self.current_item = {"engine_url": self.url}
elif tag == "table":
self.result_table = "searchResult" == attrs[0][1]
@ -141,7 +145,8 @@ class piratebay(object):
temp_data = data.split()
if "Size" in temp_data:
indx = temp_data.index("Size")
self.current_item[self.save_item] = temp_data[indx + 1] + " " + temp_data[indx + 2]
self.current_item[self.save_item] = (temp_data[indx + 1] + " "
+ temp_data[indx + 2])
elif self.save_item == "name":
# names with special characters like '&' are splitted in several pieces
@ -153,10 +158,9 @@ class piratebay(object):
self.current_item[self.save_item] = data
self.save_item = None
def search(self, what, cat='all'):
""" Performs search """
#prepare query. 7 is filtering by seeders
# prepare query. 7 is filtering by seeders
cat = cat.lower()
query = "/".join((self.url, "search", what, "0", "7", self.supported_categories[cat]))

View File

@ -1,23 +1,24 @@
#VERSION: 2.0
#AUTHORS: Douman (custparasite@gmx.se)
#CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
#VERSION: 2.1
# AUTHORS: Douman (custparasite@gmx.se)
# CONTRIBUTORS: Diego de las Heras (ngosang@hotmail.es)
from novaprinter import prettyPrinter
from helpers import retrieve_url, download_file
from re import compile as re_compile
from html.parser import HTMLParser
class torlock(object):
url = "https://www.torlock.com"
name = "TorLock"
supported_categories = {'all' : 'all',
'anime' : 'anime',
'software' : 'software',
'games' : 'game',
'movies' : 'movie',
'music' : 'music',
'tv' : 'television',
'books' : 'ebooks'}
supported_categories = {'all': 'all',
'anime': 'anime',
'software': 'software',
'games': 'game',
'movies': 'movie',
'music': 'music',
'tv': 'television',
'books': 'ebooks'}
def download_torrent(self, info):
print(download_file(info))
@ -27,14 +28,14 @@ class torlock(object):
def __init__(self, url):
HTMLParser.__init__(self)
self.url = url
self.article_found = False #true when <article> with results is found
self.article_found = False # true when <article> with results is found
self.item_found = False
self.item_bad = False #set to True for malicious links
self.current_item = None #dict for found item
self.item_name = None #key's name in current_item dict
self.parser_class = {"ts" : "size",
"tul" : "seeds",
"tdl" : "leech"}
self.item_bad = False # set to True for malicious links
self.current_item = None # dict for found item
self.item_name = None # key's name in current_item dict
self.parser_class = {"ts": "size",
"tul": "seeds",
"tdl": "leech"}
def handle_starttag(self, tag, attrs):
params = dict(attrs)
@ -50,7 +51,8 @@ class torlock(object):
link = params["href"]
if link.startswith("/torrent"):
self.current_item["desc_link"] = "".join((self.url, link))
self.current_item["link"] = "".join((self.url, "/tor/", link.split('/')[2], ".torrent"))
self.current_item["link"] = "".join((self.url, "/tor/",
link.split('/')[2], ".torrent"))
self.current_item["engine_url"] = self.url
self.item_found = True
self.item_name = "name"
@ -81,13 +83,15 @@ class torlock(object):
query = query.replace("%20", "-")
parser = self.MyHtmlParser(self.url)
page = "".join((self.url, "/", self.supported_categories[cat], "/torrents/", query, ".html?sort=seeds&page=1"))
page = "".join((self.url, "/", self.supported_categories[cat],
"/torrents/", query, ".html?sort=seeds&page=1"))
html = retrieve_url(page)
parser.feed(html)
counter = 1
additional_pages = re_compile("/{0}/torrents/{1}.html\?sort=seeds&page=[0-9]+".format(self.supported_categories[cat], query))
list_searches = additional_pages.findall(html)[:-1] #last link is next(i.e. second)
additional_pages = re_compile(r"/{0}/torrents/{1}.html\?sort=seeds&page=[0-9]+"
.format(self.supported_categories[cat], query))
list_searches = additional_pages.findall(html)[:-1] # last link is next(i.e. second)
for page in map(lambda link: "".join((self.url, link)), list_searches):
html = retrieve_url(page)
parser.feed(html)

View File

@ -1,6 +1,6 @@
btdb: 1.03
eztv: 1.00
legittorrents: 2.02
piratebay: 2.15
torlock: 2.0
zooqle: 1.12
btdb: 1.04
eztv: 1.01
legittorrents: 2.03
piratebay: 2.16
torlock: 2.1
zooqle: 1.13

View File

@ -1,6 +1,6 @@
#VERSION: 1.12
#AUTHORS: Kanishk Singh (https://github.com/ArionMiles/)
#CONTRIBUTORS: affaff (https://github.com/affaff)
#VERSION: 1.13
# AUTHORS: Kanishk Singh (https://github.com/ArionMiles/)
# CONTRIBUTORS: affaff (https://github.com/affaff)
# Copyright (c) 2017 Kanishk Singh
@ -25,11 +25,12 @@
from xml.dom import minidom
from novaprinter import prettyPrinter
user_agent = 'Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0'
headers = {'User-Agent': user_agent}
from io import StringIO
import gzip
user_agent = 'Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0'
headers = {'User-Agent': user_agent}
try:
from urllib2 import urlopen, Request, URLError
except ImportError:
@ -38,7 +39,7 @@ except ImportError:
def retrieve_url_nodecode(url):
""" Return the content of the url page as a string """
req = Request(url, headers = headers)
req = Request(url, headers=headers)
try:
response = urlopen(req)
except URLError as errno:
@ -56,50 +57,63 @@ def retrieve_url_nodecode(url):
return dat
return dat
class zooqle(object):
""" Search engine class """
url = 'https://zooqle.com'
name = 'Zooqle'
supported_categories = {'all' : 'all',
'movies' : 'Movies',
'tv' : 'TV',
'music' : 'Music',
'games' : 'Games',
'anime' : 'Anime',
'software' : 'Apps',
'books' : 'Books'}
supported_categories = {'all': 'all',
'movies': 'Movies',
'tv': 'TV',
'music': 'Music',
'games': 'Games',
'anime': 'Anime',
'software': 'Apps',
'books': 'Books'}
def search(self, what, cat="all"):
""" Performs search """
page = 1
while page < 11:
query = "".join((self.url, "/search?q=", what, "+category%3A", self.supported_categories[cat], "&fmt=rss"))
if( page>1 ):
query = query + "&pg=" + str (page)
query = "".join((self.url, "/search?q=", what,
"+category%3A", self.supported_categories[cat], "&fmt=rss"))
if page > 1:
query = query + "&pg=" + str(page)
response = retrieve_url_nodecode(query)
xmldoc = minidom.parseString(response)
itemlist = xmldoc.getElementsByTagName('item')
if( len(itemlist ) ==0):
if len(itemlist) == 0:
return
for item in itemlist:
zooqle_dict = zooqle_dict = {"engine_url" : self.url}
zooqle_dict['name'] = item.getElementsByTagName('title')[0].childNodes[0].data
zooqle_dict["size"] = item.getElementsByTagName('enclosure')[0].attributes['length'].childNodes[0].data
if( zooqle_dict["size"]=='0'):
zooqle_dict["link"] = item.getElementsByTagName('torrent:magnetURI')[0].childNodes[0].data
zooqle_dict = zooqle_dict = {"engine_url": self.url}
zooqle_dict['name'] = (item.getElementsByTagName('title')[0]
.childNodes[0].data)
zooqle_dict["size"] = (item.getElementsByTagName('enclosure')[0]
.attributes['length'].childNodes[0].data)
if zooqle_dict["size"] == '0':
zooqle_dict["link"] = (item.getElementsByTagName('torrent:magnetURI')[0]
.childNodes[0].data)
else:
zooqle_dict["link"] = item.getElementsByTagName('enclosure')[0].attributes['url'].value
zooqle_dict["desc_link"] = item.getElementsByTagName('link')[0].childNodes[0].data
zooqle_dict["leech"] = item.getElementsByTagName('torrent:peers')[0].childNodes[0].data
zooqle_dict["link"] = (item.getElementsByTagName('enclosure')[0]
.attributes['url'].value)
zooqle_dict["desc_link"] = (item.getElementsByTagName('link')[0]
.childNodes[0].data)
zooqle_dict["leech"] = (item.getElementsByTagName('torrent:peers')[0]
.childNodes[0].data)
if not zooqle_dict["leech"].isdigit():
zooqle_dict["leech"] = ''
zooqle_dict["seeds"] = item.getElementsByTagName('torrent:seeds')[0].childNodes[0].data
zooqle_dict["seeds"] = (item.getElementsByTagName('torrent:seeds')[0]
.childNodes[0].data)
if not zooqle_dict["seeds"].isdigit():
zooqle_dict["seeds"] = ''
prettyPrinter(zooqle_dict)
totalResultVal = xmldoc.getElementsByTagName('opensearch:totalResults')[0].childNodes[0].data
startIndex = xmldoc.getElementsByTagName('opensearch:startIndex')[0].childNodes[0].data
itemsPerPage = xmldoc.getElementsByTagName('opensearch:itemsPerPage')[0].childNodes[0].data
if( ( int(startIndex) + int(itemsPerPage) > int( totalResultVal ))):
totalResultVal = (xmldoc.getElementsByTagName('opensearch:totalResults')[0]
.childNodes[0].data)
startIndex = (xmldoc.getElementsByTagName('opensearch:startIndex')[0]
.childNodes[0].data)
itemsPerPage = (xmldoc.getElementsByTagName('opensearch:itemsPerPage')[0]
.childNodes[0].data)
if (int(startIndex) + int(itemsPerPage)) > int(totalResultVal):
return
page += 1
return