mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-18 06:32:06 +00:00
Compare commits
6 Commits
bf726b2cf6
...
29c553f9f6
Author | SHA1 | Date | |
---|---|---|---|
|
29c553f9f6 | ||
|
c5098961b0 | ||
|
dbc08fba83 | ||
|
71223bff39 | ||
|
e8eb999df4 | ||
|
171b7deda0 |
@ -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',
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
169
youtube_dl/extractor/bandlab.py
Normal file
169
youtube_dl/extractor/bandlab.py
Normal file
@ -0,0 +1,169 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from .common import InfoExtractor
|
||||
|
||||
from ..compat import (
|
||||
compat_str,
|
||||
)
|
||||
|
||||
from ..utils import (
|
||||
strip_or_none,
|
||||
try_get,
|
||||
url_or_none,
|
||||
)
|
||||
|
||||
|
||||
class BandlabIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?bandlab\.com/post/(?P<id>[^/]+)'
|
||||
|
||||
_TESTS = [{
|
||||
'url': 'https://www.bandlab.com/post/f5f04998635a44ea819cacdba7ae2076_f8d8574c3bdaec11b6562818783151a1',
|
||||
'info_dict': {
|
||||
'id': 'f5f04998635a44ea819cacdba7ae2076_f8d8574c3bdaec11b6562818783151a1',
|
||||
'ext': 'm4a',
|
||||
'title': 'ON MY OWN (unreleased)',
|
||||
'artist': 'Michael MacDonald',
|
||||
},
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
track_id = self._match_id(url)
|
||||
config = self._download_json(
|
||||
'http://www.bandlab.com/api/v1.3/posts/%s' % track_id, track_id)
|
||||
track_url = config['track']['sample']['audioUrl']
|
||||
|
||||
return {
|
||||
'id': track_id,
|
||||
'title': config['track']['name'],
|
||||
'url': track_url,
|
||||
'artist': config['creator']['name']
|
||||
}
|
||||
|
||||
|
||||
class BandlabAlbumOrPlaylistIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?bandlab\.com/[^/]+/(?P<kind>albums|collections)/(?P<id>[^/]+)'
|
||||
_TRACK_ID_RE = r'.+/(?P<id>[^/]+)\.m4a'
|
||||
_TESTS = [{
|
||||
'url': 'https://www.bandlab.com/sbsdasani/albums/dc26e307-e51f-ed11-95d7-002248452390',
|
||||
'playlist': [
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '91feeb36-8e10-4c91-ae57-ffac0a98c6b4',
|
||||
'title': 'How\'d I Lose You? (Intro)',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': 'd87c50a2-70cb-4937-9b97-3ae8646ca3aa',
|
||||
'title': 'Money $$$',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': 'ff2909ff-348f-448d-9d2c-7edbf2f0ec5e',
|
||||
'title': 'You\'ll Be Mine',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '53786c38-1f3c-4921-9271-793a64af7186',
|
||||
'title': 'Who You Are',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '0394bb27-113f-4d19-b902-f9c1fe6ba8a8',
|
||||
'title': 'In Your Eyes',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '2aa44689-c7fa-4d0e-b28a-e0d1dd570372',
|
||||
'title': 'The Same',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '281fe589-a559-4260-802d-78a6c7a973d8',
|
||||
'title': 'Fall In Love',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '83a9dc0a-702f-40fd-82f6-ab847f6a7b46',
|
||||
'title': 'Tried So Hard',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
},
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '3f6a4a1c-eb73-449f-bd45-f7958d6f2de1',
|
||||
'title': 'The End Of Everything',
|
||||
'ext': 'm4a',
|
||||
},
|
||||
}
|
||||
],
|
||||
'info_dict': {
|
||||
'id': 'dc26e307-e51f-ed11-95d7-002248452390',
|
||||
'album': 'ENDLESS SUMMER',
|
||||
'artist': 'Michael MacDonald'
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.bandlab.com/hexatetrahedronx/collections/8fb1041c-e865-eb11-9889-0050f28a2802',
|
||||
'playlist': [
|
||||
{
|
||||
'info_dict': {
|
||||
'id': '8f37e4aa-92c4-eb11-a7ad-0050f280467f',
|
||||
'title': 'psych ward',
|
||||
'ext': 'm4a'
|
||||
}
|
||||
}
|
||||
],
|
||||
'info_dict': {
|
||||
'id': '8fb1041c-e865-eb11-9889-0050f28a2802',
|
||||
'album': 'DOOMTAPE',
|
||||
'artist': '12days'
|
||||
}
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
resource_id, kind = re.match(self._VALID_URL, url).group('id', 'kind')
|
||||
config = self._download_json(
|
||||
'http://www.bandlab.com/api/v1.3/%s/%s' % (kind, resource_id), resource_id)
|
||||
entries = []
|
||||
for track in try_get(config, lambda x: x['posts'], list) or []:
|
||||
url, name = try_get(
|
||||
track,
|
||||
(lambda x: (x['track']['sample']['audioUrl'], x['track']['name']),
|
||||
lambda x: (x['revision']['mixdown']['file'], x['revision']['song']['name'])),
|
||||
tuple) or (None, '', )
|
||||
url = url_or_none(url)
|
||||
name = strip_or_none(name)
|
||||
if not (url and name):
|
||||
continue
|
||||
track_id = re.match(self._TRACK_ID_RE, url).group('id')
|
||||
if not track_id:
|
||||
continue
|
||||
entries.append({
|
||||
'url': url,
|
||||
'id': track_id,
|
||||
'title': name,
|
||||
})
|
||||
|
||||
return {
|
||||
'_type': 'playlist',
|
||||
'id': resource_id,
|
||||
'entries': entries,
|
||||
'album': try_get(config, lambda x: x['name'].strip(), compat_str),
|
||||
'artist': try_get(config, lambda x: x['creator']['name'].strip(), compat_str)
|
||||
}
|
@ -776,8 +776,13 @@ from .ndr import (
|
||||
NJoyEmbedIE,
|
||||
)
|
||||
from .ndtv import NDTVIE
|
||||
from .bandlab import (
|
||||
BandlabIE,
|
||||
BandlabAlbumOrPlaylistIE
|
||||
)
|
||||
from .netzkino import NetzkinoIE
|
||||
from .nerdcubed import NerdCubedFeedIE
|
||||
from .nest import NestIE
|
||||
from .neteasemusic import (
|
||||
NetEaseMusicIE,
|
||||
NetEaseMusicAlbumIE,
|
||||
|
39
youtube_dl/extractor/nest.py
Normal file
39
youtube_dl/extractor/nest.py
Normal file
@ -0,0 +1,39 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .common import InfoExtractor
|
||||
|
||||
|
||||
class NestIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?video.nest\.com/clip/(?P<id>)(.mp4)?'
|
||||
_TEST = {
|
||||
'url': 'https://video.nest.com/clip/73ddb6bd57c4485597a76e154a4429ea.mp4',
|
||||
'md5': '7ab4eb6d4c2480be1740cc014a76ee96',
|
||||
'info_dict': {
|
||||
'id': '73ddb6bd57c4485597a76e154a4429ea',
|
||||
'ext': 'mp4',
|
||||
'title': "\"\"",
|
||||
'description': '#caughtonNestCam',
|
||||
}
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, video_id)
|
||||
video_id = self._search_regex(
|
||||
r'https:\/\/video.nest.com\/clip\/(.+?)(\.|")', webpage, 'video_id', fatal=False)
|
||||
title = self._html_search_meta(['og:title', 'title'], webpage, 'title')
|
||||
if title == "":
|
||||
title = "\"\""
|
||||
description = self._html_search_meta(['og:description', 'description'], webpage, 'description')
|
||||
ext = self._html_search_meta('og:video:type', webpage, 'ext')
|
||||
if "/" in ext:
|
||||
ext = ext[ext.index("/") + 1:]
|
||||
return {
|
||||
'url': self._html_search_meta(['og:video:url', 'url'], webpage, 'url'),
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'ext': ext,
|
||||
'thumbnail': self._html_search_meta(['og:image', 'image'], webpage, 'thumbnail'),
|
||||
}
|
@ -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