How to get an Audio-CD tracks count
The Problem
I want to add a new feature to serpentine: copy an audio-cd
I have found 5 solutions: sound juicer, cdrecord, musicbrainz, pygame and cddb.
sound juicer
One way of issuing sound juicer commands would be to do the following:
set the following gconf keys (located under /apps/sound-juicer)
audio_profile = cdlossless (voice gives a stupid error about gstreamer) eject = True base_path = /tmp device = /dev/cdrom file_pattern = %t path_pattern = ""
Then we should just:
sound-juicer -a- convert each track to wav
- remove the original .flacs
- write cd
- remove tracks
cdrecord
To get the number of tracks via cdrecord:
cdrecord -toc dev=/dev/cdrom 2> /dev/null | grep ^first:
musicbrainz
With musicbrainz, on ubuntu, MBE_TOCGetCDIndexID wasn't working,
probably because there wasn't ctypes installed
>>> import musicbrainz >>> mb = musicbrainz.mb () >>> mb.SetDepth (2) >>> q = musicbrainz >>> mb.Query (q.MBQ_GetCDTOC) >>> cdid = str (mb.GetResultData (q.MBE_TOCGetCDIndexID)) >>> mb.QueryWithArgs(q.MBQ_GetCDInfoFromCDIndexId, [cdid]) >>> mb.GetResultInt(q.MBE_GetNumAlbums) 1 >>> mb.Select1(q.MBS_SelectAlbum, 1) 1 >>> mb.GetResultInt(q.MBE_AlbumGetNumTracks) 12
pygame
Here's how to do it with PyGame:
>>> import pygame.cdrom >>> pygame.cdrom.init () >>> cd = pygame.cdrom.CD (0) >>> cd.init () >>> cd.get_numtracks () 12 >>> cd.get_id () 0 >>> cd.get_name () '/dev/cdrom'
CDDB
CDDB (the python module):
This is actually a set of three modules to access the CDDB and FreeDB online databases of audio CD track titles and information. It includes a C extension module to fetch track lengths under Linux, FreeBSD, OpenBSD, Mac OS X, Solaris, and Win32, which is easily ported to other operating systems.
>>> import DiscID >>> d = DiscID.open() >>> did = DiscID.disc_id (d) >>> did[1] 12
Conclusion
I think that CDDB is the most appropriate way of doing it, since it's a really lightweight dependency and should be available in all systems. It has a GPL, but there are already lots of GUI parts of serpentine that are GPL'ed (because of nautilusburn).
I would like for this feature to be implemented as a plugin, it would prove as a very good example on the possibilities and ways of doing plugins. It could also mean some refactoring, which is always good.
TODO
Find a way to dynamicaly add elements to the menu system.