mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-01-09 21:10:10 +09:00
Compare commits
5 Commits
12186cc767
...
f675f0943e
Author | SHA1 | Date | |
---|---|---|---|
|
f675f0943e | ||
|
c5098961b0 | ||
|
dbc08fba83 | ||
|
71223bff39 | ||
|
a94b69e4d3 |
@ -425,6 +425,34 @@ class TestJSInterpreter(unittest.TestCase):
|
||||
self._test(jsi, [''], args=['', '-'])
|
||||
self._test(jsi, [], args=['', ''])
|
||||
|
||||
def test_slice(self):
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice()}', [0, 1, 2, 3, 4, 5, 6, 7, 8])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(0)}', [0, 1, 2, 3, 4, 5, 6, 7, 8])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(5)}', [5, 6, 7, 8])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(99)}', [])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-2)}', [7, 8])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-99)}', [0, 1, 2, 3, 4, 5, 6, 7, 8])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(0, 0)}', [])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(1, 0)}', [])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(0, 1)}', [0])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(3, 6)}', [3, 4, 5])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(1, -1)}', [1, 2, 3, 4, 5, 6, 7])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-1, 1)}', [])
|
||||
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-3, -1)}', [6, 7])
|
||||
self._test('function f(){return "012345678".slice()}', '012345678')
|
||||
self._test('function f(){return "012345678".slice(0)}', '012345678')
|
||||
self._test('function f(){return "012345678".slice(5)}', '5678')
|
||||
self._test('function f(){return "012345678".slice(99)}', '')
|
||||
self._test('function f(){return "012345678".slice(-2)}', '78')
|
||||
self._test('function f(){return "012345678".slice(-99)}', '012345678')
|
||||
self._test('function f(){return "012345678".slice(0, 0)}', '')
|
||||
self._test('function f(){return "012345678".slice(1, 0)}', '')
|
||||
self._test('function f(){return "012345678".slice(0, 1)}', '0')
|
||||
self._test('function f(){return "012345678".slice(3, 6)}', '345')
|
||||
self._test('function f(){return "012345678".slice(1, -1)}', '1234567')
|
||||
self._test('function f(){return "012345678".slice(-1, 1)}', '')
|
||||
self._test('function f(){return "012345678".slice(-3, -1)}', '67')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -174,6 +174,14 @@ _NSIG_TESTS = [
|
||||
'https://www.youtube.com/s/player/5604538d/player_ias.vflset/en_US/base.js',
|
||||
'7X-he4jjvMx7BCX', 'sViSydX8IHtdWA',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/20dfca59/player_ias.vflset/en_US/base.js',
|
||||
'-fLCxedkAk4LUTK2', 'O8kfRq1y1eyHGw',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/b12cc44b/player_ias.vflset/en_US/base.js',
|
||||
'keLa5R2U00sR9SQK', 'N1OGyujjEwMnLw',
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
@ -506,6 +506,7 @@ from .hungama import (
|
||||
HungamaSongIE,
|
||||
)
|
||||
from .hypem import HypemIE
|
||||
from .icareus import IcareusIE
|
||||
from .ign import (
|
||||
IGNIE,
|
||||
IGNVideoIE,
|
||||
|
230
youtube_dl/extractor/icareus.py
Normal file
230
youtube_dl/extractor/icareus.py
Normal file
@ -0,0 +1,230 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
clean_html,
|
||||
determine_ext,
|
||||
get_element_by_attribute,
|
||||
get_element_by_class,
|
||||
int_or_none,
|
||||
parse_bitrate,
|
||||
parse_resolution,
|
||||
unified_timestamp,
|
||||
urlencode_postdata,
|
||||
url_or_none,
|
||||
)
|
||||
|
||||
|
||||
class IcareusIE(InfoExtractor):
|
||||
_VALID_URL = r'''(?x)
|
||||
https?://(?:www\.)?
|
||||
(?:
|
||||
asahitv\.fi|
|
||||
helsinkikanava\.fi|
|
||||
hyvinvointitv\.fi|
|
||||
inez\.fi|
|
||||
midastv\.ke|
|
||||
permanto\.fi|
|
||||
suite.icareus.com|
|
||||
videos\.minifiddlers\.org
|
||||
)
|
||||
/.+/player/.*(?:assetId|eventId)=(?P<id>\d+).*'''
|
||||
_TESTS = [{
|
||||
'url': 'https://www.helsinkikanava.fi/fi_FI/web/helsinkikanava/player/vod?assetId=68021894',
|
||||
'md5': 'ca0b62ffc814a5411dfa6349cf5adb8a',
|
||||
'info_dict': {
|
||||
'id': '68021894',
|
||||
'ext': 'mp4',
|
||||
'title': 'Perheiden parhaaksi',
|
||||
'description': 'md5:fe4e4ec742a34f53022f3a0409b0f6e7',
|
||||
'thumbnail': 'https://www.helsinkikanava.fi/image/image_gallery?img_id=68022501',
|
||||
'upload_date': '20200924',
|
||||
'timestamp': 1600938300,
|
||||
},
|
||||
}, { # Recorded livestream
|
||||
'url': 'https://www.helsinkikanava.fi/fi/web/helsinkikanava/player/event/view?eventId=76241489',
|
||||
'md5': '014327e69dfa7b949fcc861f6d162d6d',
|
||||
'info_dict': {
|
||||
'id': '76258304',
|
||||
'ext': 'mp4',
|
||||
'title': 'Helsingin kaupungin ja HUSin tiedotustilaisuus koronaepidemiatilanteesta 24.11.2020',
|
||||
'description': 'md5:3129d041c6fbbcdc7fe68d9a938fef1c',
|
||||
'thumbnail': 'https://icareus-suite.secure2.footprint.net/image/image_gallery?img_id=76288630',
|
||||
'upload_date': '20201124',
|
||||
'timestamp': 1606206600,
|
||||
},
|
||||
}, {
|
||||
'url': 'https://asahitv.fi/fi/web/asahi/player/vod?assetId=89415818',
|
||||
'only_matching': True
|
||||
}, {
|
||||
'url': 'https://hyvinvointitv.fi/fi/web/hyvinvointitv/player/vod?assetId=89149730',
|
||||
'only_matching': True
|
||||
}, {
|
||||
'url': 'https://inez.fi/fi/web/inez-media/player/vod?assetId=71328822',
|
||||
'only_matching': True
|
||||
}, {
|
||||
'url': 'https://www.midastv.ke/en/web/midas-tv/player/embed/vod?assetId=65714535',
|
||||
'only_matching': True
|
||||
}, {
|
||||
'url': 'https://www.permanto.fi/fi/web/alfatv/player/vod?assetId=95010095',
|
||||
'only_matching': True
|
||||
}, {
|
||||
'url': 'https://suite.icareus.com/fi/web/westend-indians/player/vod?assetId=47567389',
|
||||
'only_matching': True
|
||||
}, {
|
||||
'url': 'https://videos.minifiddlers.org/web/international-minifiddlers/player/vod?assetId=1982759',
|
||||
'only_matching': True
|
||||
}]
|
||||
_API2_PATH = '/icareus-suite-api-portlet/publishing'
|
||||
|
||||
def _real_extract(self, url):
|
||||
maybe_id = self._match_id(url)
|
||||
page = self._download_webpage(url, maybe_id)
|
||||
video_id = self._search_regex(
|
||||
r"_icareus\['itemId'\]='(\d+)'", page, "video_id")
|
||||
api_base = self._search_regex(
|
||||
r'var publishingServiceURL = "(http.*?)";', page, "api_base")
|
||||
organization_id = self._search_regex(
|
||||
r"_icareus\['organizationId'\]='(\d+)'", page, "organization_id")
|
||||
token = self._search_regex(
|
||||
r"_icareus\['token'\]='([a-f0-9]+)'", page, "token")
|
||||
|
||||
token2 = self._search_regex(
|
||||
r'''data\s*:\s*{action:"getAsset".*?token:'([a-f0-9]+)'}''', page,
|
||||
"token2", default=None, fatal=False)
|
||||
metajson = get_element_by_attribute('type', 'application/ld+json', page)
|
||||
|
||||
metad = None
|
||||
if metajson:
|
||||
# The description can contain newlines, HTML tags, quote chars etc.
|
||||
# so we'll extract it manually
|
||||
mo = re.match(
|
||||
r'(.*",)\s*"description": "(.*?)",(\s*"thumbnailUrl":.*)',
|
||||
metajson, flags=re.DOTALL)
|
||||
if mo:
|
||||
desc_text = mo.group(2)
|
||||
metajson = mo.group(1) + mo.group(3)
|
||||
metad = self._parse_json(metajson, video_id, fatal=False)
|
||||
else:
|
||||
self.report_warning("Could not fix metadata JSON", video_id)
|
||||
|
||||
livestream_title = get_element_by_class(
|
||||
'unpublished-info-item future-event-title', page)
|
||||
|
||||
duration = None
|
||||
thumbnail = None
|
||||
if metad:
|
||||
title = metad.get('name')
|
||||
description = desc_text
|
||||
timestamp = unified_timestamp(metad.get('uploadDate'))
|
||||
thumbnail = url_or_none(metad.get('thumbnailUrl'))
|
||||
elif token2:
|
||||
base_url = self._search_regex(r'(https?://[^/]+)/', url, 'base_url')
|
||||
data = {
|
||||
"version": "03",
|
||||
"action": "getAsset",
|
||||
"organizationId": organization_id,
|
||||
"assetId": video_id,
|
||||
"languageId": "en_US",
|
||||
"userId": "0",
|
||||
"token": token2,
|
||||
}
|
||||
metad = self._download_json(base_url + self._API2_PATH, video_id,
|
||||
data=urlencode_postdata(data))
|
||||
title = metad.get('name')
|
||||
description = metad.get('description')
|
||||
timestamp = int_or_none(metad.get('date'), scale=1000)
|
||||
duration = int_or_none(metad.get('duration'))
|
||||
thumbnail = url_or_none(metad.get('thumbnailMedium'))
|
||||
elif livestream_title: # Recorded livestream
|
||||
title = livestream_title
|
||||
description = get_element_by_class(
|
||||
'unpublished-info-item future-event-description', page)
|
||||
timestamp = int_or_none(self._search_regex(
|
||||
r"var startEvent\s*=\s*(\d+);", page, "uploadDate",
|
||||
fatal=False), scale=1000)
|
||||
else:
|
||||
self.report_warning("Could not extract metadata", video_id)
|
||||
description = None
|
||||
timestamp = None
|
||||
|
||||
title = title if title else video_id
|
||||
description = clean_html(description)
|
||||
|
||||
data = {
|
||||
"version": "03",
|
||||
"action": "getAssetPlaybackUrls",
|
||||
"organizationId": organization_id,
|
||||
"assetId": video_id,
|
||||
"token": token,
|
||||
}
|
||||
jsond = self._download_json(api_base, video_id,
|
||||
data=urlencode_postdata(data))
|
||||
|
||||
if thumbnail is None:
|
||||
thumbnail = url_or_none(jsond.get('thumbnail'))
|
||||
|
||||
formats = []
|
||||
for item in jsond.get('urls', []):
|
||||
video_url = url_or_none(item.get('url'))
|
||||
ext = determine_ext(video_url)
|
||||
if ext == 'm3u8':
|
||||
formats.extend(self._extract_m3u8_formats(
|
||||
video_url, video_id, 'mp4',
|
||||
entry_protocol='m3u8_native', m3u8_id='hls',
|
||||
fatal=False))
|
||||
else:
|
||||
fd = {'url': video_url}
|
||||
fmt = item.get('name')
|
||||
if fmt:
|
||||
fd['format'] = fmt
|
||||
fd.update(parse_resolution(fmt))
|
||||
mo = re.search(r'\((\d+)\s*kbps\)\s*\+\s*(\d+)\s*kbps', fmt)
|
||||
if mo:
|
||||
fd['vbr'] = int_or_none(mo.group(1))
|
||||
fd['abr'] = int_or_none(mo.group(2))
|
||||
else:
|
||||
fd['tbr'] = parse_bitrate(fmt)
|
||||
fmt_id = item.get('id')
|
||||
if fmt_id:
|
||||
fd['format_id'] = str(fmt_id)
|
||||
formats.append(fd)
|
||||
|
||||
for item in jsond.get('audio_urls', []):
|
||||
fmt = item.get('name')
|
||||
mo = re.match(r'.*\((\d+)k\).*', fmt if fmt else '')
|
||||
abr = int_or_none(mo.group(1)) if mo else None
|
||||
fd = {
|
||||
'format': fmt,
|
||||
'format_id': 'audio',
|
||||
'url': url_or_none(item.get('url')),
|
||||
'vcodec': 'none',
|
||||
}
|
||||
if abr:
|
||||
fd['abr'] = abr
|
||||
formats.append(fd)
|
||||
|
||||
subtitles = {}
|
||||
for sub in jsond.get('subtitles', []):
|
||||
scode, sdesc, surl = sub
|
||||
lang = sdesc.split(' ')[0]
|
||||
lang = lang[:-1] if lang.endswith(':') else lang
|
||||
subtitles[lang] = [{"url": url_or_none(surl)}]
|
||||
|
||||
info = {
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'thumbnail': thumbnail,
|
||||
'timestamp': timestamp,
|
||||
'formats': formats,
|
||||
}
|
||||
if duration:
|
||||
info['duration'] = duration
|
||||
if subtitles:
|
||||
info['subtitles'] = subtitles
|
||||
|
||||
return info
|
@ -1659,17 +1659,46 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
def _extract_n_function_name(self, jscode):
|
||||
func_name, idx = self._search_regex(
|
||||
# new: (b=String.fromCharCode(110),c=a.get(b))&&c=nfunc[idx](c)
|
||||
# or: (b="nn"[+a.D],c=a.get(b))&&(c=nfunc[idx](c)s
|
||||
# old: .get("n"))&&(b=nfunc[idx](b)
|
||||
# older: .get("n"))&&(b=nfunc(b)
|
||||
# or: (b="nn"[+a.D],c=a.get(b))&&(c=nfunc[idx](c)
|
||||
# or: (PL(a),b=a.j.n||null)&&(b=nfunc[idx](b)
|
||||
# or: (b="nn"[+a.D],vL(a),c=a.j[b]||null)&&(c=narray[idx](c),a.set(b,c),narray.length||nfunc("")
|
||||
# old: (b=a.get("n"))&&(b=nfunc[idx](b)(?P<c>[a-z])\s*=\s*[a-z]\s*
|
||||
# older: (b=a.get("n"))&&(b=nfunc(b)
|
||||
r'''(?x)
|
||||
(?:\(\s*(?P<b>[a-z])\s*=\s*(?:
|
||||
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
||||
"n+"\[\s*\+?s*[\w$.]+\s*]
|
||||
)\s*,(?P<c>[a-z])\s*=\s*[a-z]\s*)?
|
||||
\.\s*get\s*\(\s*(?(b)(?P=b)|"n{1,2}")(?:\s*\)){2}\s*&&\s*\(\s*(?(c)(?P=c)|b)\s*=\s*
|
||||
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
||||
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
|
||||
\((?:[\w$()\s]+,)*?\s* # (
|
||||
(?P<b>[a-z])\s*=\s* # b=
|
||||
(?:
|
||||
(?: # expect ,c=a.get(b) (etc)
|
||||
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
||||
"n+"\[\s*\+?s*[\w$.]+\s*]
|
||||
)\s*(?:,[\w$()\s]+(?=,))*|
|
||||
(?P<old>[\w$]+) # a (old[er])
|
||||
)\s*
|
||||
(?(old)
|
||||
# b.get("n")
|
||||
(?:\.\s*[\w$]+\s*|\[\s*[\w$]+\s*]\s*)*?
|
||||
(?:\.\s*n|\[\s*"n"\s*]|\.\s*get\s*\(\s*"n"\s*\))
|
||||
| # ,c=a.get(b)
|
||||
,\s*(?P<c>[a-z])\s*=\s*[a-z]\s*
|
||||
(?:\.\s*[\w$]+\s*|\[\s*[\w$]+\s*]\s*)*?
|
||||
(?:\[\s*(?P=b)\s*]|\.\s*get\s*\(\s*(?P=b)\s*\))
|
||||
)
|
||||
# interstitial junk
|
||||
\s*(?:\|\|\s*null\s*)?(?:\)\s*)?&&\s*(?:\(\s*)?
|
||||
(?(c)(?P=c)|(?P=b))\s*=\s* # [c|b]=
|
||||
# nfunc|nfunc[idx]
|
||||
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
||||
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'),
|
||||
default=(None, None))
|
||||
# thx bashonly: yt-dlp/yt-dlp/pull/10611
|
||||
if not func_name:
|
||||
self.report_warning('Falling back to generic n function search')
|
||||
return self._search_regex(
|
||||
r'''(?xs)
|
||||
(?:(?<=[^\w$])|^) # instead of \b, which ignores $
|
||||
(?P<name>(?!\d)[a-zA-Z\d_$]+)\s*=\s*function\((?!\d)[a-zA-Z\d_$]+\)
|
||||
\s*\{(?:(?!};).)+?["']enhanced_except_
|
||||
''', jscode, 'Initial JS player n function name', group='name')
|
||||
if not idx:
|
||||
return func_name
|
||||
|
||||
|
@ -925,9 +925,16 @@ class JSInterpreter(object):
|
||||
obj.reverse()
|
||||
return obj
|
||||
elif member == 'slice':
|
||||
assertion(isinstance(obj, list), 'must be applied on a list')
|
||||
assertion(len(argvals) == 1, 'takes exactly one argument')
|
||||
return obj[argvals[0]:]
|
||||
assertion(isinstance(obj, (list, compat_str)), 'must be applied on a list or string')
|
||||
# From [1]:
|
||||
# .slice() - like [:]
|
||||
# .slice(n) - like [n:] (not [slice(n)]
|
||||
# .slice(m, n) - like [m:n] or [slice(m, n)]
|
||||
# [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
|
||||
assertion(len(argvals) <= 2, 'takes between 0 and 2 arguments')
|
||||
if len(argvals) < 2:
|
||||
argvals += (None,)
|
||||
return obj[slice(*argvals)]
|
||||
elif member == 'splice':
|
||||
assertion(isinstance(obj, list), 'must be applied on a list')
|
||||
assertion(argvals, 'takes one or more arguments')
|
||||
|
Loading…
Reference in New Issue
Block a user