Fix for unicode filenames

Fix for the issue discussed here:
https://github.com/rg3/youtube-dl/issues/4787
https://github.com/rg3/youtube-dl/issues/4787 by hashing the input and
output filenames before processing them and then restoring them.
This commit is contained in:
maleficarium 2015-05-03 07:11:05 +03:00
parent 963aea5279
commit 21aa58a2f1
3 changed files with 22 additions and 5 deletions

View File

@ -570,8 +570,8 @@ class YoutubeDL(object):
# Temporary fix for #4787
# 'Treat' all problem characters by passing filename through preferredencoding
# to workaround encoding issues with subprocess on python2 @ Windows
if sys.version_info < (3, 0) and sys.platform == 'win32':
filename = encodeFilename(filename, True).decode(preferredencoding())
#if sys.version_info < (3, 0) and sys.platform == 'win32':
# filename = encodeFilename(filename, True).decode(preferredencoding())
return filename
except ValueError as err:
self.report_error('Error in output template: ' + str(err) + ' (encoding: ' + repr(preferredencoding()) + ')')

View File

@ -4,7 +4,7 @@ import io
import os
import subprocess
import time
import hashNames
from .common import AudioConversionError, PostProcessor
@ -131,12 +131,17 @@ class FFmpegPostProcessor(PostProcessor):
os.stat(encodeFilename(path)).st_mtime for path in input_paths)
files_cmd = []
original_names = []
for path in input_paths:
files_cmd.extend([encodeArgument('-i'), encodeFilename(path, True)])
hashed_path = hashNames.hashRename(path)
os.rename(path, hashed_path)
original_names.append([hashed_path, path])
files_cmd.extend([encodeArgument('-i'), encodeFilename(hashed_path, True)])
hashed_out_path = hashNames.hashRename(out_path)
cmd = ([encodeFilename(self.executable, True), encodeArgument('-y')] +
files_cmd +
[encodeArgument(o) for o in opts] +
[encodeFilename(self._ffmpeg_filename_argument(out_path), True)])
[encodeFilename(self._ffmpeg_filename_argument(hashed_out_path), True)])
if self._downloader.params.get('verbose', False):
self._downloader.to_screen('[debug] ffmpeg command line: %s' % shell_quote(cmd))
@ -146,6 +151,9 @@ class FFmpegPostProcessor(PostProcessor):
stderr = stderr.decode('utf-8', 'replace')
msg = stderr.strip().split('\n')[-1]
raise FFmpegPostProcessorError(msg)
for o_name in original_names:
os.rename(o_name[0], o_name[1])
os.rename(hashed_out_path, out_path)
self.try_utime(out_path, oldest_mtime, oldest_mtime)
def run_ffmpeg(self, path, out_path, opts):

View File

@ -0,0 +1,9 @@
import os
import hashlib
#Hash the file names to drop unicode characters for FFMPEG
def hashRename(fileN):
ext = os.path.splitext(fileN)
fileHash = hashlib.sha224(fileN.encode('utf-8')).hexdigest()
hash_name = fileHash+ext[1]
return hash_name