[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] CDROM Module to calc a freeDB DiscID ???
- To: pygame-users@seul.org
- Subject: [pygame] CDROM Module to calc a freeDB DiscID ???
- From: genrich <Genrich@gmx.net>
- Date: Tue, 09 Nov 2004 18:10:04 +0100
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Tue, 09 Nov 2004 12:10:57 -0500
- Reply-to: pygame-users@seul.org
- Sender: owner-pygame-users@seul.org
- User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)
I try to generate the freeDB DiscID with the pygame CDROM Module...
Here the Code:
=======================================
from pygame import cdrom
cdrom.init()
print "CDROM initialized: ", cdrom.get_init()
print "Number of CDROMs: ", cdrom.get_count()
def GetHMS(s):
h,s = divmod(s,3600)
m,s=divmod(s,60)
return "%02.f:%02.f:%02.f" % (h, m, s)
def Sek_Frames(s):
nurSek = int( s )
Frames = int( round( (s - nurSek) * 75 ) )
return nurSek, Frames
def cddb_sum(n):
# cddb_sum(123456789) => 1+2+3+4+5+6+7+8+9 = 45
ret = 0
while n > 0:
ret += (n % 10)
n = n / 10
return ret
def DiscID(cd_object):
print "\n Nr. Länge"
print "--------------------------"
checksum=0
TotalFrames=0
TotalSek=0
for i in range(TrackAnzahl):
track_length = cd_object.get_track_length(i)
nurSek, Frames = Sek_Frames( track_length )
checksum += cddb_sum(nurSek)
print " %2d %s.%2d Frames" % (i, GetHMS(nurSek), Frames)
TotalSek += nurSek
nurSek, Frames = Sek_Frames( TotalSek )
print "\nTotalZeit:",nurSek,"sek"
print "TotalZeit: %s.%d" % (GetHMS(nurSek),Frames)
sek_LetzterTrack = Sek_Frames(cd_object.get_track_length(i))[0]
sek_ErsterTrack = Sek_Frames(cd_object.get_track_length(0))[0]
t=sek_LetzterTrack - sek_ErsterTrack
RAWdiscID=( checksum % 0xff << 24 | t << 8 | TrackAnzahl )
for i in range(cdrom.get_count()):
cd_object = cdrom.CD(i)
print "\nNr.:",i," Laufwerk:",cd_object.get_name()
print "Initialisierte..."
cd_object.init()
TrackAnzahl = cd_object.get_numtracks()
if TrackAnzahl!=0:
RAWdiscID = DiscID(cd_object)
print "\nRAW discID..:", RAWdiscID
print "freedb ID...: %08lx" % RAWdiscID
=======================================
I have test it with "Depeche Mode" - "Speak & Spell":
Nr. Länge
--------------------------
0 00:03:46. 0 Frames
1 00:02:18.25 Frames
2 00:03:57.63 Frames
3 00:03:07.25 Frames
4 00:04:15.57 Frames
5 00:02:45.40 Frames
6 00:04:44.28 Frames
7 00:04:37.62 Frames
8 00:04:24.45 Frames
9 00:02:35. 5 Frames
10 00:03:44.58 Frames
11 00:04:03.65 Frames
12 00:04:05.37 Frames
13 00:03:46.63 Frames
14 00:03:08.65 Frames
15 00:06:44.12 Frames
TotalZeit: 3718 sek
TotalZeit: 01:01:58.0
RAW discID..: -1107250672
freedb ID...: be00b210
But be00b210 isn't the right ID :(
I search by hand and one of the follow IDs are the right:
d40e9010
db0e9210
d60e5910
Here the spec. from freedb:
http://freedb.org/modules.php?name=Sections&sop=viewarticle&artid=6
--
Genrich