summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormikeos <mike.osipov@gmail.com>2013-07-21 12:54:38 +0400
committermikeos <mike.osipov@gmail.com>2013-07-21 12:54:38 +0400
commit2d2e3af0eb38218105a2514cbc806d270bf06d12 (patch)
tree69e044cecc045ab277a94f7beeae5f84beba1789
parentf122a7c9145a9ed61def2953f7579e5aeb9c3529 (diff)
copy file instead of convert if possible
-rw-r--r--TODO2
-rwxr-xr-xcutter38
-rw-r--r--utils.py2
3 files changed, 39 insertions, 3 deletions
diff --git a/TODO b/TODO
index 04dc14f..d5d61aa 100644
--- a/TODO
+++ b/TODO
@@ -3,4 +3,4 @@ OK 1. convert file with a single track
3. write tags to the splitted files
4. specify output file format including path
OK 5. add support of config file with default options
-6. copy file instead of convert if possible
+OK 6. copy file instead of convert if possible
diff --git a/cutter b/cutter
index f0f618e..0f23f18 100755
--- a/cutter
+++ b/cutter
@@ -6,6 +6,7 @@ from cue import read_cue
from optparse import OptionParser, OptionGroup
from subprocess import Popen, PIPE
from tempfile import mkdtemp
+from shutil import copyfile
import sys
import os
@@ -84,7 +85,8 @@ def print_cue(cue):
if not info:
printf(": unknown type\n")
else:
- printf(" (%d/%d, %d ch)\n",
+ printf(" [%s] (%d/%d, %d ch)\n",
+ info.type,
info.bits_per_sample,
info.sample_rate,
info.channels)
@@ -220,6 +222,8 @@ class StreamInfo:
attr = StreamInfo.__mapping.get(data[0])
if attr:
setattr(info, attr, int(data[1]))
+ elif line.startswith(b"Handled by:"):
+ info.type = to_unicode(data[2])
if proc.wait():
return None
@@ -290,7 +294,37 @@ class CueSplitter:
return "%02d.%s.flac" % (self.tracknumber, title)
def copy_file(self, file):
- return False
+ noteq = lambda a, b: a and a !=b
+
+ if file.info.type != "flac":
+ return False
+ if noteq(self.opt.sample_rate, file.info.sample_rate):
+ return False
+ if noteq(self.opt.bits_per_sample, file.info.bits_per_sample):
+ return False
+ if noteq(self.opt.channels, file.info.channels):
+ return False
+
+ track = list(file.tracks(True))[0]
+ trackname = self.get_track_name(track)
+ dest = os.path.join(self.opt.dir, trackname)
+
+ if self.opt.dry_run:
+ printf("Copy [%s] --> [%s]\n", file.name, dest)
+ return True
+
+ printf("Copy [%s] --> [%s] : ", file.name, dest)
+ sys.stdout.flush()
+
+ try:
+ copyfile(file.name, dest)
+ except Exception as err:
+ printf("FAILED: %s\n", err)
+ sys.exit(1)
+ else:
+ printf("OK\n")
+
+ return True
def convert_file(self, file):
track = list(file.tracks(True))[0]
diff --git a/utils.py b/utils.py
index 9715e5d..b911630 100644
--- a/utils.py
+++ b/utils.py
@@ -32,6 +32,8 @@ else:
return False
def to_unicode(buf):
+ if type(buf) is bytes:
+ return buf.decode("utf-8")
return buf
def to_bytes(buf):