]>
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 | |
1cc79574 | 7 | from ..compat import ( |
d8d61486 | 8 | compat_urlparse, |
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) | |
d8d61486 JMF |
33 | available_formats = re.findall( |
34 | r'case \'(?P<f_id>.*?)\' :$\s+url = \'(?P<path>.*?)\'', webpage, | |
35 | flags=re.MULTILINE) | |
36 | formats = [] | |
37 | for f_id, f_path in available_formats: | |
d349cd22 | 38 | f_path = f_path.strip() |
d8d61486 JMF |
39 | format_page = self._download_webpage( |
40 | compat_urlparse.urljoin(url, f_path), | |
ecfef3e5 | 41 | 'Downloading info for %s format' % f_id) |
b03d0d06 JMF |
42 | json_data = self._search_regex( |
43 | r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>', | |
ecfef3e5 | 44 | format_page, 'json data', flags=re.DOTALL) |
d8d61486 JMF |
45 | info = json.loads(json_data) |
46 | format_info = info['videoPlayerObject']['video'] | |
47 | formats.append({ | |
48 | 'format_id': f_id, | |
49 | 'url': format_info['url'], | |
d8d61486 JMF |
50 | }) |
51 | ||
52 | return { | |
53 | 'id': video_id, | |
54 | 'title': self._og_search_title(webpage), | |
55 | 'formats': formats, | |
56 | 'description': descr, | |
57 | 'thumbnail': format_info['slate'], | |
d8d61486 | 58 | } |
c645c765 | 59 | |
ecfef3e5 | 60 | |
c645c765 | 61 | class ImdbListIE(InfoExtractor): |
ecfef3e5 PH |
62 | IE_NAME = 'imdb:list' |
63 | IE_DESC = 'Internet Movie Database lists' | |
c645c765 | 64 | _VALID_URL = r'http://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})' |
22a6f150 PH |
65 | _TEST = { |
66 | 'url': 'http://www.imdb.com/list/JFs9NWw6XI0', | |
67 | 'info_dict': { | |
68 | 'id': 'JFs9NWw6XI0', | |
69 | 'title': 'March 23, 2012 Releases', | |
70 | }, | |
71 | 'playlist_count': 7, | |
72 | } | |
5f6a1245 | 73 | |
c645c765 | 74 | def _real_extract(self, url): |
11fba175 | 75 | list_id = self._match_id(url) |
d7b51547 | 76 | webpage = self._download_webpage(url, list_id) |
d7b51547 PH |
77 | entries = [ |
78 | self.url_result('http://www.imdb.com' + m, 'Imdb') | |
a3978a61 | 79 | for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)] |
d7b51547 PH |
80 | |
81 | list_title = self._html_search_regex( | |
82 | r'<h1 class="header">(.*?)</h1>', webpage, 'list title') | |
83 | ||
ecfef3e5 | 84 | return self.playlist_result(entries, list_id, list_title) |