From f4c29c07bfdee4800ca004bbbf4878b52980d6a7 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 2 Jun 2010 22:26:52 +0000 Subject: [PATCH] Workaround for torrentdownloads.net search engine (The web site seems partly broken though) --- src/search_engine/engines/torrentdownloads.py | 31 ++++++++++++++++--- src/search_engine/engines/versions.txt | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/search_engine/engines/torrentdownloads.py b/src/search_engine/engines/torrentdownloads.py index bbfb4de42..bdbc5244a 100644 --- a/src/search_engine/engines/torrentdownloads.py +++ b/src/search_engine/engines/torrentdownloads.py @@ -1,4 +1,4 @@ -#VERSION: 1.01 +#VERSION: 1.03 #AUTHORS: Christophe Dumez (chris@qbittorrent.org) # Redistribution and use in source and binary forms, with or without @@ -27,9 +27,11 @@ from novaprinter import prettyPrinter -from helpers import retrieve_url, download_file +from helpers import retrieve_url +import StringIO, gzip, urllib2, tempfile import sgmllib import re +import os class torrentdownloads(object): url = 'http://www.torrentdownloads.net' @@ -40,8 +42,27 @@ class torrentdownloads(object): self.results = [] self.parser = self.SimpleSGMLParser(self.results, self.url) - def download_torrent(self, info): - print download_file(info) + def download_torrent(self, url): + """ Download file at url and write it to a file, return the path to the file and the url """ + file, path = tempfile.mkstemp() + file = os.fdopen(file, "w") + # Download url + req = urllib2.Request(url) + response = urllib2.urlopen(req) + dat = response.read() + # Check if it is gzipped + if dat[:2] == '\037\213': + # Data is gzip encoded, decode it + compressedstream = StringIO.StringIO(dat) + gzipper = gzip.GzipFile(fileobj=compressedstream) + extracted_data = gzipper.read() + dat = extracted_data + + # Write it to a file + file.write(dat.strip()) + file.close() + # return file path + print path+" "+url class SimpleSGMLParser(sgmllib.SGMLParser): def __init__(self, results, url, *args): @@ -108,4 +129,4 @@ class torrentdownloads(object): if len(results) <= 0: break i += 1 - \ No newline at end of file + diff --git a/src/search_engine/engines/versions.txt b/src/search_engine/engines/versions.txt index 67457256c..a82fa4e89 100644 --- a/src/search_engine/engines/versions.txt +++ b/src/search_engine/engines/versions.txt @@ -4,4 +4,4 @@ btjunkie: 2.21 mininova: 1.40 piratebay: 1.30 vertor: 1.0 -torrentdownloads: 1.01 +torrentdownloads: 1.03