1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_str
15 class ImdbIE(InfoExtractor):
17 IE_DESC = 'Internet Movie Database trailers'
18 _VALID_URL = r'https?://(?:www|m)\.imdb\.com/(?:video|title).+?[/-]vi(?P<id>\d+)'
21 'url': 'http://www.imdb.com/video/imdb/vi2524815897',
25 'title': 'Ice Age: Continental Drift Trailer (No. 2)',
26 'description': 'md5:9061c2219254e5d14e03c25c98e96a81',
29 'url': 'http://www.imdb.com/video/_/vi2524815897',
30 'only_matching': True,
32 'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897',
33 'only_matching': True,
35 'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897',
36 'only_matching': True,
38 'url': 'http://www.imdb.com/videoplayer/vi1562949145',
39 'only_matching': True,
41 'url': 'http://www.imdb.com/title/tt4218696/videoplayer/vi2608641561',
42 'only_matching': True,
45 def _real_extract(self, url):
46 video_id = self._match_id(url)
47 webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id)
48 descr = self._html_search_regex(
49 r'(?s)<span itemprop="description">(.*?)</span>',
50 webpage, 'description', fatal=False)
51 player_url = 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
52 player_page = self._download_webpage(
53 player_url, video_id, 'Downloading player page')
54 # the player page contains the info for the default format, we have to
55 # fetch other pages for the rest of the formats
56 extra_formats = re.findall(r'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re.escape(player_url), player_page)
58 self._download_webpage(
59 f_url, video_id, 'Downloading info for %s format' % f_name)
60 for f_url, f_name in extra_formats]
61 format_pages.append(player_page)
63 quality = qualities(('SD', '480p', '720p', '1080p'))
65 for format_page in format_pages:
66 json_data = self._search_regex(
67 r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
68 format_page, 'json data', flags=re.DOTALL)
69 info = self._parse_json(json_data, video_id, fatal=False)
72 format_info = info.get('videoPlayerObject', {}).get('video', {})
75 video_info_list = format_info.get('videoInfoList')
76 if not video_info_list or not isinstance(video_info_list, list):
78 for video_info in video_info_list:
79 if not video_info or not isinstance(video_info, dict):
81 video_url = video_info.get('videoUrl')
82 if not video_url or not isinstance(video_url, compat_str):
84 if (video_info.get('videoMimeType') == 'application/x-mpegURL' or
85 determine_ext(video_url) == 'm3u8'):
86 formats.extend(self._extract_m3u8_formats(
87 video_url, video_id, 'mp4', entry_protocol='m3u8_native',
88 m3u8_id='hls', fatal=False))
90 format_id = format_info.get('ffname')
92 'format_id': format_id,
94 'ext': mimetype2ext(video_info.get('videoMimeType')),
95 'quality': quality(format_id),
97 self._sort_formats(formats)
101 'title': remove_end(self._og_search_title(webpage), ' - IMDb'),
103 'description': descr,
104 'thumbnail': format_info.get('slate'),
108 class ImdbListIE(InfoExtractor):
109 IE_NAME = 'imdb:list'
110 IE_DESC = 'Internet Movie Database lists'
111 _VALID_URL = r'https?://(?:www\.)?imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
113 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
116 'title': 'March 23, 2012 Releases',
121 def _real_extract(self, url):
122 list_id = self._match_id(url)
123 webpage = self._download_webpage(url, list_id)
125 self.url_result('http://www.imdb.com' + m, 'Imdb')
126 for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)]
128 list_title = self._html_search_regex(
129 r'<h1 class="header">(.*?)</h1>', webpage, 'list title')
131 return self.playlist_result(entries, list_id, list_title)