140278

And I'm finally getting around to ripping all of my CDs (again for a lot of them). Decided that 's idea of putting the discid as a comment tag on the ogg was a good one to make for easier retagging/renaming at a later date was a good idea.

I just wish I knew where I stashed away the scripts that I used to use for this. grip seems to be behaving a little bit better now than it used to, though, at least, and it was easier to set up quickly than rewriting my scripts.

3 thoughts on “140278”

  1. #!/usr/bin/python
    import fcntl, struct, os, string

    def get_toc(dev):
    CDROMREADTOCHDR=0x5305
    CDROMREADTOCENTRY=0x5306
    CDROM_MSF=0x02

    ioctlarg=’ ‘*1024
    val = fcntl.ioctl(dev,CDROMREADTOCHDR,ioctlarg)
    hdr = struct.unpack(‘BB’,val[:2])
    tracks = []
    for i in range(hdr[0],hdr[1]+1):
    tracks.append(i)
    tracks.append(0xAA)
    toc = []
    for track in tracks:
    ioctlarg = struct.pack(‘BBBBBBBBiB’,track, 0, CDROM_MSF,0,0,0,0,0,0,0)
    val = fcntl.ioctl(dev,CDROMREADTOCENTRY,ioctlarg)
    tocentry = struct.unpack(‘BBBBBBBBiB’, val)
    # print tocentry
    msf = {
    ‘track’ : tocentry[0],
    ‘minute’ : tocentry[4],
    ‘second’ : tocentry[5],# -2, # -2 to kludge for between-track gap
    ‘frame’ : tocentry[6]
    }
    toc.append(msf)
    return toc

    def cddb_sum(n):
    ret = 0
    while n > 0:
    ret = ret + (n % 10)
    n = n / 10
    return ret

    def seconds(msf):
    ret = (msf[‘minute’]*60) + msf[‘second’]
    return ret

    def frames(msf):
    return (msf[‘minute’]*60*75) +
    (msf[‘second’]*75) +
    (msf[‘frame’])

    def get_discinfo(toc):
    csum = 0
    t = 0
    length = 0
    trackinfo = []
    for entry in toc:
    if entry[‘track’] == 0xAA:
    t = seconds(entry) – seconds(toc[0])
    length = seconds(entry)
    else:
    trackinfo.append(frames(entry))
    csum = csum + cddb_sum(seconds(entry))
    discid = ((csum % 0xFF) << 24 | t << 8 | len(toc)-1)
    discinfo = {
    'discid' : discid,
    'tracks' : len(toc)-1,
    'trackinfo' : trackinfo,
    'length' : length,
    }
    return discinfo

    fd = os.open('/dev/scd0',os.O_RDONLY|os.O_NONBLOCK)
    toc = get_toc(fd)
    discinfo = get_discinfo(toc)
    tracklist = string.join(map(lambda a: "%d" % a, discinfo['trackinfo']),' ')
    track_info = "%(discid)08x %(tracks)d " % discinfo +
    tracklist +
    " %(length)s" % discinfo
    print track_info

  2. So, having been drinking, the above was clearly eligable to be a comment 🙂

    you can do “vorbiscomment -a DISCID=`./discid.py` in.ogg out.ogg” with that.

    Have I mentioned how much I hate python’s ioctl() routines, and how the output formats work? For fuck’s sakes, even perl does it better.

Comments are closed.