|
|
@ -1439,6 +1439,26 @@ class YoutubeDLCookieJar(compat_cookiejar.MozillaCookieJar):
|
|
|
|
'CookieFileEntry',
|
|
|
|
'CookieFileEntry',
|
|
|
|
('domain_name', 'include_subdomains', 'path', 'https_only', 'expires_at', 'name', 'value'))
|
|
|
|
('domain_name', 'include_subdomains', 'path', 'https_only', 'expires_at', 'name', 'value'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, filename=None, *args, **kwargs):
|
|
|
|
|
|
|
|
super().__init__(None, *args, **kwargs)
|
|
|
|
|
|
|
|
if self.is_path(filename):
|
|
|
|
|
|
|
|
filename = os.fspath(filename)
|
|
|
|
|
|
|
|
self.filename = filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def is_path(file):
|
|
|
|
|
|
|
|
return isinstance(file, (str, bytes, os.PathLike))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
|
|
|
|
def open(self, file, *, write=False):
|
|
|
|
|
|
|
|
if self.is_path(file):
|
|
|
|
|
|
|
|
with open(file, 'w' if write else 'r', encoding='utf-8') as f:
|
|
|
|
|
|
|
|
yield f
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if write:
|
|
|
|
|
|
|
|
file.truncate(0)
|
|
|
|
|
|
|
|
yield file
|
|
|
|
|
|
|
|
|
|
|
|
def save(self, filename=None, ignore_discard=False, ignore_expires=False):
|
|
|
|
def save(self, filename=None, ignore_discard=False, ignore_expires=False):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Save cookies to a file.
|
|
|
|
Save cookies to a file.
|
|
|
@ -1458,7 +1478,7 @@ class YoutubeDLCookieJar(compat_cookiejar.MozillaCookieJar):
|
|
|
|
if cookie.expires is None:
|
|
|
|
if cookie.expires is None:
|
|
|
|
cookie.expires = 0
|
|
|
|
cookie.expires = 0
|
|
|
|
|
|
|
|
|
|
|
|
with open(filename, 'w', encoding='utf-8') as f:
|
|
|
|
with self.open(filename, write=True) as f:
|
|
|
|
f.write(self._HEADER)
|
|
|
|
f.write(self._HEADER)
|
|
|
|
now = time.time()
|
|
|
|
now = time.time()
|
|
|
|
for cookie in self:
|
|
|
|
for cookie in self:
|
|
|
@ -1514,7 +1534,7 @@ class YoutubeDLCookieJar(compat_cookiejar.MozillaCookieJar):
|
|
|
|
return line
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
|
|
|
cf = io.StringIO()
|
|
|
|
cf = io.StringIO()
|
|
|
|
with open(filename, encoding='utf-8') as f:
|
|
|
|
with self.open(filename) as f:
|
|
|
|
for line in f:
|
|
|
|
for line in f:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
cf.write(prepare_line(line))
|
|
|
|
cf.write(prepare_line(line))
|
|
|
|