]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imdb.py
0acce9f4c2525a62e3d3ad22b16743737dbb5b07
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
12 class ImdbIE(InfoExtractor
):
14 IE_DESC
= 'Internet Movie Database trailers'
15 _VALID_URL
= r
'https?://(?:www|m)\.imdb\.com/(?:video/[^/]+/|title/tt\d+.*?#lb-)vi(?P<id>\d+)'
18 'url': 'http://www.imdb.com/video/imdb/vi2524815897',
22 'title': 'Ice Age: Continental Drift Trailer (No. 2) - IMDb',
23 'description': 'md5:9061c2219254e5d14e03c25c98e96a81',
26 'url': 'http://www.imdb.com/video/_/vi2524815897',
27 'only_matching': True,
29 'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897',
30 'only_matching': True,
32 'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897',
33 'only_matching': True,
36 def _real_extract(self
, url
):
37 video_id
= self
._match
_id
(url
)
38 webpage
= self
._download
_webpage
('http://www.imdb.com/video/imdb/vi%s' % video_id
, video_id
)
39 descr
= self
._html
_search
_regex
(
40 r
'(?s)<span itemprop="description">(.*?)</span>',
41 webpage
, 'description', fatal
=False)
42 player_url
= 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
43 player_page
= self
._download
_webpage
(
44 player_url
, video_id
, 'Downloading player page')
45 # the player page contains the info for the default format, we have to
46 # fetch other pages for the rest of the formats
47 extra_formats
= re
.findall(r
'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re
.escape(player_url
), player_page
)
49 self
._download
_webpage
(
50 f_url
, video_id
, 'Downloading info for %s format' % f_name
)
51 for f_url
, f_name
in extra_formats
]
52 format_pages
.append(player_page
)
54 quality
= qualities(('SD', '480p', '720p', '1080p'))
56 for format_page
in format_pages
:
57 json_data
= self
._search
_regex
(
58 r
'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
59 format_page
, 'json data', flags
=re
.DOTALL
)
60 info
= self
._parse
_json
(json_data
, video_id
, fatal
=False)
63 format_info
= info
.get('videoPlayerObject', {}).get('video', {})
66 video_info_list
= format_info
.get('videoInfoList')
67 if not video_info_list
or not isinstance(video_info_list
, list):
69 video_info
= video_info_list
[0]
70 if not video_info
or not isinstance(video_info
, dict):
72 video_url
= video_info
.get('videoUrl')
75 format_id
= format_info
.get('ffname')
77 'format_id': format_id
,
79 'ext': mimetype2ext(video_info
.get('videoMimeType')),
80 'quality': quality(format_id
),
82 self
._sort
_formats
(formats
)
86 'title': self
._og
_search
_title
(webpage
),
89 'thumbnail': format_info
['slate'],
93 class ImdbListIE(InfoExtractor
):
95 IE_DESC
= 'Internet Movie Database lists'
96 _VALID_URL
= r
'https?://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
98 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
101 'title': 'March 23, 2012 Releases',
106 def _real_extract(self
, url
):
107 list_id
= self
._match
_id
(url
)
108 webpage
= self
._download
_webpage
(url
, list_id
)
110 self
.url_result('http://www.imdb.com' + m
, 'Imdb')
111 for m
in re
.findall(r
'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage
)]
113 list_title
= self
._html
_search
_regex
(
114 r
'<h1 class="header">(.*?)</h1>', webpage
, 'list title')
116 return self
.playlist_result(entries
, list_id
, list_title
)