From 192d0739c52c037373b6372f15a216e858a9fab0 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 1 Jun 2009 22:42:32 +0000 Subject: [PATCH] * morituri/common/encode.py: Add a test() method to the profile so we can warn about bad flacenc versions. Encode track number and count, and release date, if possible. * morituri/rip/cd.py: Fix another off-by-one error in the tag encoding. --- ChangeLog | 9 +++++++++ morituri/common/encode.py | 25 +++++++++++++++++++++++++ morituri/rip/cd.py | 28 +++++++++++++++++++++++----- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0bb788..c8f73ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-06-02 Thomas Vander Stichele + + * morituri/common/encode.py: + Add a test() method to the profile so we can warn about bad + flacenc versions. + Encode track number and count, and release date, if possible. + * morituri/rip/cd.py: + Fix another off-by-one error in the tag encoding. + 2009-06-01 Thomas Vander Stichele * morituri/program/cdparanoia.py: diff --git a/morituri/common/encode.py b/morituri/common/encode.py index b8f2466..c326bbd 100644 --- a/morituri/common/encode.py +++ b/morituri/common/encode.py @@ -37,11 +37,34 @@ class Profile(object): extension = None pipeline = None + def test(self): + """ + Test if this profile will work. + Can check for elements, ... + """ + pass + class FlacProfile(Profile): name = 'flac' extension = 'flac' pipeline = 'flacenc name=muxer quality=8' + # FIXME: we should do something better than just printing ERRORS + def test(self): + plugin = gst.registry_get_default().find_plugin('flac') + if not plugin: + print 'ERROR: cannot find flac plugin' + return False + + versionTuple = tuple([int(x) for x in plugin.get_version().split('.')]) + if len(versionTuple) < 4: + versionTuple = versionTuple + (0, ) + if versionTuple > (0, 10, 9, 0) and versionTuple <= (0, 10, 15, 0): + print 'ERROR: flacenc between 0.10.9 and 0.10.15 has a bug' + return False + + return True + class AlacProfile(Profile): name = 'alac' extension = 'alac' @@ -92,6 +115,8 @@ class EncodeTask(task.Task): self._peakdB = None self._profile = profile + self._profile.test() + def start(self, runner): task.Task.start(self, runner) self._pipeline = gst.parse_launch(''' diff --git a/morituri/rip/cd.py b/morituri/rip/cd.py index 6b749d5..f0f637a 100644 --- a/morituri/rip/cd.py +++ b/morituri/rip/cd.py @@ -39,10 +39,15 @@ class TrackMetadata(object): title = None class DiscMetadata(object): + """ + @param release: earliest release date, in YYYY-MM-DD + @type release: unicode + """ artist = None title = None various = False tracks = None + release = None def __init__(self): self.tracks = [] @@ -107,6 +112,7 @@ def musicbrainz(discid): metadata.various = not isSingleArtist metadata.title = release.title metadata.artist = release.artist.getUniqueName() + metadata.release = release.getEarliestReleaseDate() print "%s - %s" % (release.artist.getUniqueName(), release.title) @@ -206,9 +212,21 @@ def getTagList(metadata, i): 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) - + + # gst-python 0.10.15.1 does not handle tags that are UINT + # see gst-python commit 26fa6dd184a8d6d103eaddf5f12bd7e5144413fb + # FIXME: no way to compare against 'master' version after 0.10.15 + if gst.pygst_version >= (0, 10, 15): + ret[gst.TAG_TRACK_NUMBER] = i + if metadata: + if gst.pygst_version >= (0, 10, 15): + ret[gst.TAG_TRACK_COUNT] = len(metadata.tracks) + # hack to get a GstDate which we cannot instantiate directly in + # 0.10.15.1 + s = gst.structure_from_string('hi,date=(GstDate)%s' % + str(metadata.release)) + ret[gst.TAG_DATE] = s['date'] + # FIXME: gst.TAG_ISRC return ret @@ -301,7 +319,7 @@ class Rip(logcommand.LogCommand): itable.getAccurateRipURL(), ittoc.getAccurateRipURL()) outdir = self.options.output_directory or os.getcwd() - profile = encode.PROFILES[self.options.profile] + profile = encode.PROFILES[self.options.profile]() extension = profile.extension # check for hidden track one audio @@ -368,7 +386,7 @@ class Rip(logcommand.LogCommand): offset=int(self.options.offset), device=self.parentCommand.options.device, profile=profile, - taglist=getTagList(metadata, i)) + taglist=getTagList(metadata, i + 1)) t.description = 'Reading Track %d' % (i + 1) function(runner, t) if t.checksum: