mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-01-10 21:40:11 +09:00
Compare commits
12 Commits
29904cfb9b
...
2a52337036
Author | SHA1 | Date | |
---|---|---|---|
|
2a52337036 | ||
|
c5098961b0 | ||
|
dbc08fba83 | ||
|
71223bff39 | ||
|
b0f50733a1 | ||
|
1b8805f831 | ||
|
bf7392922f | ||
|
7cc9d5b321 | ||
|
a8f88d2fec | ||
|
d82b6697c2 | ||
|
de4144a4ae | ||
|
503406d4bc |
@ -425,6 +425,34 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
self._test(jsi, [''], args=['', '-'])
|
self._test(jsi, [''], args=['', '-'])
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -174,6 +174,14 @@ _NSIG_TESTS = [
|
|||||||
'https://www.youtube.com/s/player/5604538d/player_ias.vflset/en_US/base.js',
|
'https://www.youtube.com/s/player/5604538d/player_ias.vflset/en_US/base.js',
|
||||||
'7X-he4jjvMx7BCX', 'sViSydX8IHtdWA',
|
'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',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
242
youtube_dl/extractor/duboku.py
Normal file
242
youtube_dl/extractor/duboku.py
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
from .common import InfoExtractor
|
||||||
|
from ..compat import compat_urlparse
|
||||||
|
from ..utils import (
|
||||||
|
clean_html,
|
||||||
|
extract_attributes,
|
||||||
|
ExtractorError,
|
||||||
|
get_elements_by_class,
|
||||||
|
int_or_none,
|
||||||
|
js_to_json,
|
||||||
|
smuggle_url,
|
||||||
|
unescapeHTML,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_elements_by_tag_and_attrib(html, tag=None, attribute=None, value=None, escape_value=True):
|
||||||
|
"""Return the content of the tag with the specified attribute in the passed HTML document"""
|
||||||
|
|
||||||
|
if tag is None:
|
||||||
|
tag = '[a-zA-Z0-9:._-]+'
|
||||||
|
if attribute is None:
|
||||||
|
attribute = ''
|
||||||
|
else:
|
||||||
|
attribute = r'\s+(?P<attribute>%s)' % re.escape(attribute)
|
||||||
|
if value is None:
|
||||||
|
value = ''
|
||||||
|
else:
|
||||||
|
value = re.escape(value) if escape_value else value
|
||||||
|
value = '=[\'"]?(?P<value>%s)[\'"]?' % value
|
||||||
|
|
||||||
|
retlist = []
|
||||||
|
for m in re.finditer(r'''(?xs)
|
||||||
|
<(?P<tag>%s)
|
||||||
|
(?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'|))*?
|
||||||
|
%s%s
|
||||||
|
(?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'|))*?
|
||||||
|
\s*>
|
||||||
|
(?P<content>.*?)
|
||||||
|
</\1>
|
||||||
|
''' % (tag, attribute, value), html):
|
||||||
|
retlist.append(m)
|
||||||
|
|
||||||
|
return retlist
|
||||||
|
|
||||||
|
|
||||||
|
def _get_element_by_tag_and_attrib(html, tag=None, attribute=None, value=None, escape_value=True):
|
||||||
|
retval = _get_elements_by_tag_and_attrib(html, tag, attribute, value, escape_value)
|
||||||
|
return retval[0] if retval else None
|
||||||
|
|
||||||
|
|
||||||
|
class DubokuIE(InfoExtractor):
|
||||||
|
IE_NAME = 'duboku'
|
||||||
|
IE_DESC = 'www.duboku.co'
|
||||||
|
|
||||||
|
_VALID_URL = r'(?:https?://[^/]+\.duboku\.co/vodplay/)(?P<id>[0-9]+-[0-9-]+)\.html.*'
|
||||||
|
_TESTS = [{
|
||||||
|
'url': 'https://www.duboku.co/vodplay/1575-1-1.html',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '1575-1-1',
|
||||||
|
'ext': 'ts',
|
||||||
|
'series': '白色月光',
|
||||||
|
'title': 'contains:白色月光',
|
||||||
|
'season_number': 1,
|
||||||
|
'episode_number': 1,
|
||||||
|
},
|
||||||
|
'params': {
|
||||||
|
'skip_download': 'm3u8 download',
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.duboku.co/vodplay/1588-1-1.html',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '1588-1-1',
|
||||||
|
'ext': 'ts',
|
||||||
|
'series': '亲爱的自己',
|
||||||
|
'title': 'contains:预告片',
|
||||||
|
'season_number': 1,
|
||||||
|
'episode_number': 1,
|
||||||
|
},
|
||||||
|
'params': {
|
||||||
|
'skip_download': 'm3u8 download',
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
|
||||||
|
_PLAYER_DATA_PATTERN = r'player_data\s*=\s*(\{\s*(.*)})\s*;?\s*</script'
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
video_id = self._match_id(url)
|
||||||
|
temp = video_id.split('-')
|
||||||
|
series_id = temp[0]
|
||||||
|
season_id = temp[1]
|
||||||
|
episode_id = temp[2]
|
||||||
|
|
||||||
|
webpage_url = 'https://www.duboku.co/vodplay/%s.html' % video_id
|
||||||
|
webpage_html = self._download_webpage(webpage_url, video_id)
|
||||||
|
|
||||||
|
# extract video url
|
||||||
|
|
||||||
|
player_data = self._search_regex(
|
||||||
|
self._PLAYER_DATA_PATTERN, webpage_html, 'player_data')
|
||||||
|
player_data = self._parse_json(player_data, video_id, js_to_json)
|
||||||
|
|
||||||
|
# extract title
|
||||||
|
|
||||||
|
temp = get_elements_by_class('title', webpage_html)
|
||||||
|
series_title = None
|
||||||
|
title = None
|
||||||
|
for html in temp:
|
||||||
|
mobj = re.search(r'<a\s+.*>(.*)</a>', html)
|
||||||
|
if mobj:
|
||||||
|
href = extract_attributes(mobj.group(0)).get('href')
|
||||||
|
if href:
|
||||||
|
mobj1 = re.search(r'/(\d+)\.html', href)
|
||||||
|
if mobj1 and mobj1.group(1) == series_id:
|
||||||
|
series_title = clean_html(mobj.group(0))
|
||||||
|
series_title = re.sub(r'[\s\r\n\t]+', ' ', series_title)
|
||||||
|
title = clean_html(html)
|
||||||
|
title = re.sub(r'[\s\r\n\t]+', ' ', title)
|
||||||
|
break
|
||||||
|
|
||||||
|
data_url = player_data.get('url')
|
||||||
|
if not data_url:
|
||||||
|
raise ExtractorError('Cannot find url in player_data')
|
||||||
|
data_from = player_data.get('from')
|
||||||
|
|
||||||
|
# if it is an embedded iframe, maybe it's an external source
|
||||||
|
if data_from == 'iframe':
|
||||||
|
# use _type url_transparent to retain the meaningful details
|
||||||
|
# of the video.
|
||||||
|
return {
|
||||||
|
'_type': 'url_transparent',
|
||||||
|
'url': smuggle_url(data_url, {'http_headers': {'Referer': webpage_url}}),
|
||||||
|
'id': video_id,
|
||||||
|
'title': title,
|
||||||
|
'series': series_title,
|
||||||
|
'season_number': int_or_none(season_id),
|
||||||
|
'season_id': season_id,
|
||||||
|
'episode_number': int_or_none(episode_id),
|
||||||
|
'episode_id': episode_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
formats = self._extract_m3u8_formats(data_url, video_id, 'mp4')
|
||||||
|
|
||||||
|
return {
|
||||||
|
'id': video_id,
|
||||||
|
'title': title,
|
||||||
|
'series': series_title,
|
||||||
|
'season_number': int_or_none(season_id),
|
||||||
|
'season_id': season_id,
|
||||||
|
'episode_number': int_or_none(episode_id),
|
||||||
|
'episode_id': episode_id,
|
||||||
|
'formats': formats,
|
||||||
|
'http_headers': {'Referer': 'https://www.duboku.co/static/player/videojs.html'}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DubokuPlaylistIE(InfoExtractor):
|
||||||
|
IE_NAME = 'duboku:list'
|
||||||
|
IE_DESC = 'www.duboku.co entire series'
|
||||||
|
|
||||||
|
_VALID_URL = r'(?:https?://[^/]+\.duboku\.co/voddetail/)(?P<id>[0-9]+)\.html.*'
|
||||||
|
_TESTS = [{
|
||||||
|
'url': 'https://www.duboku.co/voddetail/1575.html',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'startswith:1575',
|
||||||
|
'title': '白色月光',
|
||||||
|
},
|
||||||
|
'playlist_count': 12,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.duboku.co/voddetail/1554.html',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'startswith:1554',
|
||||||
|
'title': '以家人之名',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 30,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.duboku.co/voddetail/1554.html#playlist2',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '1554#playlist2',
|
||||||
|
'title': '以家人之名',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 27,
|
||||||
|
}]
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
mobj = re.match(self._VALID_URL, url)
|
||||||
|
if mobj is None:
|
||||||
|
raise ExtractorError('Invalid URL: %s' % url)
|
||||||
|
series_id = mobj.group('id')
|
||||||
|
fragment = compat_urlparse.urlparse(url).fragment
|
||||||
|
|
||||||
|
webpage_url = 'https://www.duboku.co/voddetail/%s.html' % series_id
|
||||||
|
webpage_html = self._download_webpage(webpage_url, series_id)
|
||||||
|
|
||||||
|
# extract title
|
||||||
|
|
||||||
|
title = _get_element_by_tag_and_attrib(webpage_html, 'h1', 'class', 'title')
|
||||||
|
title = unescapeHTML(title.group('content')) if title else None
|
||||||
|
if not title:
|
||||||
|
title = self._html_search_meta('keywords', webpage_html)
|
||||||
|
if not title:
|
||||||
|
title = _get_element_by_tag_and_attrib(webpage_html, 'title')
|
||||||
|
title = unescapeHTML(title.group('content')) if title else None
|
||||||
|
|
||||||
|
# extract playlists
|
||||||
|
|
||||||
|
playlists = {}
|
||||||
|
for div in _get_elements_by_tag_and_attrib(
|
||||||
|
webpage_html, attribute='id', value='playlist\\d+', escape_value=False):
|
||||||
|
playlist_id = div.group('value')
|
||||||
|
playlist = []
|
||||||
|
for a in _get_elements_by_tag_and_attrib(
|
||||||
|
div.group('content'), 'a', 'href', value='[^\'"]+?', escape_value=False):
|
||||||
|
playlist.append({
|
||||||
|
'href': unescapeHTML(a.group('value')),
|
||||||
|
'title': unescapeHTML(a.group('content'))
|
||||||
|
})
|
||||||
|
playlists[playlist_id] = playlist
|
||||||
|
|
||||||
|
# select the specified playlist if url fragment exists
|
||||||
|
playlist = None
|
||||||
|
playlist_id = None
|
||||||
|
if fragment:
|
||||||
|
playlist = playlists.get(fragment)
|
||||||
|
playlist_id = fragment
|
||||||
|
else:
|
||||||
|
first = next(iter(playlists.items()), None)
|
||||||
|
if first:
|
||||||
|
(playlist_id, playlist) = first
|
||||||
|
if not playlist:
|
||||||
|
raise ExtractorError(
|
||||||
|
'Cannot find %s' % fragment if fragment else 'Cannot extract playlist')
|
||||||
|
|
||||||
|
# return url results
|
||||||
|
return self.playlist_result([
|
||||||
|
self.url_result(
|
||||||
|
compat_urlparse.urljoin('https://www.duboku.co', x['href']),
|
||||||
|
ie=DubokuIE.ie_key(), video_title=x.get('title'))
|
||||||
|
for x in playlist], series_id + '#' + playlist_id, title)
|
@ -323,6 +323,10 @@ from .drtv import (
|
|||||||
)
|
)
|
||||||
from .dtube import DTubeIE
|
from .dtube import DTubeIE
|
||||||
from .dvtv import DVTVIE
|
from .dvtv import DVTVIE
|
||||||
|
from .duboku import (
|
||||||
|
DubokuIE,
|
||||||
|
DubokuPlaylistIE
|
||||||
|
)
|
||||||
from .dumpert import DumpertIE
|
from .dumpert import DumpertIE
|
||||||
from .defense import DefenseGouvFrIE
|
from .defense import DefenseGouvFrIE
|
||||||
from .discovery import DiscoveryIE
|
from .discovery import DiscoveryIE
|
||||||
|
@ -1659,17 +1659,46 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
def _extract_n_function_name(self, jscode):
|
def _extract_n_function_name(self, jscode):
|
||||||
func_name, idx = self._search_regex(
|
func_name, idx = self._search_regex(
|
||||||
# new: (b=String.fromCharCode(110),c=a.get(b))&&c=nfunc[idx](c)
|
# 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
|
# or: (b="nn"[+a.D],c=a.get(b))&&(c=nfunc[idx](c)
|
||||||
# old: .get("n"))&&(b=nfunc[idx](b)
|
# or: (PL(a),b=a.j.n||null)&&(b=nfunc[idx](b)
|
||||||
# older: .get("n"))&&(b=nfunc(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)
|
r'''(?x)
|
||||||
(?:\(\s*(?P<b>[a-z])\s*=\s*(?:
|
\((?:[\w$()\s]+,)*?\s* # (
|
||||||
|
(?P<b>[a-z])\s*=\s* # b=
|
||||||
|
(?:
|
||||||
|
(?: # expect ,c=a.get(b) (etc)
|
||||||
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
||||||
"n+"\[\s*\+?s*[\w$.]+\s*]
|
"n+"\[\s*\+?s*[\w$.]+\s*]
|
||||||
)\s*,(?P<c>[a-z])\s*=\s*[a-z]\s*)?
|
)\s*(?:,[\w$()\s]+(?=,))*|
|
||||||
\.\s*get\s*\(\s*(?(b)(?P=b)|"n{1,2}")(?:\s*\)){2}\s*&&\s*\(\s*(?(c)(?P=c)|b)\s*=\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*\)
|
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
||||||
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
|
''', 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:
|
if not idx:
|
||||||
return func_name
|
return func_name
|
||||||
|
|
||||||
|
@ -925,9 +925,16 @@ class JSInterpreter(object):
|
|||||||
obj.reverse()
|
obj.reverse()
|
||||||
return obj
|
return obj
|
||||||
elif member == 'slice':
|
elif member == 'slice':
|
||||||
assertion(isinstance(obj, list), 'must be applied on a list')
|
assertion(isinstance(obj, (list, compat_str)), 'must be applied on a list or string')
|
||||||
assertion(len(argvals) == 1, 'takes exactly one argument')
|
# From [1]:
|
||||||
return obj[argvals[0]:]
|
# .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':
|
elif member == 'splice':
|
||||||
assertion(isinstance(obj, list), 'must be applied on a list')
|
assertion(isinstance(obj, list), 'must be applied on a list')
|
||||||
assertion(argvals, 'takes one or more arguments')
|
assertion(argvals, 'takes one or more arguments')
|
||||||
|
Loading…
Reference in New Issue
Block a user