]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/appletrailers.py
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/trailers/magnolia/blackthorn/',
72 'playlist_mincount': 2,
74 'url': 'http://trailers.apple.com/ca/metropole/autrui/',
75 'only_matching': True,
78 _JSON_RE
= r
'iTunes.playURL\((.*?)\);'
80 def _real_extract(self
, url
):
81 mobj
= re
.match(self
._VALID
_URL
, url
)
82 movie
= mobj
.group('movie')
83 uploader_id
= mobj
.group('company')
85 playlist_url
= compat_urlparse
.urljoin(url
, 'includes/playlists/itunes.inc')
88 s
= re
.sub(r
'(?s)<script[^<]*?>.*?</script>', '', s
)
89 s
= re
.sub(r
'<img ([^<]*?)/?>', r
'<img \1/>', s
)
90 # The ' in the onClick attributes are not escaped, it couldn't be parsed
91 # like: http://trailers.apple.com/trailers/wb/gravity/
94 return 'iTunes.playURL(%s);' % m
.group(1).replace('\'', ''')
95 s
= re
.sub(self
._JSON
_RE
, _clean_json
, s
)
96 s
= '<html>%s</html>' % s
98 doc
= self
._download
_xml
(playlist_url
, movie
, transform_source
=fix_html
)
101 for li
in doc
.findall('./div/ul/li'):
102 on_click
= li
.find('.//a').attrib
['onClick']
103 trailer_info_json
= self
._search
_regex
(self
._JSON
_RE
,
104 on_click
, 'trailer info')
105 trailer_info
= json
.loads(trailer_info_json
)
106 first_url
= trailer_info
.get('url')
109 title
= trailer_info
['title']
110 video_id
= movie
+ '-' + re
.sub(r
'[^a-zA-Z0-9]', '', title
).lower()
111 thumbnail
= li
.find('.//img').attrib
['src']
112 upload_date
= trailer_info
['posted'].replace('-', '')
114 runtime
= trailer_info
['runtime']
115 m
= re
.search(r
'(?P<minutes>[0-9]+):(?P<seconds>[0-9]{1,2})', runtime
)
118 duration
= 60 * int(m
.group('minutes')) + int(m
.group('seconds'))
120 trailer_id
= first_url
.split('/')[-1].rpartition('_')[0].lower()
121 settings_json_url
= compat_urlparse
.urljoin(url
, 'includes/settings/%s.json' % trailer_id
)
122 settings
= self
._download
_json
(settings_json_url
, trailer_id
, 'Downloading settings json')
125 for format
in settings
['metadata']['sizes']:
126 # The src is a file pointing to the real video file
127 format_url
= re
.sub(r
'_(\d*p.mov)', r
'_h\1', format
['src'])
130 'format': format
['type'],
131 'width': int_or_none(format
['width']),
132 'height': int_or_none(format
['height']),
135 self
._sort
_formats
(formats
)
142 'duration': duration
,
143 'thumbnail': thumbnail
,
144 'upload_date': upload_date
,
145 'uploader_id': uploader_id
,
147 'User-Agent': 'QuickTime compatible (youtube-dl)',
158 class AppleTrailersSectionIE(InfoExtractor
):
159 IE_NAME
= 'appletrailers:section'
162 'feed_path': 'just_added',
163 'title': 'Just Added',
166 'feed_path': 'exclusive',
167 'title': 'Exclusive',
170 'feed_path': 'just_hd',
174 'feed_path': 'most_pop',
175 'title': 'Most Popular',
178 'feed_path': 'studios',
179 'title': 'Movie Studios',
182 _VALID_URL
= r
'https?://(?:www\.)?trailers\.apple\.com/#section=(?P<id>%s)' % '|'.join(_SECTIONS
)
184 'url': 'http://trailers.apple.com/#section=justadded',
186 'title': 'Just Added',
189 'playlist_mincount': 80,
191 'url': 'http://trailers.apple.com/#section=exclusive',
193 'title': 'Exclusive',
196 'playlist_mincount': 80,
198 'url': 'http://trailers.apple.com/#section=justhd',
203 'playlist_mincount': 80,
205 'url': 'http://trailers.apple.com/#section=mostpopular',
207 'title': 'Most Popular',
210 'playlist_mincount': 80,
212 'url': 'http://trailers.apple.com/#section=moviestudios',
214 'title': 'Movie Studios',
215 'id': 'moviestudios',
217 'playlist_mincount': 80,
220 def _real_extract(self
, url
):
221 section
= self
._match
_id
(url
)
222 section_data
= self
._download
_json
(
223 'http://trailers.apple.com/trailers/home/feeds/%s.json' % self
._SECTIONS
[section
]['feed_path'],
226 self
.url_result('http://trailers.apple.com' + e
['location'])
227 for e
in section_data
]
228 return self
.playlist_result(entries
, section
, self
._SECTIONS
[section
]['title'])