]>
Commit | Line | Data |
---|---|---|
ecfef3e5 PH |
1 | from __future__ import unicode_literals |
2 | ||
d8d61486 | 3 | import re |
d8d61486 JMF |
4 | |
5 | from .common import InfoExtractor | |
7dd6ab4a | 6 | from ..compat import compat_str |
dd67702a | 7 | from ..utils import ( |
7dd6ab4a | 8 | determine_ext, |
96c2e3e9 | 9 | mimetype2ext, |
dd67702a | 10 | qualities, |
5b9d187c | 11 | remove_end, |
d8d61486 JMF |
12 | ) |
13 | ||
14 | ||
15 | class ImdbIE(InfoExtractor): | |
ecfef3e5 PH |
16 | IE_NAME = 'imdb' |
17 | IE_DESC = 'Internet Movie Database trailers' | |
b8457665 | 18 | _VALID_URL = r'https?://(?:www|m)\.imdb\.com/(?:video|title).+?[/-]vi(?P<id>\d+)' |
d8d61486 | 19 | |
f196508f | 20 | _TESTS = [{ |
ecfef3e5 | 21 | 'url': 'http://www.imdb.com/video/imdb/vi2524815897', |
ecfef3e5 PH |
22 | 'info_dict': { |
23 | 'id': '2524815897', | |
24 | 'ext': 'mp4', | |
5b9d187c | 25 | 'title': 'Ice Age: Continental Drift Trailer (No. 2)', |
ecfef3e5 | 26 | 'description': 'md5:9061c2219254e5d14e03c25c98e96a81', |
d8d61486 | 27 | } |
f196508f S |
28 | }, { |
29 | 'url': 'http://www.imdb.com/video/_/vi2524815897', | |
30 | 'only_matching': True, | |
4c93ee8d S |
31 | }, { |
32 | 'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897', | |
33 | 'only_matching': True, | |
34 | }, { | |
35 | 'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897', | |
36 | 'only_matching': True, | |
13607896 S |
37 | }, { |
38 | 'url': 'http://www.imdb.com/videoplayer/vi1562949145', | |
39 | 'only_matching': True, | |
b8457665 S |
40 | }, { |
41 | 'url': 'http://www.imdb.com/title/tt4218696/videoplayer/vi2608641561', | |
42 | 'only_matching': True, | |
f196508f | 43 | }] |
d8d61486 JMF |
44 | |
45 | def _real_extract(self, url): | |
11fba175 | 46 | video_id = self._match_id(url) |
97e302a4 | 47 | webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id) |
11fba175 PH |
48 | descr = self._html_search_regex( |
49 | r'(?s)<span itemprop="description">(.*?)</span>', | |
50 | webpage, 'description', fatal=False) | |
dd67702a JMF |
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) | |
57 | format_pages = [ | |
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) | |
62 | ||
f7f2e53a | 63 | quality = qualities(('SD', '480p', '720p', '1080p')) |
d8d61486 | 64 | formats = [] |
dd67702a | 65 | for format_page in format_pages: |
b03d0d06 JMF |
66 | json_data = self._search_regex( |
67 | r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>', | |
ecfef3e5 | 68 | format_page, 'json data', flags=re.DOTALL) |
96c2e3e9 S |
69 | info = self._parse_json(json_data, video_id, fatal=False) |
70 | if not info: | |
71 | continue | |
72 | format_info = info.get('videoPlayerObject', {}).get('video', {}) | |
73 | if not format_info: | |
74 | continue | |
75 | video_info_list = format_info.get('videoInfoList') | |
76 | if not video_info_list or not isinstance(video_info_list, list): | |
77 | continue | |
7dd6ab4a S |
78 | for video_info in video_info_list: |
79 | if not video_info or not isinstance(video_info, dict): | |
80 | continue | |
81 | video_url = video_info.get('videoUrl') | |
82 | if not video_url or not isinstance(video_url, compat_str): | |
83 | continue | |
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)) | |
89 | continue | |
90 | format_id = format_info.get('ffname') | |
91 | formats.append({ | |
92 | 'format_id': format_id, | |
93 | 'url': video_url, | |
94 | 'ext': mimetype2ext(video_info.get('videoMimeType')), | |
95 | 'quality': quality(format_id), | |
96 | }) | |
dd67702a | 97 | self._sort_formats(formats) |
d8d61486 JMF |
98 | |
99 | return { | |
100 | 'id': video_id, | |
5b9d187c | 101 | 'title': remove_end(self._og_search_title(webpage), ' - IMDb'), |
d8d61486 JMF |
102 | 'formats': formats, |
103 | 'description': descr, | |
5b9d187c | 104 | 'thumbnail': format_info.get('slate'), |
d8d61486 | 105 | } |
c645c765 | 106 | |
ecfef3e5 | 107 | |
c645c765 | 108 | class ImdbListIE(InfoExtractor): |
ecfef3e5 PH |
109 | IE_NAME = 'imdb:list' |
110 | IE_DESC = 'Internet Movie Database lists' | |
92519402 | 111 | _VALID_URL = r'https?://(?:www\.)?imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})' |
22a6f150 PH |
112 | _TEST = { |
113 | 'url': 'http://www.imdb.com/list/JFs9NWw6XI0', | |
114 | 'info_dict': { | |
115 | 'id': 'JFs9NWw6XI0', | |
116 | 'title': 'March 23, 2012 Releases', | |
117 | }, | |
118 | 'playlist_count': 7, | |
119 | } | |
5f6a1245 | 120 | |
c645c765 | 121 | def _real_extract(self, url): |
11fba175 | 122 | list_id = self._match_id(url) |
d7b51547 | 123 | webpage = self._download_webpage(url, list_id) |
d7b51547 PH |
124 | entries = [ |
125 | self.url_result('http://www.imdb.com' + m, 'Imdb') | |
a3978a61 | 126 | for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)] |
d7b51547 PH |
127 | |
128 | list_title = self._html_search_regex( | |
129 | r'<h1 class="header">(.*?)</h1>', webpage, 'list title') | |
130 | ||
ecfef3e5 | 131 | return self.playlist_result(entries, list_id, list_title) |