* morituri/image/image.py:

Add ImageEncodeTask to encode a disk image to a different profile
	  and directory.
	* morituri/common/encode.py:
	  Add lossy encoding profiles for mp3 and vorbis.
	  Rename muxer to tagger since that's what we use it for.
	  Do progress probe after level to make sure we get samples for
	  offsets.
	* morituri/rip/image.py:
	  Add rip image encode command.
This commit is contained in:
Thomas Vander Stichele
2009-10-17 13:53:58 +00:00
parent 13936a6f11
commit fe68f676c9
4 changed files with 165 additions and 17 deletions

View File

@@ -20,12 +20,76 @@
# You should have received a copy of the GNU General Public License
# along with morituri. If not, see <http://www.gnu.org/licenses/>.
import os
from morituri.common import logcommand, task, checksum, accurip, program
from morituri.common import encode
from morituri.image import image, cue
from morituri.result import result
from morituri.program import cdrdao, cdparanoia
class Encode(logcommand.LogCommand):
summary = "encode image"
def addOptions(self):
# FIXME: get from config
self.parser.add_option('-O', '--output-directory',
action="store", dest="output_directory",
help="output directory (defaults to current directory)")
default = 'vorbis'
self.parser.add_option('', '--profile',
action="store", dest="profile",
help="profile for encoding (default '%s', choices '%s')" % (
default, "', '".join(encode.ALL_PROFILES.keys())),
default=default)
def do(self, args):
prog = program.Program()
prog.outdir = (self.options.output_directory or os.getcwd())
prog.outdir = prog.outdir.decode('utf-8')
profile = encode.ALL_PROFILES[self.options.profile]()
runner = task.SyncRunner()
for arg in args:
arg = unicode(arg)
indir = os.path.dirname(arg)
cueImage = image.Image(arg)
cueImage.setup(runner)
# FIXME: find a decent way to get an album-specific outdir
root, ext = os.path.splitext(os.path.basename(indir))
outdir = os.path.join(prog.outdir, root)
try:
os.makedirs(outdir)
except:
# FIXME: handle other exceptions than OSError Errno 17
pass
# FIXME: handle this nicer
assert outdir != indir
taskk = image.ImageEncodeTask(cueImage, profile, outdir)
runner.run(taskk)
# FIXME: translate .m3u file if it exists
root, ext = os.path.splitext(arg)
m3upath = root + '.m3u'
if os.path.exists(m3upath):
self.debug('translating .m3u file')
inm3u = open(m3upath)
outm3u = open(os.path.join(outdir, os.path.basename(m3upath)),
'w')
for line in inm3u.readlines():
root, ext = os.path.splitext(line)
if ext:
# newline is swallowed by splitext here
outm3u.write('%s.%s\n' % (root, profile.extension))
else:
outm3u.write('%s' % root)
outm3u.close()
class Verify(logcommand.LogCommand):
summary = "verify image"
@@ -35,6 +99,7 @@ class Verify(logcommand.LogCommand):
cache = accurip.AccuCache()
for arg in args:
arg = unicode(arg)
cueImage = image.Image(arg)
cueImage.setup(runner)
@@ -56,4 +121,4 @@ class Verify(logcommand.LogCommand):
class Image(logcommand.LogCommand):
summary = "handle images"
subCommandClasses = [Verify, ]
subCommandClasses = [Encode, Verify, ]