1 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urlparse
13 class AppleTrailersIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?trailers\.apple\.com/(?:trailers|ca)/(?P<company>[^/]+)/(?P<movie>[^/]+)'
16 "url": "http://trailers.apple.com/trailers/wb/manofsteel/",
22 "md5": "d97a8e575432dbcb81b7c3acb741f8a8",
24 "id": "manofsteel-trailer4",
28 "upload_date": "20130523",
33 "md5": "b8017b7131b721fb4e8d6f49e1df908c",
35 "id": "manofsteel-trailer3",
39 "upload_date": "20130417",
44 "md5": "d0f1e1150989b9924679b441f3404d48",
46 "id": "manofsteel-trailer",
50 "upload_date": "20121212",
55 "md5": "5fe08795b943eb2e757fa95cb6def1cb",
57 "id": "manofsteel-teaser",
61 "upload_date": "20120721",
67 'url': 'http://trailers.apple.com/ca/metropole/autrui/',
68 'only_matching': True,
71 _JSON_RE = r'iTunes.playURL\((.*?)\);'
73 def _real_extract(self, url):
74 mobj = re.match(self._VALID_URL, url)
75 movie = mobj.group('movie')
76 uploader_id = mobj.group('company')
78 playlist_url = compat_urlparse.urljoin(url, 'includes/playlists/itunes.inc')
81 s = re.sub(r'(?s)<script[^<]*?>.*?</script>', '', s)
82 s = re.sub(r'<img ([^<]*?)>', r'<img \1/>', s)
83 # The ' in the onClick attributes are not escaped, it couldn't be parsed
84 # like: http://trailers.apple.com/trailers/wb/gravity/
87 return 'iTunes.playURL(%s);' % m.group(1).replace('\'', ''')
88 s = re.sub(self._JSON_RE, _clean_json, s)
89 s = '<html>%s</html>' % s
91 doc = self._download_xml(playlist_url, movie, transform_source=fix_html)
94 for li in doc.findall('./div/ul/li'):
95 on_click = li.find('.//a').attrib['onClick']
96 trailer_info_json = self._search_regex(self._JSON_RE,
97 on_click, 'trailer info')
98 trailer_info = json.loads(trailer_info_json)
99 title = trailer_info['title']
100 video_id = movie + '-' + re.sub(r'[^a-zA-Z0-9]', '', title).lower()
101 thumbnail = li.find('.//img').attrib['src']
102 upload_date = trailer_info['posted'].replace('-', '')
104 runtime = trailer_info['runtime']
105 m = re.search(r'(?P<minutes>[0-9]+):(?P<seconds>[0-9]{1,2})', runtime)
108 duration = 60 * int(m.group('minutes')) + int(m.group('seconds'))
110 first_url = trailer_info['url']
111 trailer_id = first_url.split('/')[-1].rpartition('_')[0].lower()
112 settings_json_url = compat_urlparse.urljoin(url, 'includes/settings/%s.json' % trailer_id)
113 settings = self._download_json(settings_json_url, trailer_id, 'Downloading settings json')
116 for format in settings['metadata']['sizes']:
117 # The src is a file pointing to the real video file
118 format_url = re.sub(r'_(\d*p.mov)', r'_h\1', format['src'])
121 'format': format['type'],
122 'width': int_or_none(format['width']),
123 'height': int_or_none(format['height']),
126 self._sort_formats(formats)
133 'duration': duration,
134 'thumbnail': thumbnail,
135 'upload_date': upload_date,
136 'uploader_id': uploader_id,
138 'User-Agent': 'QuickTime compatible (youtube-dl)',