kopia lustrzana https://github.com/yt-dlp/yt-dlp
Porównaj commity
15 Commity
14d699ec5b
...
90d70f72d2
Autor | SHA1 | Data |
---|---|---|
HobbyistDev | 90d70f72d2 | |
Simon Sawicki | 64766459e3 | |
bashonly | 89f535e265 | |
HobbyistDev | eecd76dd92 | |
HobbyistDev | 24e83cf661 | |
HobbyistDev | bcda65fcc5 | |
HobbyistDev | 31c45e0dfd | |
HobbyistDev | 0b9fc25be6 | |
HobbyistDev | 6c6ad3298d | |
HobbyistDev | c895dfea10 | |
HobbyistDev | 05648c4fe9 | |
HobbyistDev | 27a6f8330b | |
HobbyistDev | aa2dda16cd | |
HobbyistDev | 8f2567f048 | |
HobbyistDev | 363f6b3029 |
|
@ -53,7 +53,7 @@ jobs:
|
|||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install test requirements
|
||||
run: python3 ./devscripts/install_deps.py --include dev --include curl_cffi
|
||||
run: python3 ./devscripts/install_deps.py --include dev --include curl-cffi
|
||||
- name: Run tests
|
||||
continue-on-error: False
|
||||
run: |
|
||||
|
|
|
@ -2059,7 +2059,22 @@ Line 1
|
|||
assert extract_basic_auth('http://user:pass@foo.bar') == ('http://foo.bar', 'Basic dXNlcjpwYXNz')
|
||||
|
||||
@unittest.skipUnless(compat_os_name == 'nt', 'Only relevant on Windows')
|
||||
def test_Popen_windows_escaping(self):
|
||||
def test_windows_escaping(self):
|
||||
tests = [
|
||||
'test"&',
|
||||
'%CMDCMDLINE:~-1%&',
|
||||
'a\nb',
|
||||
'"',
|
||||
'\\',
|
||||
'!',
|
||||
'^!',
|
||||
'a \\ b',
|
||||
'a \\" b',
|
||||
'a \\ b\\',
|
||||
# We replace \r with \n
|
||||
('a\r\ra', 'a\n\na'),
|
||||
]
|
||||
|
||||
def run_shell(args):
|
||||
stdout, stderr, error = Popen.run(
|
||||
args, text=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
@ -2067,15 +2082,18 @@ Line 1
|
|||
assert not error
|
||||
return stdout
|
||||
|
||||
# Test escaping
|
||||
assert run_shell(['echo', 'test"&']) == '"test""&"\n'
|
||||
assert run_shell(['echo', '%CMDCMDLINE:~-1%&']) == '"%CMDCMDLINE:~-1%&"\n'
|
||||
assert run_shell(['echo', 'a\nb']) == '"a"\n"b"\n'
|
||||
assert run_shell(['echo', '"']) == '""""\n'
|
||||
assert run_shell(['echo', '\\']) == '\\\n'
|
||||
# Test if delayed expansion is disabled
|
||||
assert run_shell(['echo', '^!']) == '"^!"\n'
|
||||
assert run_shell('echo "^!"') == '"^!"\n'
|
||||
for argument in tests:
|
||||
if isinstance(argument, str):
|
||||
expected = argument
|
||||
else:
|
||||
argument, expected = argument
|
||||
|
||||
args = [sys.executable, '-c', 'import sys; print(end=sys.argv[1])', argument, 'end']
|
||||
assert run_shell(args) == expected
|
||||
|
||||
escaped = shell_quote(argument, shell=True)
|
||||
args = f'{sys.executable} -c "import sys; print(end=sys.argv[1])" {escaped} end'
|
||||
assert run_shell(args) == expected
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -2379,6 +2379,7 @@ from .xhamster import (
|
|||
XHamsterEmbedIE,
|
||||
XHamsterUserIE,
|
||||
)
|
||||
from .xiaohongshu import XiaoHongShuIE
|
||||
from .ximalaya import (
|
||||
XimalayaIE,
|
||||
XimalayaAlbumIE
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
float_or_none,
|
||||
js_to_json,
|
||||
url_or_none,
|
||||
)
|
||||
from ..utils.traversal import traverse_obj
|
||||
|
||||
|
||||
class XiaoHongShuIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://www\.xiaohongshu.com/explore/(?P<id>[a-f0-9]+)'
|
||||
IE_DESC = '小红书'
|
||||
_TESTS = [{
|
||||
'url': 'https://www.xiaohongshu.com/explore/6411cf99000000001300b6d9',
|
||||
'md5': '2a87a77ddbedcaeeda8d7eae61b61228',
|
||||
'info_dict': {
|
||||
'id': '6411cf99000000001300b6d9',
|
||||
'ext': 'mp4',
|
||||
'uploader_id': '5c31698d0000000007018a31',
|
||||
'description': '#今日快乐今日发[话题]# #吃货薯看这里[话题]# #香妃蛋糕[话题]# #小五卷蛋糕[话题]# #新手蛋糕卷[话题]#',
|
||||
'title': '香妃蛋糕也太香了吧🔥不需要卷❗️绝对的友好',
|
||||
'tags': ['今日快乐今日发', '吃货薯看这里', '香妃蛋糕', '小五卷蛋糕', '新手蛋糕卷'],
|
||||
'duration': 101.726,
|
||||
'thumbnail': r're:https?://sns-webpic-qc\.xhscdn\.com/\d+/[a-z0-9]+/[\w]+',
|
||||
}
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, display_id)
|
||||
initial_state = self._search_json(
|
||||
r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', display_id, transform_source=js_to_json)
|
||||
|
||||
note_info = traverse_obj(initial_state, ('note', 'noteDetailMap', display_id, 'note'))
|
||||
video_info = traverse_obj(note_info, ('video', 'media', 'stream', ('h264', 'av1', 'h265'), ...))
|
||||
|
||||
formats = []
|
||||
for info in video_info:
|
||||
format_info = traverse_obj(info, {
|
||||
'fps': 'fps',
|
||||
'width': 'width',
|
||||
'height': 'height',
|
||||
'vcodec': 'videoCodec',
|
||||
'acodec': 'audioCodec',
|
||||
'abr': 'audioBitrate',
|
||||
'vbr': 'videoBitrate',
|
||||
'audio_channels': 'audioChannels',
|
||||
'tbr': 'avgBitrate',
|
||||
'format': 'qualityType',
|
||||
'filesize': 'size',
|
||||
'duration': ('duration', {lambda x: float_or_none(x, scale=1000)})
|
||||
})
|
||||
|
||||
formats.extend(traverse_obj(info, (('mediaUrl', ('backupUrls', ...)), {
|
||||
lambda url: url_or_none(url) and {'url': url, 'ext': 'mp4', **format_info}})))
|
||||
|
||||
thumbnails = []
|
||||
for image_info in traverse_obj(note_info, ('imageList', ...)):
|
||||
thumbnail_info = traverse_obj(image_info, {
|
||||
'height': 'height',
|
||||
'width': 'width'
|
||||
})
|
||||
for url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
|
||||
thumbnails.append({
|
||||
'url': url,
|
||||
**thumbnail_info
|
||||
})
|
||||
|
||||
return {
|
||||
'id': display_id,
|
||||
'formats': formats or [{
|
||||
'url': self._html_search_meta(['og:video'], webpage, fatal=True),
|
||||
'ext': 'mp4'
|
||||
}],
|
||||
'thumbnails': thumbnails or [{
|
||||
'url': self._html_search_meta(['og:image'], webpage, default=None)
|
||||
}],
|
||||
'title': self._html_search_meta(['og:title'], webpage, default=None),
|
||||
**traverse_obj(note_info, {
|
||||
'title': 'title',
|
||||
'description': 'desc',
|
||||
'tags': ('tagList', ..., 'name', {str}),
|
||||
'uploader_id': ('user', 'userId'),
|
||||
}),
|
||||
}
|
|
@ -1638,16 +1638,14 @@ def get_filesystem_encoding():
|
|||
return encoding if encoding is not None else 'utf-8'
|
||||
|
||||
|
||||
_WINDOWS_QUOTE_TRANS = str.maketrans({'"': '\\"', '\\': '\\\\'})
|
||||
_WINDOWS_QUOTE_TRANS = str.maketrans({'"': R'\"'})
|
||||
_CMD_QUOTE_TRANS = str.maketrans({
|
||||
# Keep quotes balanced by replacing them with `""` instead of `\\"`
|
||||
'"': '""',
|
||||
# Requires a variable `=` containing `"^\n\n"` (set in `utils.Popen`)
|
||||
# These require an env-variable `=` containing `"^\n\n"` (set in `utils.Popen`)
|
||||
# `=` should be unique since variables containing `=` cannot be set using cmd
|
||||
'\n': '%=%',
|
||||
# While we are only required to escape backslashes immediately before quotes,
|
||||
# we instead escape all of 'em anyways to be consistent
|
||||
'\\': '\\\\',
|
||||
'\r': '%=%',
|
||||
# Use zero length variable replacement so `%` doesn't get expanded
|
||||
# `cd` is always set as long as extensions are enabled (`/E:ON` in `utils.Popen`)
|
||||
'%': '%%cd:~,%',
|
||||
|
@ -1656,19 +1654,14 @@ _CMD_QUOTE_TRANS = str.maketrans({
|
|||
|
||||
def shell_quote(args, *, shell=False):
|
||||
args = list(variadic(args))
|
||||
if any(isinstance(item, bytes) for item in args):
|
||||
deprecation_warning('Passing bytes to utils.shell_quote is deprecated')
|
||||
encoding = get_filesystem_encoding()
|
||||
for index, item in enumerate(args):
|
||||
if isinstance(item, bytes):
|
||||
args[index] = item.decode(encoding)
|
||||
|
||||
if compat_os_name != 'nt':
|
||||
return shlex.join(args)
|
||||
|
||||
trans = _CMD_QUOTE_TRANS if shell else _WINDOWS_QUOTE_TRANS
|
||||
return ' '.join(
|
||||
s if re.fullmatch(r'[\w#$*\-+./:?@\\]+', s, re.ASCII) else s.translate(trans).join('""')
|
||||
s if re.fullmatch(r'[\w#$*\-+./:?@\\]+', s, re.ASCII)
|
||||
else re.sub(r'(\\+)("|$)', r'\1\1\2', s).translate(trans).join('""')
|
||||
for s in args)
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue