Browse Source

Workaround for torrentdownloads.net search engine (The web site seems partly broken though)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
f4c29c07bf
  1. 31
      src/search_engine/engines/torrentdownloads.py
  2. 2
      src/search_engine/engines/versions.txt

31
src/search_engine/engines/torrentdownloads.py

@ -1,4 +1,4 @@ @@ -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 @@ @@ -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): @@ -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): @@ -108,4 +129,4 @@ class torrentdownloads(object):
if len(results) <= 0:
break
i += 1

2
src/search_engine/engines/versions.txt

@ -4,4 +4,4 @@ btjunkie: 2.21 @@ -4,4 +4,4 @@ btjunkie: 2.21
mininova: 1.40
piratebay: 1.30
vertor: 1.0
torrentdownloads: 1.01
torrentdownloads: 1.03

Loading…
Cancel
Save