4
from flexget.entry import Entry
5
from flexget.utils.search import torrent_availability
6
from flexget.plugin import PluginWarning, register_plugin
8
log = logging.getLogger('kat')
11
class SearchKAT(object):
28
from flexget import validator
30
root = validator.factory('choice')
31
root.accept_choices(['all', 'movies', 'tv', 'music', 'books', 'xxx', 'other'])
34
def search(self, query, comparator, config):
35
comparator.set_seq1(query)
36
name = comparator.search_string().lower()
37
url = 'http://www.kat.ph/search/%s/?rss=1' % urllib.quote(name.encode('utf-8'))
39
url += '&category=%s' % config
41
log.debug('requesting: %s' % url)
42
rss = feedparser.parse(url)
45
status = rss.get('status', False)
47
raise PluginWarning('Search result not 200 (OK), received %s' % status)
49
ex = rss.get('bozo_exception', False)
51
raise PluginWarning('Got bozo_exception (bad feed)')
53
for item in rss.entries:
54
# Check if item passes comparator
55
comparator.set_seq2(item.title)
56
log.debug('name: %s, found name: %s, confidence: %s' % (comparator.a, comparator.b, comparator.ratio()))
57
if not comparator.matches():
61
entry['title'] = item.title
62
if item.torrentlink.startswith('//'):
63
entry['url'] = 'http:' + item.torrentlink
65
entry['url'] = item.torrentlink
66
entry['search_ratio'] = comparator.ratio()
67
entry['torrent_seeds'] = int(item.seeds)
68
entry['torrent_leeches'] = int(item.leechs)
69
entry['search_sort'] = torrent_availability(entry['torrent_seeds'], entry['torrent_leeches'])
70
entry['content_size'] = int(item.size) / 1024 / 1024
71
entry['torrent_info_hash'] = item.hash
77
raise PluginWarning('No matches for %s' % name, log, log_once=True)
79
entries.sort(reverse=True, key=lambda x: x.get('search_sort'))
82
register_plugin(SearchKAT, 'kat', groups=['search'])