]>
Commit | Line | Data |
---|---|---|
ecfef3e5 PH |
1 | from __future__ import unicode_literals |
2 | ||
d8d61486 JMF |
3 | import re |
4 | import json | |
5 | ||
6 | from .common import InfoExtractor | |
dd67702a JMF |
7 | from ..utils import ( |
8 | qualities, | |
d8d61486 JMF |
9 | ) |
10 | ||
11 | ||
12 | class ImdbIE(InfoExtractor): | |
ecfef3e5 PH |
13 | IE_NAME = 'imdb' |
14 | IE_DESC = 'Internet Movie Database trailers' | |
97e302a4 | 15 | _VALID_URL = r'http://(?:www|m)\.imdb\.com/video/imdb/vi(?P<id>\d+)' |
d8d61486 JMF |
16 | |
17 | _TEST = { | |
ecfef3e5 | 18 | 'url': 'http://www.imdb.com/video/imdb/vi2524815897', |
ecfef3e5 PH |
19 | 'info_dict': { |
20 | 'id': '2524815897', | |
21 | 'ext': 'mp4', | |
22 | 'title': 'Ice Age: Continental Drift Trailer (No. 2) - IMDb', | |
23 | 'description': 'md5:9061c2219254e5d14e03c25c98e96a81', | |
d8d61486 JMF |
24 | } |
25 | } | |
26 | ||
27 | def _real_extract(self, url): | |
11fba175 | 28 | video_id = self._match_id(url) |
97e302a4 | 29 | webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id) |
11fba175 PH |
30 | descr = self._html_search_regex( |
31 | r'(?s)<span itemprop="description">(.*?)</span>', | |
32 | webpage, 'description', fatal=False) | |
dd67702a JMF |
33 | player_url = 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id |
34 | player_page = self._download_webpage( | |
35 | player_url, video_id, 'Downloading player page') | |
36 | # the player page contains the info for the default format, we have to | |
37 | # fetch other pages for the rest of the formats | |
38 | extra_formats = re.findall(r'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re.escape(player_url), player_page) | |
39 | format_pages = [ | |
40 | self._download_webpage( | |
41 | f_url, video_id, 'Downloading info for %s format' % f_name) | |
42 | for f_url, f_name in extra_formats] | |
43 | format_pages.append(player_page) | |
44 | ||
45 | quality = qualities(['SD', '480p', '720p']) | |
d8d61486 | 46 | formats = [] |
dd67702a | 47 | for format_page in format_pages: |
b03d0d06 JMF |
48 | json_data = self._search_regex( |
49 | r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>', | |
ecfef3e5 | 50 | format_page, 'json data', flags=re.DOTALL) |
d8d61486 JMF |
51 | info = json.loads(json_data) |
52 | format_info = info['videoPlayerObject']['video'] | |
dd67702a | 53 | f_id = format_info['ffname'] |
d8d61486 JMF |
54 | formats.append({ |
55 | 'format_id': f_id, | |
c9ac7fa9 | 56 | 'url': format_info['videoInfoList'][0]['videoUrl'], |
dd67702a | 57 | 'quality': quality(f_id), |
d8d61486 | 58 | }) |
dd67702a | 59 | self._sort_formats(formats) |
d8d61486 JMF |
60 | |
61 | return { | |
62 | 'id': video_id, | |
63 | 'title': self._og_search_title(webpage), | |
64 | 'formats': formats, | |
65 | 'description': descr, | |
66 | 'thumbnail': format_info['slate'], | |
d8d61486 | 67 | } |
c645c765 | 68 | |
ecfef3e5 | 69 | |
c645c765 | 70 | class ImdbListIE(InfoExtractor): |
ecfef3e5 PH |
71 | IE_NAME = 'imdb:list' |
72 | IE_DESC = 'Internet Movie Database lists' | |
c645c765 | 73 | _VALID_URL = r'http://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})' |
22a6f150 PH |
74 | _TEST = { |
75 | 'url': 'http://www.imdb.com/list/JFs9NWw6XI0', | |
76 | 'info_dict': { | |
77 | 'id': 'JFs9NWw6XI0', | |
78 | 'title': 'March 23, 2012 Releases', | |
79 | }, | |
80 | 'playlist_count': 7, | |
81 | } | |
5f6a1245 | 82 | |
c645c765 | 83 | def _real_extract(self, url): |
11fba175 | 84 | list_id = self._match_id(url) |
d7b51547 | 85 | webpage = self._download_webpage(url, list_id) |
d7b51547 PH |
86 | entries = [ |
87 | self.url_result('http://www.imdb.com' + m, 'Imdb') | |
a3978a61 | 88 | for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)] |
d7b51547 PH |
89 | |
90 | list_title = self._html_search_regex( | |
91 | r'<h1 class="header">(.*?)</h1>', webpage, 'list title') | |
92 | ||
ecfef3e5 | 93 | return self.playlist_result(entries, list_id, list_title) |