From 2b17b8e912e6f003f2862675ec63f2e2eba5048c Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 1 Jun 2009 12:53:14 +0000 Subject: [PATCH] * morituri/program/cdparanoia.py: * morituri/rip/cd.py: Handle another off-by-one error in the m3u handling. Add a getTagList function. Use it to encode tags. --- ChangeLog | 8 +++++ morituri/program/cdparanoia.py | 9 ++++-- morituri/rip/cd.py | 54 ++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2cc186c..c0bb788 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-06-01 Thomas Vander Stichele + + * morituri/program/cdparanoia.py: + * morituri/rip/cd.py: + Handle another off-by-one error in the m3u handling. + Add a getTagList function. + Use it to encode tags. + 2009-06-01 Thomas Vander Stichele * morituri/common/encode.py: diff --git a/morituri/program/cdparanoia.py b/morituri/program/cdparanoia.py index b5726a1..b6601df 100644 --- a/morituri/program/cdparanoia.py +++ b/morituri/program/cdparanoia.py @@ -234,7 +234,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask): _tmpwavpath = None _tmppath = None - def __init__(self, path, table, start, stop, offset=0, device=None, profile=None): + def __init__(self, path, table, start, stop, offset=0, device=None, profile=None, taglist=None): """ @param path: where to store the ripped track @type path: str @@ -250,11 +250,15 @@ class ReadVerifyTrackTask(task.MultiSeparateTask): @type device: str @param profile: the encoding profile @type profile: L{encode.Profile} + @param taglist: a list of tags + @param taglist: L{gst.TagList} """ task.MultiSeparateTask.__init__(self) self.path = path + if taglist: + self.debug('read and verify with taglist %r', taglist) # FIXME: choose a dir on the same disk/dir as the final path fd, tmppath = tempfile.mkstemp(suffix='.morituri.wav') os.close(fd) @@ -273,7 +277,8 @@ class ReadVerifyTrackTask(task.MultiSeparateTask): profile.extension) os.close(fd) self._tmppath = tmpoutpath - self.tasks.append(encode.EncodeTask(tmppath, tmpoutpath, profile)) + self.tasks.append(encode.EncodeTask(tmppath, tmpoutpath, profile, + taglist=taglist)) # make sure our encoding is accurate self.tasks.append(checksum.CRC32Task(tmpoutpath)) diff --git a/morituri/rip/cd.py b/morituri/rip/cd.py index 1029b92..6b749d5 100644 --- a/morituri/rip/cd.py +++ b/morituri/rip/cd.py @@ -27,6 +27,8 @@ import math import gobject gobject.threads_init() +import gst + from morituri.common import logcommand, task, checksum, common, accurip from morituri.common import drive, encode from morituri.image import image, cue, table @@ -168,6 +170,49 @@ def getPath(outdir, template, metadata, i): return os.path.join(outdir, template % v) +def getTagList(metadata, i): + """ + Based on the metadata, get a gst.TagList for the given track. + + @param metadata: + @type metadata: L{DiscMetadata} + @param i: track number (0 for HTOA) + @type i: int + + @rtype: L{gst.TagList} + """ + artist = u'Unknown Artist' + disc = u'Unknown Disc' + title = u'Unknown Track' + + if metadata: + artist = metadata.artist + disc = metadata.title + if i > 0: + try: + artist = metadata.tracks[i - 1].artist + title = metadata.tracks[i - 1].title + except IndexError, e: + print 'ERROR: no track %d found, %r' % (i, e) + raise + else: + # htoa defaults to disc's artist + title = 'Hidden Track One Audio' + + ret = gst.TagList() + + # gst-python 0.10.15.1 does not handle unicode -> utf8 string conversion + # see http://bugzilla.gnome.org/show_bug.cgi?id=584445 + ret[gst.TAG_ARTIST] = artist.encode('utf-8') + ret[gst.TAG_TITLE] = title.encode('utf-8') + ret[gst.TAG_ALBUM] = disc.encode('utf-8') + ret[gst.TAG_TRACK_NUMBER] = i + ret[gst.TAG_TRACK_COUNT] = len(metadata.tracks) + + # FIXME: gst.TAG_ISRC + + return ret + class Rip(logcommand.LogCommand): summary = "rip CD" @@ -286,7 +331,8 @@ class Rip(logcommand.LogCommand): start, stop - 1, offset=int(self.options.offset), device=self.parentCommand.options.device, - profile=profile) + profile=profile, + taglist=getTagList(metadata, 0)) function(runner, t) if t.checksum is not None: @@ -321,7 +367,8 @@ class Rip(logcommand.LogCommand): ittoc.getTrackEnd(i + 1), offset=int(self.options.offset), device=self.parentCommand.options.device, - profile=profile) + profile=profile, + taglist=getTagList(metadata, i)) t.description = 'Reading Track %d' % (i + 1) function(runner, t) if t.checksum: @@ -358,7 +405,8 @@ class Rip(logcommand.LogCommand): handle.write('%s\n' % os.path.basename(htoapath)) for i, track in enumerate(itable.tracks): - path = getPath(outdir, self.options.track_template, metadata, i) + '.' + extension + path = getPath(outdir, self.options.track_template, metadata, + i + 1) + '.' + extension handle.write('#EXTINF:%d,%s\n' % ( itable.getTrackLength(i + 1) / common.FRAMES_PER_SECOND, os.path.basename(path)))