5 from .common
import InfoExtractor
17 class ImdbIE(InfoExtractor
):
19 IE_DESC
= 'Internet Movie Database trailers'
20 _VALID_URL
= r
'https?://(?:www|m)\.imdb\.com/(?:video|title|list).*?[/-]vi(?P<id>\d+)'
23 'url': 'http://www.imdb.com/video/imdb/vi2524815897',
28 'description': 'md5:87bd0bdc61e351f21f20d2d7441cb4e7',
30 'thumbnail': r
're:^https?://.+\.jpg',
33 'url': 'https://www.imdb.com/video/vi3516832537',
37 'title': 'Paul: U.S. Trailer #1',
38 'description': 'md5:17fcc4fe11ec29b4399be9d4c5ef126c',
40 'thumbnail': r
're:^https?://.+\.jpg',
43 'url': 'http://www.imdb.com/video/_/vi2524815897',
44 'only_matching': True,
46 'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897',
47 'only_matching': True,
49 'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897',
50 'only_matching': True,
52 'url': 'http://www.imdb.com/videoplayer/vi1562949145',
53 'only_matching': True,
55 'url': 'http://www.imdb.com/title/tt4218696/videoplayer/vi2608641561',
56 'only_matching': True,
58 'url': 'https://www.imdb.com/list/ls009921623/videoplayer/vi260482329',
59 'only_matching': True,
62 def _real_extract(self
, url
):
63 video_id
= self
._match
_id
(url
)
64 webpage
= self
._download
_webpage
(f
'https://www.imdb.com/video/vi{video_id}', video_id
)
65 info
= self
._search
_nextjs
_data
(webpage
, video_id
)
66 video_info
= traverse_obj(info
, ('props', 'pageProps', 'videoPlaybackData', 'video'), default
={})
67 title
= (traverse_obj(video_info
, ('name', 'value'), ('primaryTitle', 'titleText', 'text'))
68 or self
._html
_search
_meta
(('og:title', 'twitter:title'), webpage
, default
=None)
69 or self
._html
_extract
_title
(webpage
))
70 data
= video_info
.get('playbackURLs') or try_get(self
._download
_json
(
71 'https://www.imdb.com/ve/data/VIDEO_PLAYBACK_DATA', video_id
,
73 'key': base64
.b64encode(json
.dumps({
74 'type': 'VIDEO_PLAYER',
75 'subType': 'FORCE_LEGACY',
76 'id': f
'vi{video_id}',
77 }).encode()).decode(),
78 }), lambda x
: x
[0]['videoLegacyEncodings'])
79 quality
= qualities(('SD', '480p', '720p', '1080p'))
80 formats
, subtitles
= [], {}
82 if not encoding
or not isinstance(encoding
, dict):
84 video_url
= url_or_none(encoding
.get('url'))
87 ext
= mimetype2ext(encoding
.get(
88 'mimeType')) or determine_ext(video_url
)
90 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
91 video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
92 preference
=1, m3u8_id
='hls', fatal
=False)
93 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
96 format_id
= traverse_obj(encoding
, ('displayName', 'value'), 'definition')
98 'format_id': format_id
,
101 'quality': quality(format_id
),
107 'alt_title': info
.get('videoSubTitle'),
109 'description': try_get(video_info
, lambda x
: x
['description']['value']),
110 'thumbnail': url_or_none(try_get(video_info
, lambda x
: x
['thumbnail']['url'])),
111 'duration': int_or_none(try_get(video_info
, lambda x
: x
['runtime']['value'])),
112 'subtitles': subtitles
,
116 class ImdbListIE(InfoExtractor
):
117 IE_NAME
= 'imdb:list'
118 IE_DESC
= 'Internet Movie Database lists'
119 _VALID_URL
= r
'https?://(?:www\.)?imdb\.com/list/ls(?P<id>\d{9})(?!/videoplayer/vi\d+)'
121 'url': 'https://www.imdb.com/list/ls009921623/',
124 'title': 'The Bourne Legacy',
125 'description': 'A list of trailers, clips, and more from The Bourne Legacy, starring Jeremy Renner and Rachel Weisz.',
130 def _real_extract(self
, url
):
131 list_id
= self
._match
_id
(url
)
132 webpage
= self
._download
_webpage
(url
, list_id
)
134 self
.url_result('http://www.imdb.com' + m
, 'Imdb')
135 for m
in re
.findall(rf
'href="(/list/ls{list_id}/videoplayer/vi[^"]+)"', webpage
)]
137 list_title
= self
._html
_search
_regex
(
138 r
'<h1[^>]+class="[^"]*header[^"]*"[^>]*>(.*?)</h1>',
139 webpage
, 'list title')
140 list_description
= self
._html
_search
_regex
(
141 r
'<div[^>]+class="[^"]*list-description[^"]*"[^>]*><p>(.*?)</p>',
142 webpage
, 'list description')
144 return self
.playlist_result(entries
, list_id
, list_title
, list_description
)