mirror of https://github.com/yt-dlp/yt-dlp.git
Compare commits
9 Commits
d08efa800d
...
2002d3990d
Author | SHA1 | Date |
---|---|---|
HobbyistDev | 2002d3990d | |
Simon Sawicki | 64766459e3 | |
HobbyistDev | 4741aded6f | |
HobbyistDev | d493ce72b6 | |
HobbyistDev | f326e05e9f | |
HobbyistDev | 89cb7f7d98 | |
HobbyistDev | 08563a1cad | |
HobbyistDev | 6c311b14c6 | |
HobbyistDev | eb2969d324 |
|
@ -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__':
|
||||
|
|
|
@ -713,6 +713,7 @@ from .globo import (
|
|||
from .gmanetwork import GMANetworkVideoIE
|
||||
from .go import GoIE
|
||||
from .godtube import GodTubeIE
|
||||
from .godresource import GodResourceIE
|
||||
from .gofile import GofileIE
|
||||
from .golem import GolemIE
|
||||
from .goodgame import GoodGameIE
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
determine_ext,
|
||||
str_or_none,
|
||||
unified_timestamp,
|
||||
url_or_none
|
||||
)
|
||||
from ..utils.traversal import traverse_obj
|
||||
|
||||
|
||||
class GodResourceIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://new\.godresource\.com/video/(?P<id>\w+)'
|
||||
_TESTS = [{
|
||||
# hls stream
|
||||
'url': 'https://new.godresource.com/video/A01mTKjyf6w',
|
||||
'info_dict': {
|
||||
'id': 'A01mTKjyf6w',
|
||||
'ext': 'mp4',
|
||||
'view_count': int,
|
||||
'timestamp': 1710978666,
|
||||
'channel_id': '5',
|
||||
'thumbnail': 'https://cdn-02.godresource.com/e42968ac-9e8b-4231-ab86-f4f9d775841f/thumbnail.jpg',
|
||||
'channel': 'Stedfast Baptist Church',
|
||||
'upload_date': '20240320',
|
||||
'title': 'GodResource video #A01mTKjyf6w',
|
||||
}
|
||||
}, {
|
||||
# mp4 link
|
||||
'url': 'https://new.godresource.com/video/01DXmBbQv_X',
|
||||
'md5': '0e8f72aa89a106b9d5c011ba6f8717b7',
|
||||
'info_dict': {
|
||||
'id': '01DXmBbQv_X',
|
||||
'ext': 'mp4',
|
||||
'channel_id': '12',
|
||||
'view_count': int,
|
||||
'timestamp': 1687996800,
|
||||
'thumbnail': 'https://cdn-02.godresource.com/sodomitedeception/thumbnail.jpg',
|
||||
'channel': 'Documentaries',
|
||||
'title': 'The Sodomite Deception',
|
||||
'upload_date': '20230629',
|
||||
}
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id = self._match_id(url)
|
||||
|
||||
api_data = self._download_json(
|
||||
f'https://api.godresource.com/api/Streams/{display_id}', display_id)
|
||||
|
||||
video_url = api_data['streamUrl']
|
||||
if (ext := determine_ext(video_url)) == 'm3u8':
|
||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
||||
api_data['streamUrl'], display_id)
|
||||
elif ext == 'mp4':
|
||||
formats, subtitles = [{
|
||||
'url': video_url,
|
||||
'ext': ext
|
||||
}], {}
|
||||
else:
|
||||
raise ExtractorError(f'Unexpected video format {ext}')
|
||||
|
||||
return {
|
||||
'id': display_id,
|
||||
'formats': formats,
|
||||
'subtitles': subtitles,
|
||||
'title': '',
|
||||
**traverse_obj(api_data, {
|
||||
'title': ('title', {str}),
|
||||
'thumbnail': ('thumbnail', {url_or_none}),
|
||||
'view_count': ('views', {int}),
|
||||
'channel': ('channelName', {str}),
|
||||
'channel_id': ('channelId', {str_or_none}),
|
||||
'timestamp': ('streamDateCreated', {unified_timestamp}),
|
||||
'modified_timestamp': ('streamDataModified', {unified_timestamp})
|
||||
})
|
||||
}
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue