2 import xml.etree.ElementTree
4 from .common import InfoExtractor
11 class AppleTrailersIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?trailers.apple.com/trailers/(?P<company>[^/]+)/(?P<movie>[^/]+)'
14 u"url": u"http://trailers.apple.com/trailers/wb/manofsteel/",
17 u"file": u"manofsteel-trailer4.mov",
18 u"md5": u"11874af099d480cc09e103b189805d5f",
21 u"thumbnail": u"http://trailers.apple.com/trailers/wb/manofsteel/images/thumbnail_11624.jpg",
22 u"title": u"Trailer 4",
23 u"upload_date": u"20130523",
24 u"uploader_id": u"wb",
28 u"file": u"manofsteel-trailer3.mov",
29 u"md5": u"07a0a262aae5afe68120eed61137ab34",
32 u"thumbnail": u"http://trailers.apple.com/trailers/wb/manofsteel/images/thumbnail_10793.jpg",
33 u"title": u"Trailer 3",
34 u"upload_date": u"20130417",
35 u"uploader_id": u"wb",
39 u"file": u"manofsteel-trailer.mov",
40 u"md5": u"e401fde0813008e3307e54b6f384cff1",
43 u"thumbnail": u"http://trailers.apple.com/trailers/wb/manofsteel/images/thumbnail_8703.jpg",
45 u"upload_date": u"20121212",
46 u"uploader_id": u"wb",
50 u"file": u"manofsteel-teaser.mov",
51 u"md5": u"76b392f2ae9e7c98b22913c10a639c97",
54 u"thumbnail": u"http://trailers.apple.com/trailers/wb/manofsteel/images/thumbnail_6899.jpg",
56 u"upload_date": u"20120721",
57 u"uploader_id": u"wb",
63 def _real_extract(self, url):
64 mobj = re.match(self._VALID_URL, url)
65 movie = mobj.group('movie')
66 uploader_id = mobj.group('company')
68 playlist_url = url.partition(u'?')[0] + u'/includes/playlists/web.inc'
69 playlist_snippet = self._download_webpage(playlist_url, movie)
70 playlist_cleaned = re.sub(r'(?s)<script>.*?</script>', u'', playlist_snippet)
71 playlist_html = u'<html>' + playlist_cleaned + u'</html>'
75 doc = xml.etree.ElementTree.fromstring(playlist_html)
77 for li in doc.findall('./div/ul/li'):
78 title = li.find('.//h3').text
79 video_id = movie + '-' + re.sub(r'[^a-zA-Z0-9]', '', title).lower()
80 thumbnail = li.find('.//img').attrib['src']
82 date_el = li.find('.//p')
84 m = re.search(r':\s?(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/(?P<year>[0-9]{2})', date_el.text)
86 upload_date = u'20' + m.group('year') + m.group('month') + m.group('day')
87 runtime_el = date_el.find('./br')
88 m = re.search(r':\s?(?P<minutes>[0-9]+):(?P<seconds>[0-9]{1,2})', runtime_el.tail)
91 duration = 60 * int(m.group('minutes')) + int(m.group('seconds'))
94 for formats_el in li.findall('.//a'):
95 if formats_el.attrib['class'] != 'OverlayPanel':
97 target = formats_el.attrib['target']
99 format_code = formats_el.text
100 if 'Automatic' in format_code:
103 size_q = formats_el.attrib['href']
104 size_id = size_q.rpartition('#videos-')[2]
105 if size_id not in size_cache:
106 size_url = url + size_q
107 sizepage_html = self._download_webpage(
109 note=u'Downloading size info %s' % size_id,
110 errnote=u'Error while downloading size info %s' % size_id,
112 _doc = xml.etree.ElementTree.fromstring(sizepage_html)
113 size_cache[size_id] = _doc
115 sizepage_doc = size_cache[size_id]
116 links = sizepage_doc.findall('.//{http://www.w3.org/1999/xhtml}ul/{http://www.w3.org/1999/xhtml}li/{http://www.w3.org/1999/xhtml}a')
118 href = vid_a.get('href')
119 if not href.endswith(target):
121 detail_q = href.partition('#')[0]
122 detail_url = url + '/' + detail_q
124 m = re.match(r'includes/(?P<detail_id>[^/]+)/', detail_q)
125 detail_id = m.group('detail_id')
127 detail_html = self._download_webpage(
129 note=u'Downloading detail %s %s' % (detail_id, size_id),
130 errnote=u'Error while downloading detail %s %s' % (detail_id, size_id)
132 detail_doc = xml.etree.ElementTree.fromstring(detail_html)
133 movie_link_el = detail_doc.find('.//{http://www.w3.org/1999/xhtml}a')
134 assert movie_link_el.get('class') == 'movieLink'
135 movie_link = movie_link_el.get('href').partition('?')[0].replace('_', '_h')
136 ext = determine_ext(movie_link)
140 'format': format_code,
151 'duration': duration,
152 'thumbnail': thumbnail,
153 'upload_date': upload_date,
154 'uploader_id': uploader_id,
155 'user_agent': 'QuickTime compatible (youtube-dl)',
157 # TODO: Remove when #980 has been merged
158 info['url'] = formats[-1]['url']
159 info['ext'] = formats[-1]['ext']
161 playlist.append(info)