]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imdb.py
f95c00c7330f3db4b5354161804460cbc2bb53d0
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
13 class ImdbIE(InfoExtractor
):
15 IE_DESC
= 'Internet Movie Database trailers'
16 _VALID_URL
= r
'https?://(?:www|m)\.imdb\.com/(?:video/[^/]+/|title/tt\d+.*?#lb-|videoplayer/)vi(?P<id>\d+)'
19 'url': 'http://www.imdb.com/video/imdb/vi2524815897',
23 'title': 'Ice Age: Continental Drift Trailer (No. 2)',
24 'description': 'md5:9061c2219254e5d14e03c25c98e96a81',
27 'url': 'http://www.imdb.com/video/_/vi2524815897',
28 'only_matching': True,
30 'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897',
31 'only_matching': True,
33 'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897',
34 'only_matching': True,
36 'url': 'http://www.imdb.com/videoplayer/vi1562949145',
37 'only_matching': True,
40 def _real_extract(self
, url
):
41 video_id
= self
._match
_id
(url
)
42 webpage
= self
._download
_webpage
('http://www.imdb.com/video/imdb/vi%s' % video_id
, video_id
)
43 descr
= self
._html
_search
_regex
(
44 r
'(?s)<span itemprop="description">(.*?)</span>',
45 webpage
, 'description', fatal
=False)
46 player_url
= 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
47 player_page
= self
._download
_webpage
(
48 player_url
, video_id
, 'Downloading player page')
49 # the player page contains the info for the default format, we have to
50 # fetch other pages for the rest of the formats
51 extra_formats
= re
.findall(r
'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re
.escape(player_url
), player_page
)
53 self
._download
_webpage
(
54 f_url
, video_id
, 'Downloading info for %s format' % f_name
)
55 for f_url
, f_name
in extra_formats
]
56 format_pages
.append(player_page
)
58 quality
= qualities(('SD', '480p', '720p', '1080p'))
60 for format_page
in format_pages
:
61 json_data
= self
._search
_regex
(
62 r
'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
63 format_page
, 'json data', flags
=re
.DOTALL
)
64 info
= self
._parse
_json
(json_data
, video_id
, fatal
=False)
67 format_info
= info
.get('videoPlayerObject', {}).get('video', {})
70 video_info_list
= format_info
.get('videoInfoList')
71 if not video_info_list
or not isinstance(video_info_list
, list):
73 video_info
= video_info_list
[0]
74 if not video_info
or not isinstance(video_info
, dict):
76 video_url
= video_info
.get('videoUrl')
79 format_id
= format_info
.get('ffname')
81 'format_id': format_id
,
83 'ext': mimetype2ext(video_info
.get('videoMimeType')),
84 'quality': quality(format_id
),
86 self
._sort
_formats
(formats
)
90 'title': remove_end(self
._og
_search
_title
(webpage
), ' - IMDb'),
93 'thumbnail': format_info
.get('slate'),
97 class ImdbListIE(InfoExtractor
):
99 IE_DESC
= 'Internet Movie Database lists'
100 _VALID_URL
= r
'https?://(?:www\.)?imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
102 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
105 'title': 'March 23, 2012 Releases',
110 def _real_extract(self
, url
):
111 list_id
= self
._match
_id
(url
)
112 webpage
= self
._download
_webpage
(url
, list_id
)
114 self
.url_result('http://www.imdb.com' + m
, 'Imdb')
115 for m
in re
.findall(r
'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage
)]
117 list_title
= self
._html
_search
_regex
(
118 r
'<h1 class="header">(.*?)</h1>', webpage
, 'list title')
120 return self
.playlist_result(entries
, list_id
, list_title
)