1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 17:22:31 +01:00

[cache] Fix writing to paths with unicode characters

* Use "compat_getenv"
* "write_json_file" now expects the filename to be a string
This commit is contained in:
Jaime Marquínez Ferrándiz 2014-11-18 23:28:42 +01:00
parent 37eddd3143
commit 92120217eb
3 changed files with 4 additions and 3 deletions

View File

@ -1001,7 +1001,7 @@ def process_info(self, info_dict):
else: else:
self.to_screen('[info] Writing video description metadata as JSON to: ' + infofn) self.to_screen('[info] Writing video description metadata as JSON to: ' + infofn)
try: try:
write_json_file(info_dict, encodeFilename(infofn)) write_json_file(info_dict, infofn)
except (OSError, IOError): except (OSError, IOError):
self.report_error('Cannot write metadata to JSON file ' + infofn) self.report_error('Cannot write metadata to JSON file ' + infofn)
return return

View File

@ -8,7 +8,7 @@
import shutil import shutil
import traceback import traceback
from .compat import compat_expanduser from .compat import compat_expanduser, compat_getenv
from .utils import write_json_file from .utils import write_json_file
@ -19,7 +19,7 @@ def __init__(self, ydl):
def _get_root_dir(self): def _get_root_dir(self):
res = self._ydl.params.get('cachedir') res = self._ydl.params.get('cachedir')
if res is None: if res is None:
cache_root = os.environ.get('XDG_CACHE_HOME', '~/.cache') cache_root = compat_getenv('XDG_CACHE_HOME', '~/.cache')
res = os.path.join(cache_root, 'youtube-dl') res = os.path.join(cache_root, 'youtube-dl')
return compat_expanduser(res) return compat_expanduser(res)

View File

@ -73,6 +73,7 @@ def preferredencoding():
def write_json_file(obj, fn): def write_json_file(obj, fn):
""" Encode obj as JSON and write it to fn, atomically """ """ Encode obj as JSON and write it to fn, atomically """
fn = encodeFilename(fn)
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
encoding = get_filesystem_encoding() encoding = get_filesystem_encoding()
# os.path.basename returns a bytes object, but NamedTemporaryFile # os.path.basename returns a bytes object, but NamedTemporaryFile