Skip to content

Commit

Permalink
Add tagging using mutagen.
Browse files Browse the repository at this point in the history
Replace the gstreamer tagging code with mutagen tagging code.
getTagList is rewritten to return a dictionary of tags, which are then simply
passed to mutagen.

The way it is set up right now is not the best - I don't think it makes sense
for tagging to take place in program/cdparanoia.py ; but this is how the current
code did it.

I suggest that, when we rip out all the gstreamer code, we also move the tagging
to a more sensible place; and then also make the tagging not be an actual
'task.Task'.
  • Loading branch information
MerlijnWajer committed Jan 30, 2017
1 parent cc3cbe5 commit ae9e87e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 46 deletions.
27 changes: 27 additions & 0 deletions morituri/common/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import shutil
import tempfile

from mutagen.flac import FLAC

from morituri.common import common
from morituri.common import gstreamer as cgstreamer
from morituri.common import task as ctask
Expand Down Expand Up @@ -200,6 +202,31 @@ def _flac_encode(self):
self.new_path = flac.encode(self.track_path, self.track_out_path)
self.stop()

# TODO: Wizzup: Do we really want this as 'Task'...?
# I only made it a task for now because that it's easier to integrate in
# program/cdparanoia.py - where morituri currently does the tagging.
# We should just move the tagging to a more sensible place.
class TaggingTask(task.Task):
description = 'Writing tags to FLAC'

def __init__(self, track_path, tags):
self.track_path = track_path
self.tags = tags

def start(self, runner):
task.Task.start(self, runner)
self.schedule(0.0, self._tag)

def _tag(self):
w = FLAC(self.track_path)

for k, v in self.tags.items():
w[k] = v

w.save()

self.stop()

class EncodeTask(ctask.GstPipelineTask):
"""
I am a task that encodes a .wav file.
Expand Down
63 changes: 17 additions & 46 deletions morituri/common/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,58 +450,29 @@ def getTagList(self, number):
# htoa defaults to disc's artist
title = 'Hidden Track One Audio'

# here to avoid import gst eating our options
import gst

ret = gst.TagList()
tags = {}

# gst-python 0.10.15.1 does not handle unicode -> utf8 string
# conversion
# see http://bugzilla.gnome.org/show_bug.cgi?id=584445
if self.metadata and not self.metadata.various:
ret["album-artist"] = albumArtist.encode('utf-8')
ret[gst.TAG_ARTIST] = trackArtist.encode('utf-8')
ret[gst.TAG_TITLE] = title.encode('utf-8')
ret[gst.TAG_ALBUM] = disc.encode('utf-8')

# 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] = number
tags['ALBUMARTIST'] = albumArtist.encode('utf-8')
tags['ARTIST'] = trackArtist.encode('utf-8')
tags['TITLE'] = title.encode('utf-8')
tags['DISC'] = disc.encode('utf-8')

tags['TRACKNUMBER'] = u'%s' % number

if self.metadata:
# works, but not sure we want this
# if gst.pygst_version >= (0, 10, 15):
# ret[gst.TAG_TRACK_COUNT] = len(self.metadata.tracks)
# hack to get a GstDate which we cannot instantiate directly in
# 0.10.15.1
# FIXME: The dates are strings and must have the format 'YYYY',
# 'YYYY-MM' or 'YYYY-MM-DD'.
# GstDate expects a full date, so default to
# Jan and 1st if MM and DD are missing
date = self.metadata.release
if date:
logger.debug('Converting release date %r to structure', date)
if len(date) == 4:
date += '-01'
if len(date) == 7:
date += '-01'

s = gst.structure_from_string('hi,date=(GstDate)%s' %
str(date))
ret[gst.TAG_DATE] = s['date']

# no musicbrainz info for htoa tracks
tags['DATE'] = self.metadata.release

if number > 0:
ret["musicbrainz-trackid"] = mbidTrack
ret["musicbrainz-artistid"] = mbidTrackArtist
ret["musicbrainz-albumid"] = mbidAlbum
ret["musicbrainz-albumartistid"] = mbidTrackAlbum
ret["musicbrainz-discid"] = mbDiscId
tags['musicbrainz-trackid'] = mbidTrack
tags['musicbrainz-artistid'] = mbidTrackArtist
tags['musicbrainz-albumid'] = mbidAlbum
tags['musicbrainz-albumartistid'] = mbidTrackAlbum
tags['musicbrainz-discid'] = mbDiscId

# FIXME: gst.TAG_ISRC
# TODO/FIXME: ISRC tag

return ret
return tags

def getHTOA(self):
"""
Expand Down
3 changes: 3 additions & 0 deletions morituri/program/cdparanoia.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ def __init__(self, path, table, start, stop, overread, offset=0,
self.tasks.append(checksum.CRC32Task(tmppath))
self.tasks.append(encode.SoxPeakTask(tmppath))

# TODO: Move tagging outside of cdparanoia
self.tasks.append(encode.TaggingTask(tmpoutpath, taglist))

self.checksum = None

def stop(self):
Expand Down

0 comments on commit ae9e87e

Please sign in to comment.