|
|
@ -1,4 +1,4 @@ |
|
|
|
#VERSION: 1.51 |
|
|
|
#VERSION: 2.00 |
|
|
|
#AUTHORS: Christophe Dumez (chris@qbittorrent.org) |
|
|
|
#AUTHORS: Christophe Dumez (chris@qbittorrent.org) |
|
|
|
#CONTRIBUTORS: Diego de las Heras (diegodelasheras@gmail.com) |
|
|
|
#CONTRIBUTORS: Diego de las Heras (diegodelasheras@gmail.com) |
|
|
|
|
|
|
|
|
|
|
@ -26,90 +26,124 @@ |
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
|
|
# POSSIBILITY OF SUCH DAMAGE. |
|
|
|
# POSSIBILITY OF SUCH DAMAGE. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from HTMLParser import HTMLParser |
|
|
|
|
|
|
|
from httplib import HTTPConnection as http |
|
|
|
from novaprinter import prettyPrinter |
|
|
|
from novaprinter import prettyPrinter |
|
|
|
from helpers import retrieve_url, download_file |
|
|
|
from helpers import download_file |
|
|
|
import sgmllib |
|
|
|
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class mininova(object): |
|
|
|
class mininova(object): |
|
|
|
# Mandatory properties |
|
|
|
""" Search engine class """ |
|
|
|
url = 'http://www.mininova.org' |
|
|
|
url = 'http://www.mininova.org' |
|
|
|
name = 'Mininova' |
|
|
|
name = 'Mininova' |
|
|
|
supported_categories = {'all': '0', 'movies': '4', 'tv': '8', 'music': '5', 'games': '3', 'anime': '1', 'software': '7', 'pictures': '6', 'books': '2'} |
|
|
|
supported_categories = {'all' : '0', |
|
|
|
|
|
|
|
'movies' : '4', |
|
|
|
def __init__(self): |
|
|
|
'tv' : '8', |
|
|
|
self.results = [] |
|
|
|
'music' : '5', |
|
|
|
self.parser = self.SimpleSGMLParser(self.results, self.url) |
|
|
|
'games' : '3', |
|
|
|
|
|
|
|
'anime' : '1', |
|
|
|
def download_torrent(self, info): |
|
|
|
'software' : '7', |
|
|
|
print download_file(info) |
|
|
|
'pictures' : '6', |
|
|
|
|
|
|
|
'books' : '2'} |
|
|
|
class SimpleSGMLParser(sgmllib.SGMLParser): |
|
|
|
|
|
|
|
def __init__(self, results, url, *args): |
|
|
|
def download_torrent(self, info): |
|
|
|
sgmllib.SGMLParser.__init__(self) |
|
|
|
print(download_file(info)) |
|
|
|
self.url = url |
|
|
|
|
|
|
|
self.td_counter = None |
|
|
|
class MyHtmlParseWithBlackJack(HTMLParser): |
|
|
|
self.current_item = None |
|
|
|
""" Parser class """ |
|
|
|
self.results = results |
|
|
|
def __init__(self, list_searches, url): |
|
|
|
|
|
|
|
HTMLParser.__init__(self) |
|
|
|
def start_a(self, attr): |
|
|
|
self.list_searches = list_searches |
|
|
|
params = dict(attr) |
|
|
|
self.url = url |
|
|
|
#print params |
|
|
|
self.table_results = False |
|
|
|
if params.has_key('href'): |
|
|
|
self.current_item = None |
|
|
|
if params['href'].startswith("/get/"): |
|
|
|
self.cur_item_name = None |
|
|
|
self.current_item = {} |
|
|
|
self.next_queries = True |
|
|
|
self.td_counter = 0 |
|
|
|
|
|
|
|
self.current_item['link']=self.url+params['href'].strip() |
|
|
|
def handle_starttag_tr(self, _): |
|
|
|
elif params['href'].startswith("/tor/") and self.current_item is not None: |
|
|
|
""" Handler of tr start tag """ |
|
|
|
self.current_item['desc_link']=self.url+params['href'].strip() |
|
|
|
self.current_item = dict() |
|
|
|
|
|
|
|
|
|
|
|
def handle_data(self, data): |
|
|
|
def handle_starttag_a(self, attrs): |
|
|
|
if self.td_counter == 0: |
|
|
|
""" Handler of a start tag """ |
|
|
|
if not self.current_item.has_key('name'): |
|
|
|
params = dict(attrs) |
|
|
|
self.current_item['name'] = '' |
|
|
|
link = params["href"] |
|
|
|
self.current_item['name']+= data |
|
|
|
|
|
|
|
elif self.td_counter == 1: |
|
|
|
if link.startswith("/get/"): |
|
|
|
if not self.current_item.has_key('size'): |
|
|
|
#download link |
|
|
|
self.current_item['size'] = '' |
|
|
|
self.current_item["link"] = "".join((self.url, link)) |
|
|
|
self.current_item['size']+= data.strip() |
|
|
|
elif link.startswith("/tor/"): |
|
|
|
elif self.td_counter == 2: |
|
|
|
#description |
|
|
|
if not self.current_item.has_key('seeds'): |
|
|
|
self.current_item["desc_link"] = "".join((self.url, link)) |
|
|
|
self.current_item['seeds'] = '' |
|
|
|
self.cur_item_name = "name" |
|
|
|
self.current_item['seeds']+= data.strip() |
|
|
|
self.current_item["name"] = "" |
|
|
|
elif self.td_counter == 3: |
|
|
|
elif self.next_queries and link.startswith("/search"): |
|
|
|
if not self.current_item.has_key('leech'): |
|
|
|
if params["title"].startswith("Page"): |
|
|
|
self.current_item['leech'] = '' |
|
|
|
self.list_searches.append(link) |
|
|
|
self.current_item['leech']+= data.strip() |
|
|
|
|
|
|
|
|
|
|
|
def handle_starttag_td(self, attrs): |
|
|
|
def start_td(self,attr): |
|
|
|
""" Handler of td start tag """ |
|
|
|
if isinstance(self.td_counter,int): |
|
|
|
if ("align", "right") in attrs: |
|
|
|
self.td_counter += 1 |
|
|
|
if not "size" in self.current_item.keys(): |
|
|
|
if self.td_counter > 4: |
|
|
|
self.cur_item_name = "size" |
|
|
|
self.td_counter = None |
|
|
|
self.current_item["size"] = "" |
|
|
|
# Display item |
|
|
|
|
|
|
|
if self.current_item: |
|
|
|
def handle_starttag_span(self, attrs): |
|
|
|
self.current_item['engine_url'] = self.url |
|
|
|
""" Handler of span start tag """ |
|
|
|
if not self.current_item['seeds'].isdigit(): |
|
|
|
if ("class", "g") in attrs: |
|
|
|
self.current_item['seeds'] = 0 |
|
|
|
self.cur_item_name = "seeds" |
|
|
|
if not self.current_item['leech'].isdigit(): |
|
|
|
self.current_item["seeds"] = "" |
|
|
|
self.current_item['leech'] = 0 |
|
|
|
elif ("class", "b") in attrs: |
|
|
|
prettyPrinter(self.current_item) |
|
|
|
self.cur_item_name = "leech" |
|
|
|
self.results.append('a') |
|
|
|
self.current_item["leech"] = "" |
|
|
|
|
|
|
|
|
|
|
|
def search(self, what, cat='all'): |
|
|
|
def handle_starttag(self, tag, attrs): |
|
|
|
ret = [] |
|
|
|
""" Parser's start tag handler """ |
|
|
|
i = 1 |
|
|
|
if self.table_results: |
|
|
|
while True and i<11: |
|
|
|
dispatcher = getattr(self, "_".join(("handle_starttag", tag)), None) |
|
|
|
results = [] |
|
|
|
if dispatcher: |
|
|
|
parser = self.SimpleSGMLParser(results, self.url) |
|
|
|
dispatcher(attrs) |
|
|
|
dat = retrieve_url(self.url+'/search/%s/%s/seeds/%d'%(what, self.supported_categories[cat], i)) |
|
|
|
|
|
|
|
results_re = re.compile('(?s)<h1>Search results for.*') |
|
|
|
elif tag == "table": |
|
|
|
for match in results_re.finditer(dat): |
|
|
|
self.table_results = ("class", "maintable") in attrs |
|
|
|
res_tab = match.group(0) |
|
|
|
|
|
|
|
parser.feed(res_tab) |
|
|
|
def handle_endtag(self, tag): |
|
|
|
|
|
|
|
""" Parser's end tag handler """ |
|
|
|
|
|
|
|
if tag == "tr" and self.current_item: |
|
|
|
|
|
|
|
self.current_item["engine_url"] = self.url |
|
|
|
|
|
|
|
prettyPrinter(self.current_item) |
|
|
|
|
|
|
|
self.current_item = None |
|
|
|
|
|
|
|
elif self.cur_item_name: |
|
|
|
|
|
|
|
if tag == "a" or tag == "span": |
|
|
|
|
|
|
|
self.cur_item_name = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_data(self, data): |
|
|
|
|
|
|
|
""" Parser's data handler """ |
|
|
|
|
|
|
|
if self.cur_item_name: |
|
|
|
|
|
|
|
temp = self.current_item[self.cur_item_name] |
|
|
|
|
|
|
|
self.current_item[self.cur_item_name] = " ".join((temp, data)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def search(self, what, cat="all"): |
|
|
|
|
|
|
|
""" Performs search """ |
|
|
|
|
|
|
|
connection = http("www.mininova.org") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query = "/".join(("/search", what, self.supported_categories[cat], "seeds")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connection.request("GET", query) |
|
|
|
|
|
|
|
response = connection.getresponse() |
|
|
|
|
|
|
|
if response.status != 200: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list_searches = [] |
|
|
|
|
|
|
|
parser = self.MyHtmlParseWithBlackJack(list_searches, self.url) |
|
|
|
|
|
|
|
parser.feed(response.read().decode('utf-8')) |
|
|
|
parser.close() |
|
|
|
parser.close() |
|
|
|
break |
|
|
|
|
|
|
|
if len(results) <= 0: |
|
|
|
parser.next_queries = False |
|
|
|
break |
|
|
|
for search_query in list_searches: |
|
|
|
i += 1 |
|
|
|
connection.request("GET", search_query) |
|
|
|
|
|
|
|
response = connection.getresponse() |
|
|
|
|
|
|
|
parser.feed(response.read().decode('utf-8')) |
|
|
|
|
|
|
|
parser.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connection.close() |
|
|
|
|
|
|
|
return |
|
|
|