Skip to content

Commit

Permalink
Fix processing files with unicode names
Browse files Browse the repository at this point in the history
This only works in Py3, Py2 is still broken, see:
<https://bugs.python.org/issue1759845>.
  • Loading branch information
Kagami committed Oct 27, 2017
1 parent 1a276d7 commit 56c2e25
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions webm.py
Expand Up @@ -116,20 +116,22 @@ def _ffmpeg_output(args, check_code=True, debug=False):
try:
p = subprocess.Popen(
args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
stderr=subprocess.PIPE)
except Exception as exc:
raise Exception('failed to run FFmpeg ({})'.format(exc))
# These are bytes in both Py2 and 3.
out, err = p.communicate()
if check_code and p.returncode != 0:
raise Exception('FFmpeg exited with error')
if _PY2:
out = out.decode(OS_ENCODING)
# XXX: Error might occur if video file has corrupted/wrong
# encoding of metadata. Note that you need to use py2 in order
# to get effect of this, ``Popen(universal_newlines=True)`` on
# py3 always returns unicode.
err = err.decode(OS_ENCODING, 'ignore')

# NOTE(Kagami): Always use UTF-8 because it's what FFmpeg uses, at
# least on Windows. Let's ignore non-UTF8 nix systems for now.
out = out.decode('utf-8', 'ignore')
err = err.decode('utf-8', 'ignore')
# Fix for Windows newlines.
out = out.replace('\r\n', '\n')
err = err.replace('\r\n', '\n')

return {'stdout': out, 'stderr': err, 'code': p.returncode}


Expand Down

0 comments on commit 56c2e25

Please sign in to comment.