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/[^/]+/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,
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
32 webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id)
33 descr = self._html_search_regex(
34 r'(?s)<span itemprop="description">(.*?)</span>',
35 webpage, 'description', fatal=False)
36 player_url = 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
37 player_page = self._download_webpage(
38 player_url, video_id, 'Downloading player page')
39 # the player page contains the info for the default format, we have to
40 # fetch other pages for the rest of the formats
41 extra_formats = re.findall(r'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re.escape(player_url), player_page)
43 self._download_webpage(
44 f_url, video_id, 'Downloading info for %s format' % f_name)
45 for f_url, f_name in extra_formats]
46 format_pages.append(player_page)
48 quality = qualities(('SD', '480p', '720p', '1080p'))
50 for format_page in format_pages:
51 json_data = self._search_regex(
52 r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
53 format_page, 'json data', flags=re.DOTALL)
54 info = self._parse_json(json_data, video_id, fatal=False)
57 format_info = info.get('videoPlayerObject', {}).get('video', {})
60 video_info_list = format_info.get('videoInfoList')
61 if not video_info_list or not isinstance(video_info_list, list):
63 video_info = video_info_list[0]
64 if not video_info or not isinstance(video_info, dict):
66 video_url = video_info.get('videoUrl')
69 format_id = format_info.get('ffname')
71 'format_id': format_id,
73 'ext': mimetype2ext(video_info.get('videoMimeType')),
74 'quality': quality(format_id),
76 self._sort_formats(formats)
80 'title': self._og_search_title(webpage),
83 'thumbnail': format_info['slate'],
87 class ImdbListIE(InfoExtractor):
89 IE_DESC = 'Internet Movie Database lists'
90 _VALID_URL = r'https?://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
92 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
95 'title': 'March 23, 2012 Releases',
100 def _real_extract(self, url):
101 list_id = self._match_id(url)
102 webpage = self._download_webpage(url, list_id)
104 self.url_result('http://www.imdb.com' + m, 'Imdb')
105 for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)]
107 list_title = self._html_search_regex(
108 r'<h1 class="header">(.*?)</h1>', webpage, 'list title')
110 return self.playlist_result(entries, list_id, list_title)