3
from flexget.entry import Entry
4
from flexget.plugin import priority, register_plugin, get_plugin_by_name, DependencyError
5
from flexget.utils.cached_input import cached
6
from flexget.utils.tools import urlopener
7
from flexget.utils.soup import get_soup
9
from flexget.plugins.input.rss import InputRSS
11
raise DependencyError(issued_by='apple_trailers', missing='rss')
13
log = logging.getLogger('apple_trailers')
16
class AppleTrailers(InputRSS):
18
Adds support for Apple.com movie trailers.
22
Choice of quality is one of: ipod, '320', '480', 640w, 480p, 720p, 1080p
26
self.rss_url = 'http://trailers.apple.com/trailers/home/rss/newtrailers.rss'
27
self.qualities = ['ipod', 320, '320', 480, '480', '640w', '480p', '720p', '1080p']
30
from flexget import validator
31
config = validator.factory()
32
# TODO: 320 and 480 need to be quoted. is it possible to validate
33
# without the need for quotes?
34
config.accept('choice').accept_choices(self.qualities, ignore_case=True)
37
# Run before headers plugin
39
def on_feed_start(self, feed, config):
40
# TODO: Resolve user-agent in a way that doesn't involve modifying the feed config.
41
# make sure we have dependencies available, will throw DependencyError if not
42
get_plugin_by_name('headers')
44
feed.config['headers'] = {'User-Agent': 'QuickTime/7.6.6'}
45
self.quality = str(config)
48
@cached('apple_trailers')
49
def on_feed_input(self, feed, config):
51
rss_config = {'url': self.rss_url}
52
rss_entries = super(AppleTrailers, self).on_feed_input(feed, rss_config)
54
# Multiple entries can point to the same movie page (trailer 1, clip
57
for entry in rss_entries:
58
url = entry['original_url']
62
title = entry['title']
63
entries[url] = title[:title.rfind('-')].rstrip()
67
for url, title in entries.iteritems():
68
inc_url = url + 'includes/playlists/web.inc'
69
page = urlopener(inc_url, log)
72
links = soup.findAll('a', attrs={'class': 'target-quicktimeplayer', 'href': re.compile(r'_h?480p\.mov$')})
74
url = link.get('href')
75
url = url[:url.rfind('_')]
76
quality = self.quality.lower()
81
url += '_h' + quality + '.mov'
85
entry['title'] = title
87
match = re.search(r'.*/([^?#]*)', url)
88
entry['filename'] = match.group(1)
91
log.debug('found trailer %s', url)
95
register_plugin(AppleTrailers, 'apple_trailers', api_ver=2)