]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imdb.py
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).+?[/-]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,
39 'url': 'http://www.imdb.com/title/tt4218696/videoplayer/vi2608641561',
40 'only_matching': True,
43 def _real_extract(self
, url
):
44 video_id
= self
._match
_id
(url
)
45 webpage
= self
._download
_webpage
('http://www.imdb.com/video/imdb/vi%s' % video_id
, video_id
)
46 descr
= self
._html
_search
_regex
(
47 r
'(?s)<span itemprop="description">(.*?)</span>',
48 webpage
, 'description', fatal
=False)
49 player_url
= 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
50 player_page
= self
._download
_webpage
(
51 player_url
, video_id
, 'Downloading player page')
52 # the player page contains the info for the default format, we have to
53 # fetch other pages for the rest of the formats
54 extra_formats
= re
.findall(r
'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re
.escape(player_url
), player_page
)
56 self
._download
_webpage
(
57 f_url
, video_id
, 'Downloading info for %s format' % f_name
)
58 for f_url
, f_name
in extra_formats
]
59 format_pages
.append(player_page
)
61 quality
= qualities(('SD', '480p', '720p', '1080p'))
63 for format_page
in format_pages
:
64 json_data
= self
._search
_regex
(
65 r
'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
66 format_page
, 'json data', flags
=re
.DOTALL
)
67 info
= self
._parse
_json
(json_data
, video_id
, fatal
=False)
70 format_info
= info
.get('videoPlayerObject', {}).get('video', {})
73 video_info_list
= format_info
.get('videoInfoList')
74 if not video_info_list
or not isinstance(video_info_list
, list):
76 video_info
= video_info_list
[0]
77 if not video_info
or not isinstance(video_info
, dict):
79 video_url
= video_info
.get('videoUrl')
82 format_id
= format_info
.get('ffname')
84 'format_id': format_id
,
86 'ext': mimetype2ext(video_info
.get('videoMimeType')),
87 'quality': quality(format_id
),
89 self
._sort
_formats
(formats
)
93 'title': remove_end(self
._og
_search
_title
(webpage
), ' - IMDb'),
96 'thumbnail': format_info
.get('slate'),
100 class ImdbListIE(InfoExtractor
):
101 IE_NAME
= 'imdb:list'
102 IE_DESC
= 'Internet Movie Database lists'
103 _VALID_URL
= r
'https?://(?:www\.)?imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
105 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
108 'title': 'March 23, 2012 Releases',
113 def _real_extract(self
, url
):
114 list_id
= self
._match
_id
(url
)
115 webpage
= self
._download
_webpage
(url
, list_id
)
117 self
.url_result('http://www.imdb.com' + m
, 'Imdb')
118 for m
in re
.findall(r
'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage
)]
120 list_title
= self
._html
_search
_regex
(
121 r
'<h1 class="header">(.*?)</h1>', webpage
, 'list title')
123 return self
.playlist_result(entries
, list_id
, list_title
)