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