summaryrefslogtreecommitdiff
path: root/cue.py
diff options
context:
space:
mode:
authormikeos <mike.osipov@gmail.com>2013-09-12 23:39:17 +0400
committermikeos <mike.osipov@gmail.com>2013-09-12 23:39:17 +0400
commit524948282b48867cdda2f43a512e872413752c32 (patch)
tree640671bec53c894b98a6eafe513759f10d53ee7b /cue.py
parentc18fca9cfcd9aa333fd3f0d81c005f5e541243c5 (diff)
add charset coding argument
Diffstat (limited to 'cue.py')
-rw-r--r--cue.py11
1 files changed, 8 insertions, 3 deletions
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