mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-08-22 22:34:01 -07:00
Merge eb0d0d1eed
into 195f22f679
This commit is contained in:
commit
dbb6a89280
4 changed files with 291 additions and 295 deletions
|
@ -11,8 +11,12 @@ print('WARNING: Lazy loading extractors is an experimental feature that may not
|
||||||
sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
|
sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
|
||||||
|
|
||||||
lazy_extractors_filename = sys.argv[1]
|
lazy_extractors_filename = sys.argv[1]
|
||||||
if os.path.exists(lazy_extractors_filename):
|
# Py2: may be confused by left-over lazy_extractors.pyc
|
||||||
os.remove(lazy_extractors_filename)
|
for x in ('', 'c'):
|
||||||
|
try:
|
||||||
|
os.remove(lazy_extractors_filename + x)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
from youtube_dl.extractor import _ALL_CLASSES
|
from youtube_dl.extractor import _ALL_CLASSES
|
||||||
from youtube_dl.extractor.common import InfoExtractor, SearchInfoExtractor
|
from youtube_dl.extractor.common import InfoExtractor, SearchInfoExtractor
|
||||||
|
@ -21,7 +25,9 @@ with open('devscripts/lazy_load_template.py', 'rt') as f:
|
||||||
module_template = f.read()
|
module_template = f.read()
|
||||||
|
|
||||||
module_contents = [
|
module_contents = [
|
||||||
module_template + '\n' + getsource(InfoExtractor.suitable) + '\n',
|
module_template,
|
||||||
|
(lambda cls: ('_match_valid_url' in cls.__dict__) and getsource(cls._match_valid_url))(InfoExtractor),
|
||||||
|
getsource(InfoExtractor.suitable), '',
|
||||||
'class LazyLoadSearchExtractor(LazyLoadExtractor):\n pass\n']
|
'class LazyLoadSearchExtractor(LazyLoadExtractor):\n pass\n']
|
||||||
|
|
||||||
ie_template = '''
|
ie_template = '''
|
||||||
|
@ -94,7 +100,7 @@ for ie in ordered_cls:
|
||||||
module_contents.append(
|
module_contents.append(
|
||||||
'_ALL_CLASSES = [{0}]'.format(', '.join(names)))
|
'_ALL_CLASSES = [{0}]'.format(', '.join(names)))
|
||||||
|
|
||||||
module_src = '\n'.join(module_contents) + '\n'
|
module_src = '\n'.join(filter(lambda x: x is not None, module_contents)) + '\n'
|
||||||
|
|
||||||
with io.open(lazy_extractors_filename, 'wt', encoding='utf-8') as f:
|
with io.open(lazy_extractors_filename, 'wt', encoding='utf-8') as f:
|
||||||
f.write(module_src)
|
f.write(module_src)
|
||||||
|
|
|
@ -1,30 +1,21 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
import re
|
import re
|
||||||
from xml.sax.saxutils import escape
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_str,
|
compat_str,
|
||||||
compat_HTTPError,
|
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
get_element_by_class,
|
||||||
js_to_json,
|
js_to_json,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
try_get,
|
try_get,
|
||||||
xpath_text,
|
|
||||||
xpath_element,
|
|
||||||
xpath_with_ns,
|
|
||||||
find_xpath_attr,
|
|
||||||
orderedSet,
|
orderedSet,
|
||||||
parse_duration,
|
remove_end,
|
||||||
parse_iso8601,
|
|
||||||
parse_age_limit,
|
|
||||||
strip_or_none,
|
strip_or_none,
|
||||||
int_or_none,
|
unified_timestamp,
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,6 +50,7 @@ class CBCIE(InfoExtractor):
|
||||||
'uploader': 'CBCC-NEW',
|
'uploader': 'CBCC-NEW',
|
||||||
'timestamp': 1382717907,
|
'timestamp': 1382717907,
|
||||||
},
|
},
|
||||||
|
'skip': 'No longer available',
|
||||||
}, {
|
}, {
|
||||||
# with clipId, feed only available via tpfeed.cbc.ca
|
# with clipId, feed only available via tpfeed.cbc.ca
|
||||||
'url': 'http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live',
|
'url': 'http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live',
|
||||||
|
@ -100,12 +92,13 @@ class CBCIE(InfoExtractor):
|
||||||
}],
|
}],
|
||||||
'skip': 'Geo-restricted to Canada',
|
'skip': 'Geo-restricted to Canada',
|
||||||
}, {
|
}, {
|
||||||
# multiple CBC.APP.Caffeine.initInstance(...)
|
# multiple in React ld+json, formerly CBC.APP.Caffeine.initInstance(...)
|
||||||
'url': 'http://www.cbc.ca/news/canada/calgary/dog-indoor-exercise-winter-1.3928238',
|
'url': 'http://www.cbc.ca/news/canada/calgary/dog-indoor-exercise-winter-1.3928238',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'title': 'Keep Rover active during the deep freeze with doggie pushups and other fun indoor tasks',
|
'title': 'Keep Rover active during the deep freeze with doggie pushups and other fun indoor tasks',
|
||||||
'id': 'dog-indoor-exercise-winter-1.3928238',
|
'id': 'dog-indoor-exercise-winter-1.3928238',
|
||||||
'description': 'md5:c18552e41726ee95bd75210d1ca9194c',
|
'description': 'md5:c18552e41726ee95bd75210d1ca9194c',
|
||||||
|
'timestamp': 1484016300,
|
||||||
},
|
},
|
||||||
'playlist_mincount': 6,
|
'playlist_mincount': 6,
|
||||||
}]
|
}]
|
||||||
|
@ -130,12 +123,56 @@ class CBCIE(InfoExtractor):
|
||||||
clip_id)['entries'][0]['id'].split('/')[-1]
|
clip_id)['entries'][0]['id'].split('/')[-1]
|
||||||
return self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id)
|
return self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id)
|
||||||
|
|
||||||
|
def _extract_ld_json(self, ldjson, display_id):
|
||||||
|
"""Extract video playlist from JSON {plItem: itemVal, ..., video: [...], ...}"""
|
||||||
|
playlist_info = self._parse_json(ldjson, display_id, fatal=False)
|
||||||
|
videos = try_get(playlist_info, lambda x: x['video'], list)
|
||||||
|
if not videos:
|
||||||
|
return None
|
||||||
|
entries = []
|
||||||
|
for video in videos:
|
||||||
|
vtype = try_get(video, lambda x: x['@type'], compat_str)
|
||||||
|
if vtype != 'VideoObject':
|
||||||
|
continue
|
||||||
|
clip_id = video.get('identifier')
|
||||||
|
if clip_id is None:
|
||||||
|
continue
|
||||||
|
title = video.get('name')
|
||||||
|
entries.append({
|
||||||
|
'_type': 'url_transparent',
|
||||||
|
'url': 'cbcplayer:%s' % clip_id,
|
||||||
|
'title': title,
|
||||||
|
'description': video.get('description'),
|
||||||
|
'timestamp': unified_timestamp(video.get('dateModified')),
|
||||||
|
'thumbnail': video.get('thumbnailUrl')
|
||||||
|
})
|
||||||
|
result = self.playlist_result(
|
||||||
|
entries,
|
||||||
|
playlist_id=display_id,
|
||||||
|
playlist_title=playlist_info.get('name'),
|
||||||
|
playlist_description=playlist_info.get('description'))
|
||||||
|
result['timestamp'] = unified_timestamp(playlist_info.get('datePublished'))
|
||||||
|
result['release_timestamp'] = unified_timestamp(playlist_info.get('dateModified'))
|
||||||
|
result['thumbnail'] = playlist_info.get('thumbnailUrl')
|
||||||
|
return result
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, display_id)
|
webpage = self._download_webpage(url, display_id)
|
||||||
|
|
||||||
|
# 2021-09 React-based page with playlist in <script type="application/ld+json"> element
|
||||||
|
ldjson = self._search_regex(
|
||||||
|
r'(?s)<script\s[^>]*?\bdata-react-helmet\s*=[^>]+?\btype\s*=\s*(?P<q>"|\'|\b)application/ld\+json(?P=q)[^>]*>\s*(?P<json_ld>{.+?})\s*</script>',
|
||||||
|
webpage, 'ld+json', default=None, group='json_ld')
|
||||||
|
result = self._extract_ld_json(ldjson, display_id)
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
|
||||||
|
# Continue trying older schemes
|
||||||
title = self._og_search_title(webpage, default=None) or self._html_search_meta(
|
title = self._og_search_title(webpage, default=None) or self._html_search_meta(
|
||||||
'twitter:title', webpage, 'title', default=None) or self._html_search_regex(
|
'twitter:title', webpage, 'title', default=None) or self._html_search_regex(
|
||||||
r'<title>([^<]+)</title>', webpage, 'title', fatal=False)
|
r'<title>([^<]+)</title>', webpage, 'title')
|
||||||
|
title = strip_or_none(remove_end(title, '| CBC News')) or 'Untitled video %s' % display_id
|
||||||
entries = [
|
entries = [
|
||||||
self._extract_player_init(player_init, display_id)
|
self._extract_player_init(player_init, display_id)
|
||||||
for player_init in re.findall(r'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);', webpage)]
|
for player_init in re.findall(r'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);', webpage)]
|
||||||
|
@ -150,7 +187,8 @@ class CBCIE(InfoExtractor):
|
||||||
for media_id in orderedSet(media_ids)])
|
for media_id in orderedSet(media_ids)])
|
||||||
return self.playlist_result(
|
return self.playlist_result(
|
||||||
entries, display_id, strip_or_none(title),
|
entries, display_id, strip_or_none(title),
|
||||||
self._og_search_description(webpage))
|
self._og_search_description(webpage, default=None)
|
||||||
|
or get_element_by_class('item-content', webpage))
|
||||||
|
|
||||||
|
|
||||||
class CBCPlayerIE(InfoExtractor):
|
class CBCPlayerIE(InfoExtractor):
|
||||||
|
@ -209,289 +247,235 @@ class CBCPlayerIE(InfoExtractor):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CBCWatchBaseIE(InfoExtractor):
|
class CBCGemIE(InfoExtractor):
|
||||||
_device_id = None
|
IE_NAME = 'cbc.ca:gem:video'
|
||||||
_device_token = None
|
_VALID_URL = r'https?://gem\.cbc\.ca/media/(?P<id>[0-9a-z-]+/s\d+[a-z]\d+)'
|
||||||
_API_BASE_URL = 'https://api-cbc.cloud.clearleap.com/cloffice/client/'
|
|
||||||
_NS_MAP = {
|
|
||||||
'media': 'http://search.yahoo.com/mrss/',
|
|
||||||
'clearleap': 'http://www.clearleap.com/namespace/clearleap/1.0/',
|
|
||||||
}
|
|
||||||
_GEO_COUNTRIES = ['CA']
|
|
||||||
_LOGIN_URL = 'https://api.loginradius.com/identity/v2/auth/login'
|
|
||||||
_TOKEN_URL = 'https://cloud-api.loginradius.com/sso/jwt/api/token'
|
|
||||||
_API_KEY = '3f4beddd-2061-49b0-ae80-6f1f2ed65b37'
|
|
||||||
_NETRC_MACHINE = 'cbcwatch'
|
|
||||||
|
|
||||||
def _signature(self, email, password):
|
|
||||||
data = json.dumps({
|
|
||||||
'email': email,
|
|
||||||
'password': password,
|
|
||||||
}).encode()
|
|
||||||
headers = {'content-type': 'application/json'}
|
|
||||||
query = {'apikey': self._API_KEY}
|
|
||||||
resp = self._download_json(self._LOGIN_URL, None, data=data, headers=headers, query=query)
|
|
||||||
access_token = resp['access_token']
|
|
||||||
|
|
||||||
# token
|
|
||||||
query = {
|
|
||||||
'access_token': access_token,
|
|
||||||
'apikey': self._API_KEY,
|
|
||||||
'jwtapp': 'jwt',
|
|
||||||
}
|
|
||||||
resp = self._download_json(self._TOKEN_URL, None, headers=headers, query=query)
|
|
||||||
return resp['signature']
|
|
||||||
|
|
||||||
def _call_api(self, path, video_id):
|
|
||||||
url = path if path.startswith('http') else self._API_BASE_URL + path
|
|
||||||
for _ in range(2):
|
|
||||||
try:
|
|
||||||
result = self._download_xml(url, video_id, headers={
|
|
||||||
'X-Clearleap-DeviceId': self._device_id,
|
|
||||||
'X-Clearleap-DeviceToken': self._device_token,
|
|
||||||
})
|
|
||||||
except ExtractorError as e:
|
|
||||||
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
|
|
||||||
# Device token has expired, re-acquiring device token
|
|
||||||
self._register_device()
|
|
||||||
continue
|
|
||||||
raise
|
|
||||||
error_message = xpath_text(result, 'userMessage') or xpath_text(result, 'systemMessage')
|
|
||||||
if error_message:
|
|
||||||
raise ExtractorError('%s said: %s' % (self.IE_NAME, error_message))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _real_initialize(self):
|
|
||||||
if self._valid_device_token():
|
|
||||||
return
|
|
||||||
device = self._downloader.cache.load(
|
|
||||||
'cbcwatch', self._cache_device_key()) or {}
|
|
||||||
self._device_id, self._device_token = device.get('id'), device.get('token')
|
|
||||||
if self._valid_device_token():
|
|
||||||
return
|
|
||||||
self._register_device()
|
|
||||||
|
|
||||||
def _valid_device_token(self):
|
|
||||||
return self._device_id and self._device_token
|
|
||||||
|
|
||||||
def _cache_device_key(self):
|
|
||||||
email, _ = self._get_login_info()
|
|
||||||
return '%s_device' % hashlib.sha256(email.encode()).hexdigest() if email else 'device'
|
|
||||||
|
|
||||||
def _register_device(self):
|
|
||||||
result = self._download_xml(
|
|
||||||
self._API_BASE_URL + 'device/register',
|
|
||||||
None, 'Acquiring device token',
|
|
||||||
data=b'<device><type>web</type></device>')
|
|
||||||
self._device_id = xpath_text(result, 'deviceId', fatal=True)
|
|
||||||
email, password = self._get_login_info()
|
|
||||||
if email and password:
|
|
||||||
signature = self._signature(email, password)
|
|
||||||
data = '<login><token>{0}</token><device><deviceId>{1}</deviceId><type>web</type></device></login>'.format(
|
|
||||||
escape(signature), escape(self._device_id)).encode()
|
|
||||||
url = self._API_BASE_URL + 'device/login'
|
|
||||||
result = self._download_xml(
|
|
||||||
url, None, data=data,
|
|
||||||
headers={'content-type': 'application/xml'})
|
|
||||||
self._device_token = xpath_text(result, 'token', fatal=True)
|
|
||||||
else:
|
|
||||||
self._device_token = xpath_text(result, 'deviceToken', fatal=True)
|
|
||||||
self._downloader.cache.store(
|
|
||||||
'cbcwatch', self._cache_device_key(), {
|
|
||||||
'id': self._device_id,
|
|
||||||
'token': self._device_token,
|
|
||||||
})
|
|
||||||
|
|
||||||
def _parse_rss_feed(self, rss):
|
|
||||||
channel = xpath_element(rss, 'channel', fatal=True)
|
|
||||||
|
|
||||||
def _add_ns(path):
|
|
||||||
return xpath_with_ns(path, self._NS_MAP)
|
|
||||||
|
|
||||||
entries = []
|
|
||||||
for item in channel.findall('item'):
|
|
||||||
guid = xpath_text(item, 'guid', fatal=True)
|
|
||||||
title = xpath_text(item, 'title', fatal=True)
|
|
||||||
|
|
||||||
media_group = xpath_element(item, _add_ns('media:group'), fatal=True)
|
|
||||||
content = xpath_element(media_group, _add_ns('media:content'), fatal=True)
|
|
||||||
content_url = content.attrib['url']
|
|
||||||
|
|
||||||
thumbnails = []
|
|
||||||
for thumbnail in media_group.findall(_add_ns('media:thumbnail')):
|
|
||||||
thumbnail_url = thumbnail.get('url')
|
|
||||||
if not thumbnail_url:
|
|
||||||
continue
|
|
||||||
thumbnails.append({
|
|
||||||
'id': thumbnail.get('profile'),
|
|
||||||
'url': thumbnail_url,
|
|
||||||
'width': int_or_none(thumbnail.get('width')),
|
|
||||||
'height': int_or_none(thumbnail.get('height')),
|
|
||||||
})
|
|
||||||
|
|
||||||
timestamp = None
|
|
||||||
release_date = find_xpath_attr(
|
|
||||||
item, _add_ns('media:credit'), 'role', 'releaseDate')
|
|
||||||
if release_date is not None:
|
|
||||||
timestamp = parse_iso8601(release_date.text)
|
|
||||||
|
|
||||||
entries.append({
|
|
||||||
'_type': 'url_transparent',
|
|
||||||
'url': content_url,
|
|
||||||
'id': guid,
|
|
||||||
'title': title,
|
|
||||||
'description': xpath_text(item, 'description'),
|
|
||||||
'timestamp': timestamp,
|
|
||||||
'duration': int_or_none(content.get('duration')),
|
|
||||||
'age_limit': parse_age_limit(xpath_text(item, _add_ns('media:rating'))),
|
|
||||||
'episode': xpath_text(item, _add_ns('clearleap:episode')),
|
|
||||||
'episode_number': int_or_none(xpath_text(item, _add_ns('clearleap:episodeInSeason'))),
|
|
||||||
'series': xpath_text(item, _add_ns('clearleap:series')),
|
|
||||||
'season_number': int_or_none(xpath_text(item, _add_ns('clearleap:season'))),
|
|
||||||
'thumbnails': thumbnails,
|
|
||||||
'ie_key': 'CBCWatchVideo',
|
|
||||||
})
|
|
||||||
|
|
||||||
return self.playlist_result(
|
|
||||||
entries, xpath_text(channel, 'guid'),
|
|
||||||
xpath_text(channel, 'title'),
|
|
||||||
xpath_text(channel, 'description'))
|
|
||||||
|
|
||||||
|
|
||||||
class CBCWatchVideoIE(CBCWatchBaseIE):
|
|
||||||
IE_NAME = 'cbc.ca:watch:video'
|
|
||||||
_VALID_URL = r'https?://api-cbc\.cloud\.clearleap\.com/cloffice/client/web/play/?\?.*?\bcontentId=(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
|
|
||||||
_TEST = {
|
|
||||||
# geo-restricted to Canada, bypassable
|
|
||||||
'url': 'https://api-cbc.cloud.clearleap.com/cloffice/client/web/play/?contentId=3c84472a-1eea-4dee-9267-2655d5055dcf&categoryId=ebc258f5-ee40-4cca-b66b-ba6bd55b7235',
|
|
||||||
'only_matching': True,
|
|
||||||
}
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
|
||||||
video_id = self._match_id(url)
|
|
||||||
result = self._call_api(url, video_id)
|
|
||||||
|
|
||||||
m3u8_url = xpath_text(result, 'url', fatal=True)
|
|
||||||
formats = self._extract_m3u8_formats(re.sub(r'/([^/]+)/[^/?]+\.m3u8', r'/\1/\1.m3u8', m3u8_url), video_id, 'mp4', fatal=False)
|
|
||||||
if len(formats) < 2:
|
|
||||||
formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
|
|
||||||
for f in formats:
|
|
||||||
format_id = f.get('format_id')
|
|
||||||
if format_id.startswith('AAC'):
|
|
||||||
f['acodec'] = 'aac'
|
|
||||||
elif format_id.startswith('AC3'):
|
|
||||||
f['acodec'] = 'ac-3'
|
|
||||||
self._sort_formats(formats)
|
|
||||||
|
|
||||||
info = {
|
|
||||||
'id': video_id,
|
|
||||||
'title': video_id,
|
|
||||||
'formats': formats,
|
|
||||||
}
|
|
||||||
|
|
||||||
rss = xpath_element(result, 'rss')
|
|
||||||
if rss:
|
|
||||||
info.update(self._parse_rss_feed(rss)['entries'][0])
|
|
||||||
del info['url']
|
|
||||||
del info['_type']
|
|
||||||
del info['ie_key']
|
|
||||||
return info
|
|
||||||
|
|
||||||
|
|
||||||
class CBCWatchIE(CBCWatchBaseIE):
|
|
||||||
IE_NAME = 'cbc.ca:watch'
|
|
||||||
_VALID_URL = r'https?://(?:gem|watch)\.cbc\.ca/(?:[^/]+/)+(?P<id>[0-9a-f-]+)'
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
# geo-restricted to Canada, bypassable
|
# This is a normal, public, TV show video
|
||||||
'url': 'http://watch.cbc.ca/doc-zone/season-6/customer-disservice/38e815a-009e3ab12e4',
|
'url': 'https://gem.cbc.ca/media/schitts-creek/s06e01',
|
||||||
|
'md5': '93dbb31c74a8e45b378cf13bd3f6f11e',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '9673749a-5e77-484c-8b62-a1092a6b5168',
|
'id': 'schitts-creek/s06e01',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Customer (Dis)Service',
|
'title': 'Smoke Signals',
|
||||||
'description': 'md5:8bdd6913a0fe03d4b2a17ebe169c7c87',
|
'description': 'md5:929868d20021c924020641769eb3e7f1',
|
||||||
'upload_date': '20160219',
|
'thumbnail': 'https://images.radio-canada.ca/v1/synps-cbc/episode/perso/cbc_schitts_creek_season_06e01_thumbnail_v01.jpg?im=Resize=(Size)',
|
||||||
'timestamp': 1455840000,
|
'duration': 1314,
|
||||||
},
|
'categories': ['comedy'],
|
||||||
'params': {
|
'series': 'Schitt\'s Creek',
|
||||||
# m3u8 download
|
'season': 'Season 6',
|
||||||
'skip_download': True,
|
'season_number': 6,
|
||||||
'format': 'bestvideo',
|
'episode': 'Smoke Signals',
|
||||||
|
'episode_number': 1,
|
||||||
|
'episode_id': 'schitts-creek/s06e01',
|
||||||
},
|
},
|
||||||
|
'params': {'format': 'bv'},
|
||||||
|
# no longer amenable to geo-bypass
|
||||||
|
'skip': 'Geo-restricted to Canada',
|
||||||
}, {
|
}, {
|
||||||
# geo-restricted to Canada, bypassable
|
# This video requires an account in the browser, but works fine in yt-dlp
|
||||||
'url': 'http://watch.cbc.ca/arthur/all/1ed4b385-cd84-49cf-95f0-80f004680057',
|
'url': 'https://gem.cbc.ca/media/schitts-creek/s01e01',
|
||||||
|
'md5': '297a9600f554f2258aed01514226a697',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '1ed4b385-cd84-49cf-95f0-80f004680057',
|
'id': 'schitts-creek/s01e01',
|
||||||
'title': 'Arthur',
|
'ext': 'mp4',
|
||||||
'description': 'Arthur, the sweetest 8-year-old aardvark, and his pals solve all kinds of problems with humour, kindness and teamwork.',
|
'title': 'The Cup Runneth Over',
|
||||||
|
'description': 'md5:9bca14ea49ab808097530eb05a29e797',
|
||||||
|
'thumbnail': 'https://images.radio-canada.ca/v1/synps-cbc/episode/perso/cbc_schitts_creek_season_01e01_thumbnail_v01.jpg?im=Resize=(Size)',
|
||||||
|
'series': 'Schitt\'s Creek',
|
||||||
|
'season_number': 1,
|
||||||
|
'season': 'Season 1',
|
||||||
|
'episode_number': 1,
|
||||||
|
'episode': 'The Cup Runneth Over',
|
||||||
|
'episode_id': 'schitts-creek/s01e01',
|
||||||
|
'duration': 1309,
|
||||||
|
'categories': ['comedy'],
|
||||||
},
|
},
|
||||||
'playlist_mincount': 30,
|
'params': {'format': 'bv'},
|
||||||
}, {
|
# no longer amenable to geo-bypass
|
||||||
'url': 'https://gem.cbc.ca/media/this-hour-has-22-minutes/season-26/episode-20/38e815a-0108c6c6a42',
|
'skip': 'Geo-restricted to Canada',
|
||||||
'only_matching': True,
|
|
||||||
}]
|
}]
|
||||||
|
_API_BASE = 'https://services.radio-canada.ca/ott/cbc-api/v2/assets/'
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
rss = self._call_api('web/browse/' + video_id, video_id)
|
video_info = self._download_json(self._API_BASE + video_id, video_id)
|
||||||
return self._parse_rss_feed(rss)
|
|
||||||
|
|
||||||
|
last_error = None
|
||||||
class CBCOlympicsIE(InfoExtractor):
|
attempt = -1
|
||||||
IE_NAME = 'cbc.ca:olympics'
|
retries = self._downloader.params.get('extractor_retries', 15)
|
||||||
_VALID_URL = r'https?://olympics\.cbc\.ca/video/[^/]+/(?P<id>[^/?#]+)'
|
while attempt < retries:
|
||||||
_TESTS = [{
|
attempt += 1
|
||||||
'url': 'https://olympics.cbc.ca/video/whats-on-tv/olympic-morning-featuring-the-opening-ceremony/',
|
if last_error:
|
||||||
'only_matching': True,
|
self.report_warning('%s. Retrying ...' % last_error)
|
||||||
}]
|
m3u8_info = self._download_json(
|
||||||
|
video_info['playSession']['url'], video_id,
|
||||||
def _real_extract(self, url):
|
note='Downloading JSON metadata (attempt %d)' % attempt)
|
||||||
display_id = self._match_id(url)
|
m3u8_url = m3u8_info.get('url')
|
||||||
webpage = self._download_webpage(url, display_id)
|
if m3u8_url:
|
||||||
video_id = self._hidden_inputs(webpage)['videoId']
|
break
|
||||||
video_doc = self._download_xml(
|
elif m3u8_info.get('errorCode') == 1:
|
||||||
'https://olympics.cbc.ca/videodata/%s.xml' % video_id, video_id)
|
self.raise_geo_restricted(countries=['CA'])
|
||||||
title = xpath_text(video_doc, 'title', fatal=True)
|
|
||||||
is_live = xpath_text(video_doc, 'kind') == 'Live'
|
|
||||||
if is_live:
|
|
||||||
title = self._live_title(title)
|
|
||||||
|
|
||||||
formats = []
|
|
||||||
for video_source in video_doc.findall('videoSources/videoSource'):
|
|
||||||
uri = xpath_text(video_source, 'uri')
|
|
||||||
if not uri:
|
|
||||||
continue
|
|
||||||
tokenize = self._download_json(
|
|
||||||
'https://olympics.cbc.ca/api/api-akamai/tokenize',
|
|
||||||
video_id, data=json.dumps({
|
|
||||||
'VideoSource': uri,
|
|
||||||
}).encode(), headers={
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Referer': url,
|
|
||||||
# d3.VideoPlayer._init in https://olympics.cbc.ca/components/script/base.js
|
|
||||||
'Cookie': '_dvp=TK:C0ObxjerU', # AKAMAI CDN cookie
|
|
||||||
}, fatal=False)
|
|
||||||
if not tokenize:
|
|
||||||
continue
|
|
||||||
content_url = tokenize['ContentUrl']
|
|
||||||
video_source_format = video_source.get('format')
|
|
||||||
if video_source_format == 'IIS':
|
|
||||||
formats.extend(self._extract_ism_formats(
|
|
||||||
content_url, video_id, ism_id=video_source_format, fatal=False))
|
|
||||||
else:
|
else:
|
||||||
formats.extend(self._extract_m3u8_formats(
|
last_error = (
|
||||||
content_url, video_id, 'mp4',
|
'%s said: %s - %s' %
|
||||||
'm3u8' if is_live else 'm3u8_native',
|
(self.IE_NAME, m3u8_info.get("errorCode"), m3u8_info.get("message")))
|
||||||
m3u8_id=video_source_format, fatal=False))
|
# 35 means media unavailable, but retries work
|
||||||
|
if m3u8_info.get('errorCode') != 35 or attempt >= retries:
|
||||||
|
raise ExtractorError(last_error)
|
||||||
|
|
||||||
|
formats = self._extract_m3u8_formats(m3u8_url, video_id, m3u8_id='hls')
|
||||||
|
self._remove_duplicate_formats(formats)
|
||||||
|
|
||||||
|
for i, format in enumerate(formats):
|
||||||
|
if format.get('vcodec') == 'none':
|
||||||
|
if format.get('ext') is None:
|
||||||
|
format['ext'] = 'm4a'
|
||||||
|
if format.get('acodec') is None:
|
||||||
|
format['acodec'] = 'mp4a.40.2'
|
||||||
|
|
||||||
|
# Put described audio at the beginning of the list, so that it
|
||||||
|
# isn't chosen by default, as most people won't want it.
|
||||||
|
if 'descriptive' in format['format_id'].lower():
|
||||||
|
format['preference'] = -2
|
||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
season_number = video_info.get('season')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'display_id': display_id,
|
'title': video_info['title'],
|
||||||
'title': title,
|
'description': video_info.get('description'),
|
||||||
'description': xpath_text(video_doc, 'description'),
|
'thumbnail': video_info.get('image'),
|
||||||
'thumbnail': xpath_text(video_doc, 'thumbnailUrl'),
|
'series': video_info.get('series'),
|
||||||
'duration': parse_duration(xpath_text(video_doc, 'duration')),
|
'season_number': season_number,
|
||||||
|
'season': 'Season %s' % season_number if season_number else None,
|
||||||
|
'episode_number': video_info.get('episode'),
|
||||||
|
'episode': video_info.get('title'),
|
||||||
|
'episode_id': video_id,
|
||||||
|
'duration': video_info.get('duration'),
|
||||||
|
'categories': [video_info.get('category')],
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'is_live': is_live,
|
'release_timestamp': video_info.get('airDate'),
|
||||||
|
'timestamp': video_info.get('availableDate'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CBCGemPlaylistIE(InfoExtractor):
|
||||||
|
IE_NAME = 'cbc.ca:gem:playlist'
|
||||||
|
_VALID_URL = r'https?://gem\.cbc\.ca/media/(?P<id>(?P<show>[0-9a-z-]+)/s(?P<season>\d+))/?(?:[?#]|$)'
|
||||||
|
_TESTS = [{
|
||||||
|
# playlist not geo-restricted to Canada, even if shows are
|
||||||
|
# TV show playlist, all public videos
|
||||||
|
'url': 'https://gem.cbc.ca/media/schitts-creek/s06',
|
||||||
|
'playlist_count': 16,
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'schitts-creek/s06',
|
||||||
|
'title': 'Season 6',
|
||||||
|
'description': 'md5:6a92104a56cbeb5818cc47884d4326a2',
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
_API_BASE = 'https://services.radio-canada.ca/ott/cbc-api/v2/shows/'
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
match = self._match_valid_url(url)
|
||||||
|
season_id = match.group('id')
|
||||||
|
show = match.group('show')
|
||||||
|
show_info = self._download_json(self._API_BASE + show, season_id, fatal=False)
|
||||||
|
season = match.group('season')
|
||||||
|
season_info = try_get(show_info, lambda x: x['seasons'][int(season) - 1])
|
||||||
|
|
||||||
|
if season_info is None:
|
||||||
|
raise ExtractorError('Couldn\'t find season %s of %s' % (season, show))
|
||||||
|
|
||||||
|
episodes = []
|
||||||
|
for episode in season_info['assets']:
|
||||||
|
episodes.append({
|
||||||
|
'_type': 'url_transparent',
|
||||||
|
'ie_key': 'CBCGem',
|
||||||
|
'url': 'https://gem.cbc.ca/media/' + episode['id'],
|
||||||
|
'id': episode['id'],
|
||||||
|
'title': episode.get('title'),
|
||||||
|
'description': episode.get('description'),
|
||||||
|
'thumbnail': episode.get('image'),
|
||||||
|
'series': episode.get('series'),
|
||||||
|
'season_number': episode.get('season'),
|
||||||
|
'season': season_info['title'],
|
||||||
|
'season_id': season_info.get('id'),
|
||||||
|
'episode_number': episode.get('episode'),
|
||||||
|
'episode': episode.get('title'),
|
||||||
|
'episode_id': episode['id'],
|
||||||
|
'duration': episode.get('duration'),
|
||||||
|
'categories': [episode.get('category')],
|
||||||
|
})
|
||||||
|
|
||||||
|
thumbnail = None
|
||||||
|
tn_uri = season_info.get('image')
|
||||||
|
# the-national was observed to use a "data:image/png;base64"
|
||||||
|
# URI for their 'image' value. The image was 1x1, and is
|
||||||
|
# probably just a placeholder, so it is ignored.
|
||||||
|
if tn_uri is not None and not tn_uri.startswith('data:'):
|
||||||
|
thumbnail = tn_uri
|
||||||
|
|
||||||
|
return {
|
||||||
|
'_type': 'playlist',
|
||||||
|
'entries': episodes,
|
||||||
|
'id': season_id,
|
||||||
|
'title': season_info['title'],
|
||||||
|
'description': season_info.get('description'),
|
||||||
|
'thumbnail': thumbnail,
|
||||||
|
'series': show_info.get('title'),
|
||||||
|
'season_number': season_info.get('season'),
|
||||||
|
'season': season_info['title'],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CBCGemLiveIE(InfoExtractor):
|
||||||
|
IE_NAME = 'cbc.ca:gem:live'
|
||||||
|
_VALID_URL = r'https?://gem\.cbc\.ca/live/(?P<id>[0-9]{12})'
|
||||||
|
_TEST = {
|
||||||
|
'url': 'https://gem.cbc.ca/live/920604739687',
|
||||||
|
'info_dict': {
|
||||||
|
'title': 'Ottawa',
|
||||||
|
'description': 'The live TV channel and local programming from Ottawa',
|
||||||
|
'thumbnail': 'https://thumbnails.cbc.ca/maven_legacy/thumbnails/CBC_OTT_VMS/Live_Channel_Static_Images/Ottawa_2880x1620.jpg',
|
||||||
|
'is_live': True,
|
||||||
|
'id': 'AyqZwxRqh8EH',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'timestamp': 1492106160,
|
||||||
|
'upload_date': '20170413',
|
||||||
|
'uploader': 'CBCC-NEW',
|
||||||
|
},
|
||||||
|
'skip': 'Live might have ended',
|
||||||
|
}
|
||||||
|
|
||||||
|
# It's unclear where the chars at the end come from, but they appear to be
|
||||||
|
# constant. Might need updating in the future.
|
||||||
|
_API = 'https://tpfeed.cbc.ca/f/ExhSPC/t_t3UKJR6MAT'
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
video_id = self._match_id(url)
|
||||||
|
live_info = self._download_json(self._API, video_id)['entries']
|
||||||
|
|
||||||
|
video_info = None
|
||||||
|
for stream in live_info:
|
||||||
|
if stream.get('guid') == video_id:
|
||||||
|
video_info = stream
|
||||||
|
|
||||||
|
if video_info is None:
|
||||||
|
raise ExtractorError(
|
||||||
|
'Couldn\'t find video metadata, maybe this livestream is now offline',
|
||||||
|
expected=True)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'_type': 'url_transparent',
|
||||||
|
'ie_key': 'ThePlatform',
|
||||||
|
'url': video_info['content'][0]['url'],
|
||||||
|
'id': video_id,
|
||||||
|
'title': video_info.get('title'),
|
||||||
|
'description': video_info.get('description'),
|
||||||
|
'tags': try_get(video_info, lambda x: x['keywords'].split(', ')),
|
||||||
|
'thumbnail': video_info.get('cbc$staticImage'),
|
||||||
|
'is_live': True,
|
||||||
}
|
}
|
||||||
|
|
|
@ -405,21 +405,27 @@ class InfoExtractor(object):
|
||||||
self.set_downloader(downloader)
|
self.set_downloader(downloader)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def suitable(cls, url):
|
def _match_valid_url(cls, url):
|
||||||
"""Receives a URL and returns True if suitable for this IE."""
|
"""Receives a URL and returns match against the IE's _VALID_URL."""
|
||||||
|
|
||||||
# This does not use has/getattr intentionally - we want to know whether
|
# This does not use has/getattr intentionally - we want to know whether
|
||||||
# we have cached the regexp for *this* class, whereas getattr would also
|
# we have cached the regexp for *this* class, whereas getattr would also
|
||||||
# match the superclass
|
# match the superclass
|
||||||
if '_VALID_URL_RE' not in cls.__dict__:
|
if '_VALID_URL_RE' not in cls.__dict__:
|
||||||
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
|
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
|
||||||
return cls._VALID_URL_RE.match(url) is not None
|
return cls._VALID_URL_RE.match(url)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def suitable(cls, url):
|
||||||
|
"""Receives a URL and returns True if suitable for this IE."""
|
||||||
|
|
||||||
|
return cls._match_valid_url(url) is not None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _match_id(cls, url):
|
def _match_id(cls, url):
|
||||||
if '_VALID_URL_RE' not in cls.__dict__:
|
"""Extracts the ID from the URL"""
|
||||||
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
|
m = cls._match_valid_url(url)
|
||||||
m = cls._VALID_URL_RE.match(url)
|
# Must have matched in suitable()
|
||||||
assert m
|
assert m
|
||||||
return compat_str(m.group('id'))
|
return compat_str(m.group('id'))
|
||||||
|
|
||||||
|
|
|
@ -181,9 +181,9 @@ from .cartoonnetwork import CartoonNetworkIE
|
||||||
from .cbc import (
|
from .cbc import (
|
||||||
CBCIE,
|
CBCIE,
|
||||||
CBCPlayerIE,
|
CBCPlayerIE,
|
||||||
CBCWatchVideoIE,
|
CBCGemIE,
|
||||||
CBCWatchIE,
|
CBCGemPlaylistIE,
|
||||||
CBCOlympicsIE,
|
CBCGemLiveIE,
|
||||||
)
|
)
|
||||||
from .cbs import CBSIE
|
from .cbs import CBSIE
|
||||||
from .cbslocal import (
|
from .cbslocal import (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue