Porównaj commity

...

15 Commity

Autor SHA1 Wiadomość Data
HobbyistDev 90d70f72d2
Merge eecd76dd92 into 64766459e3 2024-04-27 16:54:49 +08:00
Simon Sawicki 64766459e3
[core/windows] Improve shell quoting and tests (#9802)
Authored by: Grub4K
2024-04-27 10:37:26 +02:00
bashonly 89f535e265
[ci] Fix `curl-cffi` installation (Bugfix for 02483bea1c)
Authored by: bashonly
2024-04-22 20:36:01 +00:00
HobbyistDev eecd76dd92 pull out common thumbnail info 2024-04-12 21:32:01 +08:00
HobbyistDev 24e83cf661 pull the common formats info outside for second `for` loop 2024-04-12 21:30:08 +08:00
HobbyistDev bcda65fcc5 add `default=None` in fallback `thumbnails` 2024-04-11 22:03:02 +08:00
HobbyistDev 31c45e0dfd rename to `XiaoHongshu` 2024-04-11 21:34:13 +08:00
HobbyistDev 0b9fc25be6 remove `merge_dicts` import and cleanup 2024-04-11 21:32:36 +08:00
HobbyistDev 6c6ad3298d
Refactor the return result
Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com>
2024-04-11 21:29:54 +08:00
HobbyistDev c895dfea10 Add `md5` key in test 2024-04-11 21:24:28 +08:00
HobbyistDev 05648c4fe9
Change `name` to `initial_state`
Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com>
2024-04-11 21:18:12 +08:00
HobbyistDev 27a6f8330b add `IE_DESC` 2024-04-11 07:37:57 +08:00
HobbyistDev aa2dda16cd change name to `XiaoHongSu` 2024-04-11 07:35:27 +08:00
HobbyistDev 8f2567f048 remove `url` and `ext` from the return
Instead of set it in return, the extractor will extract the fallback formats if the `formats` length is 0
2024-04-08 21:28:03 +08:00
HobbyistDev 363f6b3029 [extractors/xiaohungsu] Add `XiaoHungSu` extractor 2024-04-08 21:13:02 +08:00
5 zmienionych plików z 120 dodań i 23 usunięć

Wyświetl plik

@ -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: |

Wyświetl plik

@ -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__':

Wyświetl plik

@ -2379,6 +2379,7 @@ from .xhamster import (
XHamsterEmbedIE,
XHamsterUserIE,
)
from .xiaohongshu import XiaoHongShuIE
from .ximalaya import (
XimalayaIE,
XimalayaAlbumIE

Wyświetl plik

@ -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'),
}),
}

Wyświetl plik

@ -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)