diff options
| -rw-r--r-- | TODO | 4 | ||||
| -rw-r--r-- | cue.py | 11 | ||||
| -rwxr-xr-x | cutter | 13 |
3 files changed, 21 insertions, 7 deletions
@@ -1,8 +1,8 @@ OK 1. convert file with a single track -2. search cue in specified dir if cutter's argument is dir +OK 2. search cue in specified dir if cutter's argument is dir OK 3. write tags to the splitted files OK 4. specify output file format including path OK 5. add support of config file with default options OK 6. copy file instead of convert if possible OK 7. substitute odd symbols in track names -8. add charset coding argument +OK 8. add charset coding argument @@ -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 @@ -135,6 +135,9 @@ def parse_args(): enc = OptionGroup(parser, "Encoding options") + enc.add_option("--coding", dest="coding", + help="encoding of original text") + enc.add_option("-d", "--dir", dest="dir", default=config.DIR, help="output directory") @@ -616,14 +619,20 @@ def main(): debug("use cue file %s", quote(cuepath)) try: - cue = read_cue(cuepath, on_error=on_error) + cue = read_cue(cuepath, options.coding, on_error=on_error) except StopIteration: return 1 except IOError as err: printerr("open %s: %s", err.filename, err.strerror) return 1 except Exception as err: - printerr("read_cue failed: %s: %s\n", err.__class__.__name__, err.filename) + msg = "%s (%s)" % (err, err.__class__.__name__) + + if hasattr(err, "filename"): + printerr("%s: %s: %s\n", err.filename, msg) + else: + printerr("%s\n", msg) + return 1 cue.dir = os.path.dirname(cuepath) |
