1 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urlparse
13 class AppleTrailersIE(InfoExtractor):
14 IE_NAME = 'appletrailers'
15 _VALID_URL = r'https?://(?:www\.)?trailers\.apple\.com/(?:trailers|ca)/(?P<company>[^/]+)/(?P<movie>[^/]+)'
17 'url': 'http://trailers.apple.com/trailers/wb/manofsteel/',
23 'md5': 'd97a8e575432dbcb81b7c3acb741f8a8',
25 'id': 'manofsteel-trailer4',
29 'upload_date': '20130523',
34 'md5': 'b8017b7131b721fb4e8d6f49e1df908c',
36 'id': 'manofsteel-trailer3',
40 'upload_date': '20130417',
45 'md5': 'd0f1e1150989b9924679b441f3404d48',
47 'id': 'manofsteel-trailer',
51 'upload_date': '20121212',
56 'md5': '5fe08795b943eb2e757fa95cb6def1cb',
58 'id': 'manofsteel-teaser',
62 'upload_date': '20120721',
68 'url': 'http://trailers.apple.com/ca/metropole/autrui/',
69 'only_matching': True,
72 _JSON_RE = r'iTunes.playURL\((.*?)\);'
74 def _real_extract(self, url):
75 mobj = re.match(self._VALID_URL, url)
76 movie = mobj.group('movie')
77 uploader_id = mobj.group('company')
79 playlist_url = compat_urlparse.urljoin(url, 'includes/playlists/itunes.inc')
82 s = re.sub(r'(?s)<script[^<]*?>.*?</script>', '', s)
83 s = re.sub(r'<img ([^<]*?)>', r'<img \1/>', s)
84 # The ' in the onClick attributes are not escaped, it couldn't be parsed
85 # like: http://trailers.apple.com/trailers/wb/gravity/
88 return 'iTunes.playURL(%s);' % m.group(1).replace('\'', ''')
89 s = re.sub(self._JSON_RE, _clean_json, s)
90 s = '<html>%s</html>' % s
92 doc = self._download_xml(playlist_url, movie, transform_source=fix_html)
95 for li in doc.findall('./div/ul/li'):
96 on_click = li.find('.//a').attrib['onClick']
97 trailer_info_json = self._search_regex(self._JSON_RE,
98 on_click, 'trailer info')
99 trailer_info = json.loads(trailer_info_json)
100 title = trailer_info['title']
101 video_id = movie + '-' + re.sub(r'[^a-zA-Z0-9]', '', title).lower()
102 thumbnail = li.find('.//img').attrib['src']
103 upload_date = trailer_info['posted'].replace('-', '')
105 runtime = trailer_info['runtime']
106 m = re.search(r'(?P<minutes>[0-9]+):(?P<seconds>[0-9]{1,2})', runtime)
109 duration = 60 * int(m.group('minutes')) + int(m.group('seconds'))
111 first_url = trailer_info['url']
112 trailer_id = first_url.split('/')[-1].rpartition('_')[0].lower()
113 settings_json_url = compat_urlparse.urljoin(url, 'includes/settings/%s.json' % trailer_id)
114 settings = self._download_json(settings_json_url, trailer_id, 'Downloading settings json')
117 for format in settings['metadata']['sizes']:
118 # The src is a file pointing to the real video file
119 format_url = re.sub(r'_(\d*p.mov)', r'_h\1', format['src'])
122 'format': format['type'],
123 'width': int_or_none(format['width']),
124 'height': int_or_none(format['height']),
127 self._sort_formats(formats)
134 'duration': duration,
135 'thumbnail': thumbnail,
136 'upload_date': upload_date,
137 'uploader_id': uploader_id,
139 'User-Agent': 'QuickTime compatible (youtube-dl)',
150 class AppleTrailersSectionIE(InfoExtractor):
151 IE_NAME = 'appletrailers:section'
154 'feed_path': 'just_added',
155 'title': 'Just Added',
158 'feed_path': 'exclusive',
159 'title': 'Exclusive',
162 'feed_path': 'just_hd',
166 'feed_path': 'most_pop',
167 'title': 'Most Popular',
170 'feed_path': 'studios',
171 'title': 'Movie Studios',
174 _VALID_URL = r'https?://(?:www\.)?trailers\.apple\.com/#section=(?P<id>%s)' % '|'.join(_SECTIONS)
176 'url': 'http://trailers.apple.com/#section=justadded',
178 'title': 'Just Added',
181 'playlist_mincount': 80,
183 'url': 'http://trailers.apple.com/#section=exclusive',
185 'title': 'Exclusive',
188 'playlist_mincount': 80,
190 'url': 'http://trailers.apple.com/#section=justhd',
195 'playlist_mincount': 80,
197 'url': 'http://trailers.apple.com/#section=mostpopular',
199 'title': 'Most Popular',
202 'playlist_mincount': 80,
204 'url': 'http://trailers.apple.com/#section=moviestudios',
206 'title': 'Movie Studios',
207 'id': 'moviestudios',
209 'playlist_mincount': 80,
212 def _real_extract(self, url):
213 section = self._match_id(url)
214 section_data = self._download_json(
215 'http://trailers.apple.com/trailers/home/feeds/%s.json' % self._SECTIONS[section]['feed_path'],
218 self.url_result('http://trailers.apple.com' + e['location'])
219 for e in section_data]
220 return self.playlist_result(entries, section, self._SECTIONS[section]['title'])