3
from flexget.entry import Entry
4
from flexget.plugin import *
5
from flexget.utils.soup import get_soup
6
from flexget.utils.cached_input import cached
7
from flexget.utils.tools import urlopener
9
log = logging.getLogger('tvtorrents')
12
class InputTVTorrents(object):
14
A customized HTML input plugin. Parses out full torrent URLs from
15
TVTorrents' page for Recently Aired TV shows.
17
A bit fragile right now, because it depends heavily on the exact
18
structure of the HTML.
20
Just set tvt: true in your config, and provide the path to your login
21
cookie by using the cookies plugin.
23
Note: Of yourse, you need to configure patterns filter to match only
24
desired content. The series filter does NOT appear to work well with
25
this plugin yet - just use a pattern like (lost|csi).*?720p until we
28
Plugin-specific code by Fredrik Braenstroem.
32
from flexget import validator
33
return validator.factory('url')
37
def on_feed_input(self, feed):
38
pageurl = "http://tvtorrents.com/loggedin/recently_aired.do"
39
log.debug("InputPlugin tvtorrents requesting url %s" % pageurl)
41
page = urlopener(pageurl, log)
44
hscript = soup.find('script', src=None).contents[0]
45
hlines = hscript.splitlines()
46
hash = hlines[15].strip().split("'")[1]
47
digest = hlines[16].strip().split("'")[1]
48
hurl = hlines[17].strip().split("'")
49
hashurl = hurl[1] + "%s" + hurl[3] + digest + hurl[5] + hash
51
for link in soup.findAll('a'):
52
if not 'href' in link:
55
title = link.contents[0]
57
if link.has_key('onclick') and link['onclick'].find("loadTorrent") != -1:
58
infohash = link['onclick'].split("'")[1]
59
td = link.parent.parent.contents[4]
60
sname = td.contents[0].strip()
61
epi = td.contents[2].contents[0].strip()
62
title = "%s - %s" % (sname, epi)
63
url = hashurl % (infohash,)
74
if url.startswith('//'):
76
elif not url.startswith('http://') or not url.startswith('https://'):
77
url = urlparse.urljoin(pageurl, url)
79
# in case the title contains xxxxxxx.torrent - foooo.torrent clean it a bit (get upto first .torrent)
80
if title.lower().find('.torrent') > 0:
81
title = title[:title.lower().find(".torrent")]
85
entry['title'] = title
87
feed.entries.append(entry)
89
register_plugin(InputTVTorrents, 'tvt')