From 524948282b48867cdda2f43a512e872413752c32 Mon Sep 17 00:00:00 2001 From: mikeos Date: Thu, 12 Sep 2013 23:39:17 +0400 Subject: add charset coding argument --- cue.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'cue.py') diff --git a/cue.py b/cue.py index 623aacd..7967d82 100644 --- a/cue.py +++ b/cue.py @@ -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 -- cgit v1.2.3-70-g09d2