Skip to content

Commit

Permalink
Fix Unicode strings processing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeLametta committed Oct 22, 2018
1 parent fd9296f commit ce212cb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions whipper/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os.path
import math
import subprocess
import unicodedata

from whipper.extern import asyncsub

Expand Down Expand Up @@ -156,13 +157,15 @@ class MissingFrames(Exception):
def truncate_filename(path):
"""
Truncate filename to the max. len. allowed by the path's filesystem
Should handle unicode correctly too
Hopefully it handles Unicode strings correctly
"""
p, f = os.path.split(os.path.normpath(path))
f, e = os.path.splitext(f)
fn_lim = os.pathconf(p, 'PC_NAME_MAX')
length = fn_lim - len(e)
return os.path.join(p, f[:length] + e)
fn_lim = os.pathconf(p, 'PC_NAME_MAX') # max filenmae length in bytes
max = fn_lim - len(e.encode('utf-8'))
f = unicodedata.normalize('NFC', f)
f_trunc = unicode(f.encode('utf-8')[:max], 'utf-8', errors='ignore')
return os.path.join(p, f_trunc + e)


def shrinkPath(path):
Expand Down

0 comments on commit ce212cb

Please sign in to comment.