diff options
| author | mikeos <mike.osipov@gmail.com> | 2013-09-12 23:39:17 +0400 |
|---|---|---|
| committer | mikeos <mike.osipov@gmail.com> | 2013-09-12 23:39:17 +0400 |
| commit | 524948282b48867cdda2f43a512e872413752c32 (patch) | |
| tree | 640671bec53c894b98a6eafe513759f10d53ee7b /cue.py | |
| parent | c18fca9cfcd9aa333fd3f0d81c005f5e541243c5 (diff) | |
add charset coding argument
Diffstat (limited to 'cue.py')
| -rw-r--r-- | cue.py | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -291,11 +291,14 @@ class CueParser: previous = track -def __read_file(filename): +def __read_file(filename, coding = None): f = open(filename, "rb") data = f.read() f.close() + if coding: + return data.decode(coding) + encoded = None try: encoded = data.decode("utf-8-sig") @@ -311,10 +314,12 @@ def __read_file(filename): encoded = data.decode(encoding) except UnicodeDecodeError: raise Exception("autodetect failed: invalid encoding %s" % encoding) + except Exception as exc: + raise Exception("decoding failed: %s" % exc) return encoded -def read_cue(filename, on_error = None): +def read_cue(filename, coding = None, on_error = None): if on_error: def msg(fmt, *args): err = CueParserError(fmt % args) @@ -323,7 +328,7 @@ def read_cue(filename, on_error = None): else: msg = lambda *args: None - cuefile = __read_file(filename) + cuefile = __read_file(filename, coding) parser = CueParser() nline = 0 |
