parent
7550ea501a
commit
0167f0dbfe
@ -7,23 +7,23 @@ from ..compat import compat_str
|
|||||||
from ..utils import (
|
from ..utils import (
|
||||||
determine_ext,
|
determine_ext,
|
||||||
mimetype2ext,
|
mimetype2ext,
|
||||||
|
parse_duration,
|
||||||
qualities,
|
qualities,
|
||||||
remove_end,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ImdbIE(InfoExtractor):
|
class ImdbIE(InfoExtractor):
|
||||||
IE_NAME = 'imdb'
|
IE_NAME = 'imdb'
|
||||||
IE_DESC = 'Internet Movie Database trailers'
|
IE_DESC = 'Internet Movie Database trailers'
|
||||||
_VALID_URL = r'https?://(?:www|m)\.imdb\.com/(?:video|title).+?[/-]vi(?P<id>\d+)'
|
_VALID_URL = r'https?://(?:www|m)\.imdb\.com/(?:video|title|list).+?[/-]vi(?P<id>\d+)'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://www.imdb.com/video/imdb/vi2524815897',
|
'url': 'http://www.imdb.com/video/imdb/vi2524815897',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '2524815897',
|
'id': '2524815897',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Ice Age: Continental Drift Trailer (No. 2)',
|
'title': 'No. 2 from Ice Age: Continental Drift (2012)',
|
||||||
'description': 'md5:9061c2219254e5d14e03c25c98e96a81',
|
'description': 'md5:87bd0bdc61e351f21f20d2d7441cb4e7',
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.imdb.com/video/_/vi2524815897',
|
'url': 'http://www.imdb.com/video/_/vi2524815897',
|
||||||
@ -40,82 +40,67 @@ class ImdbIE(InfoExtractor):
|
|||||||
}, {
|
}, {
|
||||||
'url': 'http://www.imdb.com/title/tt4218696/videoplayer/vi2608641561',
|
'url': 'http://www.imdb.com/title/tt4218696/videoplayer/vi2608641561',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.imdb.com/list/ls009921623/videoplayer/vi260482329',
|
||||||
|
'only_matching': True,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id)
|
webpage = self._download_webpage(
|
||||||
descr = self._html_search_regex(
|
'https://www.imdb.com/videoplayer/vi' + video_id, video_id)
|
||||||
r'(?s)<span itemprop="description">(.*?)</span>',
|
video_metadata = self._parse_json(self._search_regex(
|
||||||
webpage, 'description', fatal=False)
|
r'window\.IMDbReactInitialState\.push\(({.+?})\);', webpage,
|
||||||
player_url = 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
|
'video metadata'), video_id)['videos']['videoMetadata']['vi' + video_id]
|
||||||
player_page = self._download_webpage(
|
title = self._html_search_meta(
|
||||||
player_url, video_id, 'Downloading player page')
|
['og:title', 'twitter:title'], webpage) or self._html_search_regex(
|
||||||
# the player page contains the info for the default format, we have to
|
r'<title>(.+?)</title>', webpage, 'title', fatal=False) or video_metadata['title']
|
||||||
# fetch other pages for the rest of the formats
|
|
||||||
extra_formats = re.findall(r'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re.escape(player_url), player_page)
|
|
||||||
format_pages = [
|
|
||||||
self._download_webpage(
|
|
||||||
f_url, video_id, 'Downloading info for %s format' % f_name)
|
|
||||||
for f_url, f_name in extra_formats]
|
|
||||||
format_pages.append(player_page)
|
|
||||||
|
|
||||||
quality = qualities(('SD', '480p', '720p', '1080p'))
|
quality = qualities(('SD', '480p', '720p', '1080p'))
|
||||||
formats = []
|
formats = []
|
||||||
for format_page in format_pages:
|
for encoding in video_metadata.get('encodings', []):
|
||||||
json_data = self._search_regex(
|
if not encoding or not isinstance(encoding, dict):
|
||||||
r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
|
|
||||||
format_page, 'json data', flags=re.DOTALL)
|
|
||||||
info = self._parse_json(json_data, video_id, fatal=False)
|
|
||||||
if not info:
|
|
||||||
continue
|
continue
|
||||||
format_info = info.get('videoPlayerObject', {}).get('video', {})
|
video_url = encoding.get('videoUrl')
|
||||||
if not format_info:
|
|
||||||
continue
|
|
||||||
video_info_list = format_info.get('videoInfoList')
|
|
||||||
if not video_info_list or not isinstance(video_info_list, list):
|
|
||||||
continue
|
|
||||||
for video_info in video_info_list:
|
|
||||||
if not video_info or not isinstance(video_info, dict):
|
|
||||||
continue
|
|
||||||
video_url = video_info.get('videoUrl')
|
|
||||||
if not video_url or not isinstance(video_url, compat_str):
|
if not video_url or not isinstance(video_url, compat_str):
|
||||||
continue
|
continue
|
||||||
if (video_info.get('videoMimeType') == 'application/x-mpegURL' or
|
ext = determine_ext(video_url, mimetype2ext(encoding.get('mimeType')))
|
||||||
determine_ext(video_url) == 'm3u8'):
|
if ext == 'm3u8':
|
||||||
formats.extend(self._extract_m3u8_formats(
|
formats.extend(self._extract_m3u8_formats(
|
||||||
video_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
video_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
||||||
m3u8_id='hls', fatal=False))
|
m3u8_id='hls', fatal=False))
|
||||||
continue
|
continue
|
||||||
format_id = format_info.get('ffname')
|
format_id = encoding.get('definition')
|
||||||
formats.append({
|
formats.append({
|
||||||
'format_id': format_id,
|
'format_id': format_id,
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
'ext': mimetype2ext(video_info.get('videoMimeType')),
|
'ext': ext,
|
||||||
'quality': quality(format_id),
|
'quality': quality(format_id),
|
||||||
})
|
})
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': remove_end(self._og_search_title(webpage), ' - IMDb'),
|
'title': title,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'description': descr,
|
'description': video_metadata.get('description'),
|
||||||
'thumbnail': format_info.get('slate'),
|
'thumbnail': video_metadata.get('slate', {}).get('url'),
|
||||||
|
'duration': parse_duration(video_metadata.get('duration')),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ImdbListIE(InfoExtractor):
|
class ImdbListIE(InfoExtractor):
|
||||||
IE_NAME = 'imdb:list'
|
IE_NAME = 'imdb:list'
|
||||||
IE_DESC = 'Internet Movie Database lists'
|
IE_DESC = 'Internet Movie Database lists'
|
||||||
_VALID_URL = r'https?://(?:www\.)?imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
|
_VALID_URL = r'https?://(?:www\.)?imdb\.com/list/ls(?P<id>\d+)(?!/videoplayer/vi\d+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
|
'url': 'https://www.imdb.com/list/ls009921623/',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'JFs9NWw6XI0',
|
'id': '009921623',
|
||||||
'title': 'March 23, 2012 Releases',
|
'title': 'The Bourne Legacy',
|
||||||
|
'description': 'A list of trailers, clips, and more from The Bourne Legacy, starring Jeremy Renner and Rachel Weisz.',
|
||||||
},
|
},
|
||||||
'playlist_count': 7,
|
'playlist_count': 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
@ -123,9 +108,13 @@ class ImdbListIE(InfoExtractor):
|
|||||||
webpage = self._download_webpage(url, list_id)
|
webpage = self._download_webpage(url, list_id)
|
||||||
entries = [
|
entries = [
|
||||||
self.url_result('http://www.imdb.com' + m, 'Imdb')
|
self.url_result('http://www.imdb.com' + m, 'Imdb')
|
||||||
for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)]
|
for m in re.findall(r'href="(/list/ls%s/videoplayer/vi[^"]+)"' % list_id, webpage)]
|
||||||
|
|
||||||
list_title = self._html_search_regex(
|
list_title = self._html_search_regex(
|
||||||
r'<h1 class="header">(.*?)</h1>', webpage, 'list title')
|
r'<h1[^>]+class="[^"]*header[^"]*"[^>]*>(.*?)</h1>',
|
||||||
|
webpage, 'list title')
|
||||||
|
list_description = self._html_search_regex(
|
||||||
|
r'<div[^>]+class="[^"]*list-description[^"]*"[^>]*><p>(.*?)</p>',
|
||||||
|
webpage, 'list description')
|
||||||
|
|
||||||
return self.playlist_result(entries, list_id, list_title)
|
return self.playlist_result(entries, list_id, list_title, list_description)
|
||||||
|
Loading…
Reference in New Issue
Block a user