mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-23 09:01:43 +00:00
parent
0cb0fdbbfe
commit
941e881e1f
@ -108,6 +108,7 @@
|
|||||||
get_domain,
|
get_domain,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
iri_to_uri,
|
iri_to_uri,
|
||||||
|
is_path_like,
|
||||||
join_nonempty,
|
join_nonempty,
|
||||||
locked_file,
|
locked_file,
|
||||||
make_archive_id,
|
make_archive_id,
|
||||||
@ -725,7 +726,7 @@ def preload_download_archive(fn):
|
|||||||
archive = set()
|
archive = set()
|
||||||
if fn is None:
|
if fn is None:
|
||||||
return archive
|
return archive
|
||||||
elif not isinstance(fn, os.PathLike):
|
elif not is_path_like(fn):
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
self.write_debug(f'Loading archive file {fn!r}')
|
self.write_debug(f'Loading archive file {fn!r}')
|
||||||
|
@ -1497,6 +1497,10 @@ def https_open(self, req):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def is_path_like(f):
|
||||||
|
return isinstance(f, (str, bytes, os.PathLike))
|
||||||
|
|
||||||
|
|
||||||
class YoutubeDLCookieJar(http.cookiejar.MozillaCookieJar):
|
class YoutubeDLCookieJar(http.cookiejar.MozillaCookieJar):
|
||||||
"""
|
"""
|
||||||
See [1] for cookie file format.
|
See [1] for cookie file format.
|
||||||
@ -1515,7 +1519,7 @@ class YoutubeDLCookieJar(http.cookiejar.MozillaCookieJar):
|
|||||||
|
|
||||||
def __init__(self, filename=None, *args, **kwargs):
|
def __init__(self, filename=None, *args, **kwargs):
|
||||||
super().__init__(None, *args, **kwargs)
|
super().__init__(None, *args, **kwargs)
|
||||||
if self.is_path(filename):
|
if is_path_like(filename):
|
||||||
filename = os.fspath(filename)
|
filename = os.fspath(filename)
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
@ -1523,13 +1527,9 @@ def __init__(self, filename=None, *args, **kwargs):
|
|||||||
def _true_or_false(cndn):
|
def _true_or_false(cndn):
|
||||||
return 'TRUE' if cndn else 'FALSE'
|
return 'TRUE' if cndn else 'FALSE'
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_path(file):
|
|
||||||
return isinstance(file, (str, bytes, os.PathLike))
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def open(self, file, *, write=False):
|
def open(self, file, *, write=False):
|
||||||
if self.is_path(file):
|
if is_path_like(file):
|
||||||
with open(file, 'w' if write else 'r', encoding='utf-8') as f:
|
with open(file, 'w' if write else 'r', encoding='utf-8') as f:
|
||||||
yield f
|
yield f
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user