Skip to content

Commit

Permalink
Merge pull request #44 from Chocobo1/pep8
Browse files Browse the repository at this point in the history
Refactor code to be PEP8 compliant
  • Loading branch information
Chocobo1 committed Sep 16, 2018
2 parents 2ff7040 + 5609281 commit c16c7e4
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 207 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ matrix:
env: NOVA_DIR=nova3

install:
- pip install pyflakes
- pip install pycodestyle pyflakes

script:
- cd "$TRAVIS_BUILD_DIR"
- python -m compileall "$NOVA_DIR/engines/"*.py
- pyflakes "$NOVA_DIR/engines/"*.py
- cd "$TRAVIS_BUILD_DIR/$NOVA_DIR/engines"
- python -m compileall *.py
- pyflakes *.py
# skipping E265, fixing it will break plugin usage on older qbt instances (< v4.1.2)
- pycodestyle --ignore=E265,W503 --max-line-length=100 --statistics *.py
23 changes: 12 additions & 11 deletions nova/engines/btdb.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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'
Expand All @@ -46,9 +47,9 @@ def __init__(self, results, url):
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 = []
Expand Down Expand Up @@ -85,15 +86,15 @@ def handle_starttag(self, tag, attrs):
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
Expand Down
17 changes: 11 additions & 6 deletions nova/engines/eztv.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +13,7 @@
from novaprinter import prettyPrinter
from helpers import retrieve_url


class eztv(object):
name = "EZTV"
url = 'https://eztv.ag'
Expand Down Expand Up @@ -45,13 +46,16 @@ def handle_starttag(self, tag, attrs):
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 == '-'):
Expand All @@ -65,13 +69,14 @@ def handle_endtag(self, tag):
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')
23 changes: 13 additions & 10 deletions nova/engines/legittorrents.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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))
Expand All @@ -55,13 +56,14 @@ def handle_starttag(self, tag, attrs):
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":
Expand All @@ -84,11 +86,12 @@ def handle_data(self, data):

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]]

Expand Down
30 changes: 17 additions & 13 deletions nova/engines/piratebay.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 """
Expand All @@ -51,7 +53,7 @@ def __init__(self, list_searches, url):
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
Expand Down Expand Up @@ -93,12 +95,14 @@ def handle_start_tag_td(self, attrs):
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]
Expand Down Expand Up @@ -141,7 +145,8 @@ def handle_data(self, data):
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
Expand All @@ -153,10 +158,9 @@ def handle_data(self, data):
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]))

Expand Down
48 changes: 26 additions & 22 deletions nova/engines/torlock.py
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -27,14 +28,14 @@ class MyHtmlParser(HTMLParser):
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)
Expand All @@ -50,7 +51,8 @@ def handle_starttag(self, tag, attrs):
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"
Expand Down Expand Up @@ -81,13 +83,15 @@ def search(self, query, cat='all'):
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)
Expand Down
12 changes: 6 additions & 6 deletions nova/engines/versions.txt
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit c16c7e4

Please sign in to comment.