5
from flexget.entry import Entry
6
from flexget.utils.search import torrent_availability
7
from flexget.plugin import PluginWarning, register_plugin
9
log = logging.getLogger('isohunt')
12
class UrlRewriteIsoHunt(object):
13
"""IsoHunt urlrewriter and search plugin.
36
from flexget import validator
38
root = validator.factory('choice')
39
root.accept_choices(['misc', 'movies', 'audio', 'tv', 'games', 'apps', 'pics', 'anime', 'comics',
40
'books', 'music video', 'unclassified', 'all'])
43
def url_rewritable(self, feed, entry):
45
# search is not supported
46
if url.startswith('http://isohunt.com/torrents/?ihq='):
49
if not 'torrent_details' in url:
51
return url.startswith('http://isohunt.com') and url.find('download') == -1
53
def url_rewrite(self, feed, entry):
54
entry['url'] = entry['url'].replace('torrent_details', 'download')
56
def search(self, query, comparator, config):
57
# urllib.quote will crash if the unicode string has non ascii characters, so encode in utf-8 beforehand
58
comparator.set_seq1(query)
59
name = comparator.search_string()
60
optionlist = ['misc', 'movies', 'audio', 'tv', 'games', 'apps', 'pics', 'anime', 'comics', 'books',
61
'music video', 'unclassified', 'all']
62
url = 'http://isohunt.com/js/rss/%s?iht=%s&noSL' % (
63
urllib.quote(name.encode('utf-8')), optionlist.index(config))
65
log.debug('requesting: %s' % url)
66
rss = feedparser.parse(url)
69
status = rss.get('status', False)
71
raise PluginWarning('Search result not 200 (OK), received %s' % status)
73
ex = rss.get('bozo_exception', False)
75
raise PluginWarning('Got bozo_exception (bad feed)')
77
for item in rss.entries:
80
# assign confidence score of how close this link is to the name you're looking for. .6 and above is "close"
81
comparator.set_seq2(item.title)
82
log.debug('name: %s' % comparator.a)
83
log.debug('found name: %s' % comparator.b)
84
log.debug('confidence: %s' % comparator.ratio())
85
if not comparator.matches():
89
entry['title'] = item.title
90
entry['url'] = item.link
91
entry['search_ratio'] = comparator.ratio()
93
m = re.search(r'Size: ([\d]+).*Seeds: (\d+).*Leechers: (\d+)', item.description, re.IGNORECASE)
95
log.debug('regexp did not find seeds / peer data')
98
log.debug('regexp found size(%s), Seeds(%s) and Leeches(%s)' % (m.group(1), m.group(2), m.group(3)))
100
entry['content_size'] = int(m.group(1))
101
entry['torrent_seeds'] = int(m.group(2))
102
entry['torrent_leeches'] = int(m.group(3))
103
entry['search_sort'] = torrent_availability(entry['torrent_seeds'], entry['torrent_leeches'])
105
entries.append(entry)
108
raise PluginWarning('No close matches for %s' % name, log, log_once=True)
110
entries.sort(reverse=True, key=lambda x: x.get('search_sort'))
114
register_plugin(UrlRewriteIsoHunt, 'isohunt', groups=['urlrewriter', 'search'])