diff --git a/torrentgalaxy.py b/torrentgalaxy.py index 99c1d62..02ff948 100644 --- a/torrentgalaxy.py +++ b/torrentgalaxy.py @@ -37,12 +37,14 @@ class TorrentGalaxyParser(HTMLParser): count_div, = -1, get_size, get_seeds, get_leechs = False, False, False this_record = {} - url = 'https://torrentgalaxy.to' + + def __init__(self, url): + HTMLParser.__init__(self) + self.url = url def handle_starttag(self, tag, attrs): if tag == self.DIV: my_attrs = dict(attrs) - # if (my_attrs.get('class') == 'tgxtablerow txlight'): if my_attrs.get('class') and 'tgxtablerow' in my_attrs.get('class'): self.count_div = 0 self.this_record = {} @@ -89,12 +91,12 @@ def handle_data(self, data): def do_search(self, url): webpage = retrieve_url(url) - tgParser = self.TorrentGalaxyParser() + tgParser = self.TorrentGalaxyParser(url) tgParser.feed(webpage) def search(self, what, cat='all'): query = str(what).replace(r' ', '+') - search_url = 'https://torrentgalaxy.to/torrents.php?' + search_url = self.url + 'torrents.php?' full_url = \ search_url + \ self.supported_categories[cat.lower()] + \ @@ -102,7 +104,7 @@ def search(self, what, cat='all'): query webpage = retrieve_url(full_url) - tgParser = self.TorrentGalaxyParser() + tgParser = self.TorrentGalaxyParser(self.url) tgParser.feed(webpage) all_results_re = re.compile(r'steelblue[^>]+>(.*?)<') @@ -115,7 +117,6 @@ def search(self, what, cat='all'): t = threading.Thread(args=(this_url,), target=self.do_search) threads.append(t) t.start() - # self.do_search(this_url) for thread in threads: thread.join()