[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] CDROM Module to calc a freeDB DiscID =?koi8-r?Q?=3F=3F=3F?=
From: genrich <Genrich@gmx.net>
To: pygame-users@seul.org
Date: Tue, 09 Nov 2004 18:10:04 +0100
Subject: [pygame] CDROM Module to calc a freeDB DiscID ???
>
> I try to generate the freeDB DiscID with the pygame CDROM Module...
>
> Here the Code:
>
> =======================================
>
> from pygame import cdrom
[snip]
The first thing I saw was you need lead in and lead out to calc it properly.
Here is how I do it:
# ---------------------------------------------------
def getDiskId( tracksInfo ):
"""
Returns disc id based on tracksInfo which is tuple of ( track_start, track_length )
"""
# check sum
def sumDigits( val ):
return int( reduce( lambda x, y: int( y )+ int( x ), str( val ) ) )
# check sum
checkSum= reduce( lambda x, y: x+ y, map( lambda x: sumDigits( int( x[ 0 ]/75 )), tracksInfo ) )
# total length
totalTime= reduce( lambda x, y: x+ y, map( lambda x: x[ 1 ], tracksInfo ) )
return ( ( long(checkSum % 0xff) << 24 ) + ( long( totalTime/75 ) << 8 ) + len( tracksInfo ) )
print getDiskId( [ ( cd.get_track_start( x ), cd.get_track_length( x ) ) for x in xrange( cd.get_numtracks() ) ] )
Dmitry/