Re: [LAU] ID3/Ogg metadata copying?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-audio-user@...>
Date: Thursday, October 25, 2007 - 3:38 am

Hey Ken, I've done something similar.
The python libraries I ended up using were:

In one of my scripts, I have some code that might be a useful starting
point, though taken out of context it will surely need some fixing

def tag_all(self):
Tag all mp3 files in mp3dir with info from the corresponding
artist, title = self.artist, self.title
mp3files = sorted(glob.glob(self.mp3dir + '/*mp3'))
oggfiles = sorted(glob.glob(self.oggdir + '/*ogg'))
self.log("Tagging %d files." % len(oggfiles))
assert len(oggfiles) == len(mp3files)
files = zip(oggfiles, mp3files)

for i, t in enumerate(files):
oggpath, mp3path = t
self.comment_to_id3(i, len(files), oggpath, mp3path)

def comment_to_id3(self, n, ntracks, oggpath, mp3path):
# XXX note we could also have just used lame command line options
# to insert the tag during encoding. Oh well, this works.
oggfile = ogg.vorbis.VorbisFile(oggpath)
comment = oggfile.comment().as_dict()
mp3tag = pyid3lib.tag(mp3path)

def _get(key, default=''):
# Helper for getting single ascii strings out of weird
# comments, and cleaning up fallback values that may be
# filenames.
value = comment.get(key)
if value == None:
value = [default.replace('_', ' ')]
value = value[0].encode('ascii', 'ignore')
return value

#mp3tag.genre = _get('GENRE') #id3v2 has given up on genre, it was dumb
mp3tag.artist = _get('ARTIST', self.artist)
mp3tag.album = _get('ALBUM', self.title)
default_name = os.path.basename(oggpath)[:-4]
mp3tag.title = _get('TITLE', default_name) = _get('DATE')
tracknumber = _get('TRACKNUMBER', '%d/%d' % (n + 1, ntracks))
tracknumber = [int(i) for i in tracknumber.split('/')]
mp3tag.track = tuple(tracknumber)


Paul Winkler

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[LAU] ID3/Ogg metadata copying?, Ken Restivo, (Wed Oct 24, 11:14 pm)
Re: [LAU] ID3/Ogg metadata copying?, Paul Winkler, (Thu Oct 25, 3:38 am)