mirror of https://github.com/yt-dlp/yt-dlp.git
Compare commits
4 Commits
0ac82a8158
...
e3a19a120b
Author | SHA1 | Date |
---|---|---|
sky-cake | e3a19a120b | |
Simon Sawicki | 64766459e3 | |
sky-cake | 43655bc01b | |
sky-cake | c937925afc |
|
@ -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__':
|
||||
|
|
|
@ -138,12 +138,13 @@ class PornHubIE(PornHubBaseIE):
|
|||
_EMBED_REGEX = [r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub(?:premium)?\.(?:com|net|org)/embed/[\da-z]+)']
|
||||
_TESTS = [{
|
||||
'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
|
||||
'md5': 'a6391306d050e4547f62b3f485dd9ba9',
|
||||
'md5': '4d4a4e9178b655776f86cf89ecaf0edf',
|
||||
'info_dict': {
|
||||
'id': '648719015',
|
||||
'ext': 'mp4',
|
||||
'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
|
||||
'uploader': 'Babes',
|
||||
'uploader_id': str,
|
||||
'uploader': 'BABES-COM',
|
||||
'upload_date': '20130628',
|
||||
'timestamp': 1372447216,
|
||||
'duration': 361,
|
||||
|
@ -155,6 +156,8 @@ class PornHubIE(PornHubBaseIE):
|
|||
'tags': list,
|
||||
'categories': list,
|
||||
'cast': list,
|
||||
'thumbnail': str,
|
||||
'production': list,
|
||||
},
|
||||
}, {
|
||||
# non-ASCII title
|
||||
|
@ -208,11 +211,23 @@ class PornHubIE(PornHubBaseIE):
|
|||
'url': 'http://www.pornhub.com/view_video.php?viewkey=ph601dc30bae19a',
|
||||
'info_dict': {
|
||||
'id': 'ph601dc30bae19a',
|
||||
'ext': 'mp4',
|
||||
'uploader': 'Projekt Melody',
|
||||
'uploader_id': 'projekt-melody',
|
||||
'upload_date': '20210205',
|
||||
'title': '"Welcome to My Pussy Mansion" - CB Stream (02/03/21)',
|
||||
'thumbnail': r're:https?://.+',
|
||||
'duration': 8173,
|
||||
'timestamp': 1612564932,
|
||||
'age_limit': 18,
|
||||
'tags': list,
|
||||
'like_count': int,
|
||||
'view_count': int,
|
||||
'categories': list,
|
||||
'dislike_count': int,
|
||||
'production': list,
|
||||
'cast': list,
|
||||
'comment_count': int,
|
||||
},
|
||||
}, {
|
||||
'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
|
||||
|
@ -263,7 +278,33 @@ class PornHubIE(PornHubBaseIE):
|
|||
}, {
|
||||
'url': 'http://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/view_video.php?viewkey=ph5a9813bfa7156',
|
||||
'only_matching': True,
|
||||
}]
|
||||
}, {
|
||||
# language spoken, model attributes, production
|
||||
'url': 'https://www.pornhub.com/view_video.php?viewkey=65a6ca42725f2',
|
||||
'info_dict': {
|
||||
'id': '65a6ca42725f2',
|
||||
'ext': 'mp4',
|
||||
'title': 'Busty blonde sucks the juice out of me',
|
||||
'uploader_id': 'egon-kowalski',
|
||||
'cast': [],
|
||||
'thumbnail': 'https://ei.phncdn.com/videos/202401/16/446618441/thumbs_14/(m=eaAaGwObaaaa)(mh=dIONqa8IT3Sw1RqL)5.jpg',
|
||||
'uploader': 'Egon Kowalski',
|
||||
'upload_date': '20240116',
|
||||
'timestamp': 1705429963,
|
||||
'duration': 358,
|
||||
'view_count': int,
|
||||
'like_count': int,
|
||||
'dislike_count': int,
|
||||
'comment_count': int,
|
||||
'age_limit': 18,
|
||||
'tags': list,
|
||||
'categories': list,
|
||||
'language_spoken': ['german'],
|
||||
'model_attributes': ['tattoos', 'white', 'no piercing'],
|
||||
'production': ['homemade'],
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
def _extract_count(self, pattern, webpage, name):
|
||||
return str_to_int(self._search_regex(pattern, webpage, '%s count' % name, default=None))
|
||||
|
@ -488,6 +529,15 @@ class PornHubIE(PornHubBaseIE):
|
|||
if div:
|
||||
return [clean_html(x).strip() for x in re.findall(r'(?s)<a[^>]+\bhref=[^>]+>.+?</a>', div)]
|
||||
|
||||
def get_model_attributes():
|
||||
model_attributes = re.findall(
|
||||
r'<a[^>]*\bdata-label=["\']model_attributes["\'][^>]*>(.*?)<\/a>',
|
||||
webpage,
|
||||
re.DOTALL)
|
||||
|
||||
if model_attributes:
|
||||
return [x.strip().lower() for x in model_attributes]
|
||||
|
||||
info = self._search_json_ld(webpage, video_id, default={})
|
||||
# description provided in JSON-LD is irrelevant
|
||||
info['description'] = None
|
||||
|
@ -509,6 +559,9 @@ class PornHubIE(PornHubBaseIE):
|
|||
'tags': extract_list('tags'),
|
||||
'categories': extract_list('categories'),
|
||||
'cast': extract_list('pornstars'),
|
||||
'production': extract_list('production'),
|
||||
'language_spoken': extract_list('langSpoken'),
|
||||
'model_attributes': get_model_attributes(),
|
||||
'subtitles': subtitles,
|
||||
}, info)
|
||||
|
||||
|
|
|
@ -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