]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/imdb.py
[prosiebensat1] extract all formats
[yt-dlp.git] / youtube_dl / extractor / imdb.py
CommitLineData
ecfef3e5
PH
1from __future__ import unicode_literals
2
d8d61486 3import re
d8d61486
JMF
4
5from .common import InfoExtractor
dd67702a 6from ..utils import (
96c2e3e9 7 mimetype2ext,
dd67702a 8 qualities,
d8d61486
JMF
9)
10
11
12class ImdbIE(InfoExtractor):
ecfef3e5
PH
13 IE_NAME = 'imdb'
14 IE_DESC = 'Internet Movie Database trailers'
4c93ee8d 15 _VALID_URL = r'https?://(?:www|m)\.imdb\.com/(?:video/[^/]+/|title/tt\d+.*?#lb-)vi(?P<id>\d+)'
d8d61486 16
f196508f 17 _TESTS = [{
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 24 }
f196508f
S
25 }, {
26 'url': 'http://www.imdb.com/video/_/vi2524815897',
27 'only_matching': True,
4c93ee8d
S
28 }, {
29 'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897',
30 'only_matching': True,
31 }, {
32 'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897',
33 'only_matching': True,
f196508f 34 }]
d8d61486
JMF
35
36 def _real_extract(self, url):
11fba175 37 video_id = self._match_id(url)
97e302a4 38 webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id)
11fba175
PH
39 descr = self._html_search_regex(
40 r'(?s)<span itemprop="description">(.*?)</span>',
41 webpage, 'description', fatal=False)
dd67702a
JMF
42 player_url = 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
43 player_page = self._download_webpage(
44 player_url, video_id, 'Downloading player page')
45 # the player page contains the info for the default format, we have to
46 # fetch other pages for the rest of the formats
47 extra_formats = re.findall(r'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re.escape(player_url), player_page)
48 format_pages = [
49 self._download_webpage(
50 f_url, video_id, 'Downloading info for %s format' % f_name)
51 for f_url, f_name in extra_formats]
52 format_pages.append(player_page)
53
f7f2e53a 54 quality = qualities(('SD', '480p', '720p', '1080p'))
d8d61486 55 formats = []
dd67702a 56 for format_page in format_pages:
b03d0d06
JMF
57 json_data = self._search_regex(
58 r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
ecfef3e5 59 format_page, 'json data', flags=re.DOTALL)
96c2e3e9
S
60 info = self._parse_json(json_data, video_id, fatal=False)
61 if not info:
62 continue
63 format_info = info.get('videoPlayerObject', {}).get('video', {})
64 if not format_info:
65 continue
66 video_info_list = format_info.get('videoInfoList')
67 if not video_info_list or not isinstance(video_info_list, list):
68 continue
69 video_info = video_info_list[0]
70 if not video_info or not isinstance(video_info, dict):
71 continue
72 video_url = video_info.get('videoUrl')
73 if not video_url:
74 continue
75 format_id = format_info.get('ffname')
d8d61486 76 formats.append({
96c2e3e9
S
77 'format_id': format_id,
78 'url': video_url,
79 'ext': mimetype2ext(video_info.get('videoMimeType')),
80 'quality': quality(format_id),
d8d61486 81 })
dd67702a 82 self._sort_formats(formats)
d8d61486
JMF
83
84 return {
85 'id': video_id,
86 'title': self._og_search_title(webpage),
87 'formats': formats,
88 'description': descr,
89 'thumbnail': format_info['slate'],
d8d61486 90 }
c645c765 91
ecfef3e5 92
c645c765 93class ImdbListIE(InfoExtractor):
ecfef3e5
PH
94 IE_NAME = 'imdb:list'
95 IE_DESC = 'Internet Movie Database lists'
5886b38d 96 _VALID_URL = r'https?://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
22a6f150
PH
97 _TEST = {
98 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
99 'info_dict': {
100 'id': 'JFs9NWw6XI0',
101 'title': 'March 23, 2012 Releases',
102 },
103 'playlist_count': 7,
104 }
5f6a1245 105
c645c765 106 def _real_extract(self, url):
11fba175 107 list_id = self._match_id(url)
d7b51547 108 webpage = self._download_webpage(url, list_id)
d7b51547
PH
109 entries = [
110 self.url_result('http://www.imdb.com' + m, 'Imdb')
a3978a61 111 for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)]
d7b51547
PH
112
113 list_title = self._html_search_regex(
114 r'<h1 class="header">(.*?)</h1>', webpage, 'list title')
115
ecfef3e5 116 return self.playlist_result(entries, list_id, list_title)