Merge pull request #236 from ytdl-org/master
[pull] master from ytdl-org:master
This commit is contained in:
commit
e850753621
@ -5,6 +5,7 @@ from .common import InfoExtractor
|
|||||||
from ..utils import (
|
from ..utils import (
|
||||||
clean_html,
|
clean_html,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
|
js_to_json,
|
||||||
try_get,
|
try_get,
|
||||||
unified_strdate,
|
unified_strdate,
|
||||||
)
|
)
|
||||||
@ -13,22 +14,21 @@ from ..utils import (
|
|||||||
class AmericasTestKitchenIE(InfoExtractor):
|
class AmericasTestKitchenIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?americastestkitchen\.com/(?:episode|videos)/(?P<id>\d+)'
|
_VALID_URL = r'https?://(?:www\.)?americastestkitchen\.com/(?:episode|videos)/(?P<id>\d+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.americastestkitchen.com/episode/548-summer-dinner-party',
|
'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
|
||||||
'md5': 'b861c3e365ac38ad319cfd509c30577f',
|
'md5': 'b861c3e365ac38ad319cfd509c30577f',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '1_5g5zua6e',
|
'id': '5b400b9ee338f922cb06450c',
|
||||||
'title': 'Summer Dinner Party',
|
'title': 'Weeknight Japanese Suppers',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'description': 'md5:858d986e73a4826979b6a5d9f8f6a1ec',
|
'description': 'md5:3d0c1a44bb3b27607ce82652db25b4a8',
|
||||||
'thumbnail': r're:^https?://.*\.jpg',
|
'thumbnail': r're:^https?://',
|
||||||
'timestamp': 1497285541,
|
'timestamp': 1523664000,
|
||||||
'upload_date': '20170612',
|
'upload_date': '20180414',
|
||||||
'uploader_id': 'roger.metcalf@americastestkitchen.com',
|
'release_date': '20180414',
|
||||||
'release_date': '20170617',
|
|
||||||
'series': "America's Test Kitchen",
|
'series': "America's Test Kitchen",
|
||||||
'season_number': 17,
|
'season_number': 18,
|
||||||
'episode': 'Summer Dinner Party',
|
'episode': 'Weeknight Japanese Suppers',
|
||||||
'episode_number': 24,
|
'episode_number': 15,
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'skip_download': True,
|
'skip_download': True,
|
||||||
@ -47,7 +47,7 @@ class AmericasTestKitchenIE(InfoExtractor):
|
|||||||
self._search_regex(
|
self._search_regex(
|
||||||
r'window\.__INITIAL_STATE__\s*=\s*({.+?})\s*;\s*</script>',
|
r'window\.__INITIAL_STATE__\s*=\s*({.+?})\s*;\s*</script>',
|
||||||
webpage, 'initial context'),
|
webpage, 'initial context'),
|
||||||
video_id)
|
video_id, js_to_json)
|
||||||
|
|
||||||
ep_data = try_get(
|
ep_data = try_get(
|
||||||
video_data,
|
video_data,
|
||||||
@ -55,17 +55,7 @@ class AmericasTestKitchenIE(InfoExtractor):
|
|||||||
lambda x: x['videoDetail']['content']['data']), dict)
|
lambda x: x['videoDetail']['content']['data']), dict)
|
||||||
ep_meta = ep_data.get('full_video', {})
|
ep_meta = ep_data.get('full_video', {})
|
||||||
|
|
||||||
zype_id = ep_meta.get('zype_id')
|
zype_id = ep_data.get('zype_id') or ep_meta['zype_id']
|
||||||
if zype_id:
|
|
||||||
embed_url = 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % zype_id
|
|
||||||
ie_key = 'Zype'
|
|
||||||
else:
|
|
||||||
partner_id = self._search_regex(
|
|
||||||
r'src=["\'](?:https?:)?//(?:[^/]+\.)kaltura\.com/(?:[^/]+/)*(?:p|partner_id)/(\d+)',
|
|
||||||
webpage, 'kaltura partner id')
|
|
||||||
external_id = ep_data.get('external_id') or ep_meta['external_id']
|
|
||||||
embed_url = 'kaltura:%s:%s' % (partner_id, external_id)
|
|
||||||
ie_key = 'Kaltura'
|
|
||||||
|
|
||||||
title = ep_data.get('title') or ep_meta.get('title')
|
title = ep_data.get('title') or ep_meta.get('title')
|
||||||
description = clean_html(ep_meta.get('episode_description') or ep_data.get(
|
description = clean_html(ep_meta.get('episode_description') or ep_data.get(
|
||||||
@ -79,8 +69,8 @@ class AmericasTestKitchenIE(InfoExtractor):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
'_type': 'url_transparent',
|
'_type': 'url_transparent',
|
||||||
'url': embed_url,
|
'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % zype_id,
|
||||||
'ie_key': ie_key,
|
'ie_key': 'Zype',
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
|
@ -2098,6 +2098,9 @@ class GenericIE(InfoExtractor):
|
|||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Smoky Barbecue Favorites',
|
'title': 'Smoky Barbecue Favorites',
|
||||||
'thumbnail': r're:^https?://.*\.jpe?g',
|
'thumbnail': r're:^https?://.*\.jpe?g',
|
||||||
|
'description': 'md5:5ff01e76316bd8d46508af26dc86023b',
|
||||||
|
'upload_date': '20170909',
|
||||||
|
'timestamp': 1504915200,
|
||||||
},
|
},
|
||||||
'add_ie': [ZypeIE.ie_key()],
|
'add_ie': [ZypeIE.ie_key()],
|
||||||
'params': {
|
'params': {
|
||||||
|
@ -1,21 +1,12 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
|
||||||
dict_get,
|
|
||||||
float_or_none,
|
|
||||||
int_or_none,
|
|
||||||
unified_timestamp,
|
|
||||||
update_url_query,
|
|
||||||
url_or_none,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TruNewsIE(InfoExtractor):
|
class TruNewsIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?trunews\.com/stream/(?P<id>[^/?#&]+)'
|
_VALID_URL = r'https?://(?:www\.)?trunews\.com/stream/(?P<id>[^/?#&]+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'https://www.trunews.com/stream/will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
|
'url': 'https://www.trunews.com/stream/will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
|
||||||
'md5': 'a19c024c3906ff954fac9b96ce66bb08',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '5c5a21e65d3c196e1c0020cc',
|
'id': '5c5a21e65d3c196e1c0020cc',
|
||||||
'display_id': 'will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
|
'display_id': 'will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
|
||||||
@ -28,48 +19,16 @@ class TruNewsIE(InfoExtractor):
|
|||||||
},
|
},
|
||||||
'add_ie': ['Zype'],
|
'add_ie': ['Zype'],
|
||||||
}
|
}
|
||||||
|
_ZYPE_TEMPL = 'https://player.zype.com/embed/%s.js?api_key=X5XnahkjCwJrT_l5zUqypnaLEObotyvtUKJWWlONxDoHVjP8vqxlArLV8llxMbyt'
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
|
|
||||||
video = self._download_json(
|
zype_id = self._download_json(
|
||||||
'https://api.zype.com/videos', display_id, query={
|
'https://api.zype.com/videos', display_id, query={
|
||||||
'app_key': 'PUVKp9WgGUb3-JUw6EqafLx8tFVP6VKZTWbUOR-HOm__g4fNDt1bCsm_LgYf_k9H',
|
'app_key': 'PUVKp9WgGUb3-JUw6EqafLx8tFVP6VKZTWbUOR-HOm__g4fNDt1bCsm_LgYf_k9H',
|
||||||
'per_page': 1,
|
'per_page': 1,
|
||||||
'active': 'true',
|
'active': 'true',
|
||||||
'friendly_title': display_id,
|
'friendly_title': display_id,
|
||||||
})['response'][0]
|
})['response'][0]['_id']
|
||||||
|
return self.url_result(self._ZYPE_TEMPL % zype_id, 'Zype', zype_id)
|
||||||
zype_id = video['_id']
|
|
||||||
|
|
||||||
thumbnails = []
|
|
||||||
thumbnails_list = video.get('thumbnails')
|
|
||||||
if isinstance(thumbnails_list, list):
|
|
||||||
for thumbnail in thumbnails_list:
|
|
||||||
if not isinstance(thumbnail, dict):
|
|
||||||
continue
|
|
||||||
thumbnail_url = url_or_none(thumbnail.get('url'))
|
|
||||||
if not thumbnail_url:
|
|
||||||
continue
|
|
||||||
thumbnails.append({
|
|
||||||
'url': thumbnail_url,
|
|
||||||
'width': int_or_none(thumbnail.get('width')),
|
|
||||||
'height': int_or_none(thumbnail.get('height')),
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
'_type': 'url_transparent',
|
|
||||||
'url': update_url_query(
|
|
||||||
'https://player.zype.com/embed/%s.js' % zype_id,
|
|
||||||
{'api_key': 'X5XnahkjCwJrT_l5zUqypnaLEObotyvtUKJWWlONxDoHVjP8vqxlArLV8llxMbyt'}),
|
|
||||||
'ie_key': 'Zype',
|
|
||||||
'id': zype_id,
|
|
||||||
'display_id': display_id,
|
|
||||||
'title': video.get('title'),
|
|
||||||
'description': dict_get(video, ('description', 'ott_description', 'short_description')),
|
|
||||||
'duration': int_or_none(video.get('duration')),
|
|
||||||
'timestamp': unified_timestamp(video.get('published_at')),
|
|
||||||
'average_rating': float_or_none(video.get('rating')),
|
|
||||||
'view_count': int_or_none(video.get('request_count')),
|
|
||||||
'thumbnails': thumbnails,
|
|
||||||
}
|
|
||||||
|
@ -4,10 +4,20 @@ from __future__ import unicode_literals
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..compat import compat_HTTPError
|
||||||
|
from ..utils import (
|
||||||
|
dict_get,
|
||||||
|
ExtractorError,
|
||||||
|
int_or_none,
|
||||||
|
js_to_json,
|
||||||
|
parse_iso8601,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ZypeIE(InfoExtractor):
|
class ZypeIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://player\.zype\.com/embed/(?P<id>[\da-fA-F]+)\.js\?.*?api_key=[^&]+'
|
_ID_RE = r'[\da-fA-F]+'
|
||||||
|
_COMMON_RE = r'//player\.zype\.com/embed/%s\.(?:js|json|html)\?.*?(?:access_token|(?:ap[ip]|player)_key)='
|
||||||
|
_VALID_URL = r'https?:%s[^&]+' % (_COMMON_RE % ('(?P<id>%s)' % _ID_RE))
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'https://player.zype.com/embed/5b400b834b32992a310622b9.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ&autoplay=false&controls=true&da=false',
|
'url': 'https://player.zype.com/embed/5b400b834b32992a310622b9.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ&autoplay=false&controls=true&da=false',
|
||||||
'md5': 'eaee31d474c76a955bdaba02a505c595',
|
'md5': 'eaee31d474c76a955bdaba02a505c595',
|
||||||
@ -16,6 +26,9 @@ class ZypeIE(InfoExtractor):
|
|||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Smoky Barbecue Favorites',
|
'title': 'Smoky Barbecue Favorites',
|
||||||
'thumbnail': r're:^https?://.*\.jpe?g',
|
'thumbnail': r're:^https?://.*\.jpe?g',
|
||||||
|
'description': 'md5:5ff01e76316bd8d46508af26dc86023b',
|
||||||
|
'timestamp': 1504915200,
|
||||||
|
'upload_date': '20170909',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,34 +37,98 @@ class ZypeIE(InfoExtractor):
|
|||||||
return [
|
return [
|
||||||
mobj.group('url')
|
mobj.group('url')
|
||||||
for mobj in re.finditer(
|
for mobj in re.finditer(
|
||||||
r'<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//player\.zype\.com/embed/[\da-fA-F]+\.js\?.*?api_key=.+?)\1',
|
r'<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?%s.+?)\1' % (ZypeIE._COMMON_RE % ZypeIE._ID_RE),
|
||||||
webpage)]
|
webpage)]
|
||||||
|
|
||||||
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(url, video_id)
|
try:
|
||||||
|
response = self._download_json(re.sub(
|
||||||
|
r'\.(?:js|html)\?', '.json?', url), video_id)['response']
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, compat_HTTPError) and e.cause.code in (400, 401, 403):
|
||||||
|
raise ExtractorError(self._parse_json(
|
||||||
|
e.cause.read().decode(), video_id)['message'], expected=True)
|
||||||
|
raise
|
||||||
|
|
||||||
title = self._search_regex(
|
body = response['body']
|
||||||
r'video_title\s*[:=]\s*(["\'])(?P<value>(?:(?!\1).)+)\1', webpage,
|
video = response['video']
|
||||||
'title', group='value')
|
title = video['title']
|
||||||
|
|
||||||
m3u8_url = self._search_regex(
|
if isinstance(body, dict):
|
||||||
r'(["\'])(?P<url>(?:(?!\1).)+\.m3u8(?:(?!\1).)*)\1', webpage,
|
formats = []
|
||||||
'm3u8 url', group='url')
|
for output in body.get('outputs', []):
|
||||||
|
output_url = output.get('url')
|
||||||
formats = self._extract_m3u8_formats(
|
if not output_url:
|
||||||
m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
continue
|
||||||
m3u8_id='hls')
|
name = output.get('name')
|
||||||
|
if name == 'm3u8':
|
||||||
|
formats = self._extract_m3u8_formats(
|
||||||
|
output_url, video_id, 'mp4',
|
||||||
|
'm3u8_native', m3u8_id='hls', fatal=False)
|
||||||
|
else:
|
||||||
|
f = {
|
||||||
|
'format_id': name,
|
||||||
|
'tbr': int_or_none(output.get('bitrate')),
|
||||||
|
'url': output_url,
|
||||||
|
}
|
||||||
|
if name in ('m4a', 'mp3'):
|
||||||
|
f['vcodec'] = 'none'
|
||||||
|
else:
|
||||||
|
f.update({
|
||||||
|
'height': int_or_none(output.get('height')),
|
||||||
|
'width': int_or_none(output.get('width')),
|
||||||
|
})
|
||||||
|
formats.append(f)
|
||||||
|
text_tracks = body.get('subtitles') or []
|
||||||
|
else:
|
||||||
|
m3u8_url = self._search_regex(
|
||||||
|
r'(["\'])(?P<url>(?:(?!\1).)+\.m3u8(?:(?!\1).)*)\1',
|
||||||
|
body, 'm3u8 url', group='url')
|
||||||
|
formats = self._extract_m3u8_formats(
|
||||||
|
m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls')
|
||||||
|
text_tracks = self._search_regex(
|
||||||
|
r'textTracks\s*:\s*(\[[^]]+\])',
|
||||||
|
body, 'text tracks', default=None)
|
||||||
|
if text_tracks:
|
||||||
|
text_tracks = self._parse_json(
|
||||||
|
text_tracks, video_id, js_to_json, False)
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
thumbnail = self._search_regex(
|
subtitles = {}
|
||||||
r'poster\s*[:=]\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'thumbnail',
|
if text_tracks:
|
||||||
default=False, group='url')
|
for text_track in text_tracks:
|
||||||
|
tt_url = dict_get(text_track, ('file', 'src'))
|
||||||
|
if not tt_url:
|
||||||
|
continue
|
||||||
|
subtitles.setdefault(text_track.get('label') or 'English', []).append({
|
||||||
|
'url': tt_url,
|
||||||
|
})
|
||||||
|
|
||||||
|
thumbnails = []
|
||||||
|
for thumbnail in video.get('thumbnails', []):
|
||||||
|
thumbnail_url = thumbnail.get('url')
|
||||||
|
if not thumbnail_url:
|
||||||
|
continue
|
||||||
|
thumbnails.append({
|
||||||
|
'url': thumbnail_url,
|
||||||
|
'width': int_or_none(thumbnail.get('width')),
|
||||||
|
'height': int_or_none(thumbnail.get('height')),
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
'display_id': video.get('friendly_title'),
|
||||||
'title': title,
|
'title': title,
|
||||||
'thumbnail': thumbnail,
|
'thumbnails': thumbnails,
|
||||||
|
'description': dict_get(video, ('description', 'ott_description', 'short_description')),
|
||||||
|
'timestamp': parse_iso8601(video.get('published_at')),
|
||||||
|
'duration': int_or_none(video.get('duration')),
|
||||||
|
'view_count': int_or_none(video.get('request_count')),
|
||||||
|
'average_rating': int_or_none(video.get('rating')),
|
||||||
|
'season_number': int_or_none(video.get('season')),
|
||||||
|
'episode_number': int_or_none(video.get('episode')),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
|
'subtitles': subtitles,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user