Page Date
2004-05-18
DD-Software
Kapitel zurück / previous Chapter
Main Index
 
Seite zurück / previous page
Backward
Seite vor / next page
Forward
 
Seitenanfang/TopOfPage
Top
Seitenende/EndOfPage
Bottom
MyWbtHelp current version

CDDBQSC


CDDBQSC.WBT   Version 1.02  2003:11:04

CDDB Query String Creator
This WinBatch script calculates the CDDB ID from Audio CDROM
and builds a formatted query string for CDDB request.

Example:
"cddb query 890a9a0b 11 187 20610 41790 60137 77472 90200 111502 128465 142360 162700 183120 2716"



;================================================================================================================================
; CDDB Query String Creator, CDDBQSC.WBT, Version 1.02                                                  (c)Detlev Dalitz.20010801
;================================================================================================================================
; Detlev Dalitz.20010801.20010809.20031104.
;
; This WinBatch script calculates the CDDB ID from Audio CDROM
; and builds a formatted query string for CDDB request.
;
; Example:
; cddb query 890a9a0b 11 187 20610 41790 60137 77472 90200 111502 128465 142360 162700 183120 2716
;================================================================================================================================

GoSub DefineUDFs

; Get List of CD-ROM drives.
CdRomList = DiskScan(8) ; Tab delimited list of logical drive names.
CdRomCount = ItemCount(CdRomList, @TAB)

While @TRUE
   ; Select one CD-ROM drive.
   IntControl (63, 300, 200, 700, 500)
   CdRomDrive = AskItemlist("Select one CD-ROM drive",CdRomList,@TAB, @SORTED, @SINGLE)

   ; Get List of cda track files from the selected drive.
   TrackList = FileItemize(StrCat(CdRomDrive,"\*.cda"))
   If (TrackList=="") Then Continue
   TrackList = ItemSort(TrackList,@TAB) ; For sure.
   TrackCount = ItemCount(TrackList,@TAB)

   DispList = ""
   DispItem = ""
   DispItem = ItemInsert("CD",-1,DispItem,@TAB)
   DispItem = ItemInsert("Begin",-1,DispItem,@TAB)
   DispItem = ItemInsert("",-1,DispItem,@TAB)
   DispItem = ItemInsert("",-1,DispItem,@TAB)
   DispItem = ItemInsert("Length",-1,DispItem,@TAB)
   DispItem = ItemInsert("",-1,DispItem,@TAB)
   DispItem = ItemInsert("",-1,DispItem,@TAB)
   DispList = ItemInsert(DispItem,-1,DispList,@CR)
   DispItem = ""
   DispItem = ItemInsert("Track ",-1,DispItem,@TAB)
   DispItem = ItemInsert("Minute",-1,DispItem,@TAB)
   DispItem = ItemInsert("Second",-1,DispItem,@TAB)
   DispItem = ItemInsert("Frame" ,-1,DispItem,@TAB)
   DispItem = ItemInsert("Minute",-1,DispItem,@TAB)
   DispItem = ItemInsert("Second",-1,DispItem,@TAB)
   DispItem = ItemInsert("Frame" ,-1,DispItem,@TAB)
   DispList = ItemInsert(DispItem,-1,DispList,@CR)

   CDAFileSize = 44 ; Magic value, see cda structure table below.
   bbcda = BinaryAlloc(CDAFileSize)

   SumNumbers = 0
   SumSeconds = 0
   FrameOffsetList = ""

   For t=1 To TrackCount
      TrackFilename = StrCat(CdRomDrive, "\", ItemExtract(t, TrackList, @TAB))
      BinaryEodSet(bbcda, 0)
      BinaryRead(bbcda, TrackFilename)

      TrackNr           = BinaryPeek2(bbcda, 22)
      TrackBeginMinute  = BinaryPeek(bbcda, 38)
      TrackBeginSecond  = BinaryPeek(bbcda, 37)
      TrackBeginFrame   = BinaryPeek(bbcda, 36)
      TrackLengthMinute = BinaryPeek(bbcda, 42)
      TrackLengthSecond = BinaryPeek(bbcda, 41)
      TrackLengthFrame  = BinaryPeek(bbcda, 40)

      If (t==1)
         ; Store first track begin for later use.
         FirstTrackStart = (TrackBeginMinute * 60) + TrackBeginSecond
      EndIf
      If (t==TrackCount)
         CDTotallength = 1
         CDTotallength = CDTotallength + (TrackBeginMinute * 60 * 75) + (TrackBeginSecond * 75) + TrackBeginFrame
         CDTotallength = CDTotallength + (TracklengthMinute * 60 * 75) + (TrackLengthSecond * 75) + TrackLengthFrame
         CDTotallength = CDTotallength / 75
      EndIf

      OffsetSecond = (TrackBeginMinute * 60) + TrackBeginSecond
      While (OffsetSecond > 0)
         SumNumbers = SumNumbers + (OffsetSecond mod 10);
         OffsetSecond = OffsetSecond / 10;
      EndWhile

      FrameOffset = (TrackBeginMinute * 60 * 75) + (TrackBeginSecond * 75) + TrackBeginFrame
      ; Store FrameOffsets for later use.
      FrameOffsetList = ItemInsert(FrameOffset,-1,FrameOffsetList," ")

      DispTrackNr           = StrFixLeft(TrackNr          ,"0",2)
      DispTrackBeginMinute  = StrFixLeft(TrackBeginMinute ,"0",2)
      DispTrackBeginSecond  = StrFixLeft(TrackBeginSecond ,"0",2)
      DispTrackBeginFrame   = StrFixLeft(TrackBeginFrame  ,"0",2)
      DispTrackLengthMinute = StrFixLeft(TrackLengthMinute,"0",2)
      DispTrackLengthSecond = StrFixLeft(TrackLengthSecond,"0",2)
      DispTrackLengthFrame  = StrFixLeft(TrackLengthFrame ,"0",2)

      DispItem = ""
      DispItem = ItemInsert(DispTrackNr          ,-1,DispItem,@TAB)
      DispItem = ItemInsert(DispTrackBeginMinute ,-1,DispItem,@TAB)
      DispItem = ItemInsert(DispTrackBeginSecond ,-1,DispItem,@TAB)
      DispItem = ItemInsert(DispTrackBeginFrame  ,-1,DispItem,@TAB)
      DispItem = ItemInsert(DispTrackLengthMinute,-1,DispItem,@TAB)
      DispItem = ItemInsert(DispTrackLengthSecond,-1,DispItem,@TAB)
      DispItem = ItemInsert(DispTrackLengthFrame ,-1,DispItem,@TAB)
      DispList = ItemInsert(DispItem,-1,DispList,@CR)
   Next
   DropWild("DispTrack*")
   DropWild("TrackBegin*")
   DropWild("TrackLength*")
   Drop(FrameOffset,OffsetSecond,TrackFilename,TrackNr,TrackList)

   CDSerialNrHex = ""
   For i=0 To 3
      CDSerialNrHex  = StrCat(udfByteToHex(BinaryPeek(bbcda, 24 + i)),CDSerialNrHex)
   Next
   CDSerialNrHex = StrSub(CDSerialNrHex,StrScan(CDSerialNrHex, "123456789abcdef", 1, @FWDSCAN), -1)
   CDSerialNrHex = StrCat("[", StrUpper(CDSerialNrHex), "]") ; As stored in CDPLAYER.INI.

   SumSeconds = CDTotalLength - FirstTrackStart
   bbcddb = BinaryAlloc(4)
   BinaryPoke4(bbcddb,0,((SumNumbers mod 255) << 24 | SumSeconds << 8 | TrackCount))
   CDDBIDHex = ""
   For i=0 To 3
      CDDBIDHex  = StrCat(udfByteToHex(BinaryPeek(bbcddb, 0 + i)), CDDBIDHex)
   Next
   BinaryFree(bbcddb)
   BinaryFree(bbcda)

   ; Here comes the ultimative CDDD query string.
   CDDBQueryList = ""
   CDDBQueryList = ItemInsert("cddb query"   , -1, CDDBQueryList, " ")
   CDDBQueryList = ItemInsert(CDDBIDHex      , -1, CDDBQueryList, " ")
   CDDBQueryList = ItemInsert(TrackCount     , -1, CDDBQueryList, " ")
   CDDBQueryList = ItemInsert(FrameOffsetList, -1, CDDBQueryList, " ")
   CDDBQueryList = ItemInsert(CDTotalLength  , -1, CDDBQueryList, " ")
   Drop(FrameOffsetList)

   DispList = ItemInsert(StrCat(@CR, "CD SerialNr ", CDSerialNrHex, @CR), -1, DispList, @CR)
   DispList = ItemInsert(CDDBQueryList, -1, DispList, @CR)

   IntControl (63, 100, 200, 900, 800)
   AskItemlist(StrCat("CDDB Query String Creator - Tracklist Info for CD drive ", CdRomDrive), DispList, @CR, @UNSORTED, @SINGLE)

   GoSub ClipCopyDialog
   DropWild("QueryList*")
EndWhile

:CANCEL
Exit

;================================================================================================================================
:DefineUDFs
;--------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfbytetohex",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfbytetohex

#DefineFunction udfByteToHex(Byte)
HexChars="0123456789abcdef"
h1=StrSub(HexChars,1+(Byte>>4),1)
h2=StrSub(HexChars,1+(Byte&15),1)
Return (StrCat(h1,h2))
;HexChars="0123456789ABCDEF"
;Byte=0..255
#EndFunction

:skip_udfbytetohex
;--------------------------------------------------------------------------------------------------------------------------------
Return ; from DefineUDFs
;================================================================================================================================


;================================================================================================================================
; Procedures
;--------------------------------------------------------------------------------------------------------------------------------
:ClipCopyDialog

CDDBQueryList_save = CDDBQueryList
ClipInfo = ""
done = @FALSE
While !done

   ;MyClipCopyDialogFormat=`WWWDLGED,5.0`
   ;MyClipCopyDialogCaption=`CDDB Query String Creator`
   ;MyClipCopyDialogX=60
   ;MyClipCopyDialogY=100
   ;MyClipCopyDialogWidth=363
   ;MyClipCopyDialogHeight=52
   ;MyClipCopyDialogNumControls=6
   ;MyClipCopyDialog01=`006,004,074,DEFAULT,STATICTEXT,DEFAULT,"CDDB Query String"`
   ;MyClipCopyDialog02=`312,004,044,DEFAULT,STATICTEXT,DEFAULT,"(c) DD.20010808"`
   ;MyClipCopyDialog03=`004,016,352,DEFAULT,EDITBOX,CDDBQueryList,""`
   ;MyClipCopyDialog04=`006,032,120,DEFAULT,VARYTEXT,ClipInfo,""`
   ;MyClipCopyDialog05=`132,032,064,DEFAULT,PUSHBUTTON,DEFAULT,"Copy to &ClipBoard",11`
   ;MyClipCopyDialog06=`204,032,064,DEFAULT,PUSHBUTTON,DEFAULT,"Cl&ose",1`
   ;ButtonPushed=Dialog("MyClipCopyDialog")

   MyClipCopyDialogFormat=`WWWDLGED,6.1`
   MyClipCopyDialogCaption=`CDDB Query String Creator`
   MyClipCopyDialogX=060
   MyClipCopyDialogY=100
   MyClipCopyDialogWidth=362
   MyClipCopyDialogHeight=051
   MyClipCopyDialogNumControls=006
   MyClipCopyDialogProcedure=`DEFAULT`
   MyClipCopyDialogFont=`DEFAULT`
   MyClipCopyDialogTextColor=`DEFAULT`
   MyClipCopyDialogBackground=`DEFAULT,DEFAULT`
   MyClipCopyDialogConfig=0
   MyClipCopyDialog001=`007,005,074,012,STATICTEXT,DEFAULT,"CDDB Query String",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   MyClipCopyDialog002=`313,005,044,012,STATICTEXT,DEFAULT,"(c) DD.20010808",DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   MyClipCopyDialog003=`005,017,352,012,EDITBOX,CDDBQueryList,"Edit 1",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   MyClipCopyDialog004=`007,033,120,012,VARYTEXT,ClipInfo,"Vary 1",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   MyClipCopyDialog005=`133,033,064,012,PUSHBUTTON,DEFAULT,"Copy to &ClipBoard",11,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   MyClipCopyDialog006=`205,033,064,012,PUSHBUTTON,DEFAULT,"Cl&ose",1,6,32,DEFAULT,DEFAULT,DEFAULT`
   ButtonPushed=Dialog("MyClipCopyDialog")

   CDDBQueryList = CDDBQueryList_save
   Select ButtonPushed
   Case 11
      ClipPut(CDDBQueryList)
      If (CDDBQueryList==ClipGet())
         ClipInfo = "The whole Query String was copied to Clipboard"
      Else
         ClipInfo = ""
      EndIf
      Break
   Case 1
      done = @TRUE
      Break
   EndSelect
EndWhile
DropWild("MyClipCopyDialog*")
Return
;================================================================================================================================


;================================================================================================================================
; Note:
; The rounding formula I've used in CDDBQSC.WBT Version 1.00 was not good in all cases.
; Therefore the calculation formulas were changed in Version 1.01.
; Now we use the known standard vehicle for calculation of TotalLength.
;================================================================================================================================


;================================================================================================================================
; CDA file structure
; Thanks to Wojtek Kaniewski, 1997, wojtekka@logonet.com.pl, published on http://www.wotsit.org
;--------------------------------------------------------------------------------------------------------------------------------
; Offset Length  Offset Length
; 00h    08h     00d    08d     RIFF resource identifier string: "RIFF$".
; 08h    04h     08d    04d     RIFF ID: "CDDA".
; 0ch    04h     12d    04d     Data ID: "fmt ".
; 10h    04h     16d    04d     Length of following block: "18 00 00 00" = 24 byte
; 14h    02h     20d    02d     CDA file version. Currently equals 1.
;                               If it has other value, following data may be out of date.
; 16h    02h     22d    02d     Number of Track.
; 18h    04h     24d    04d     CD disc serial number (the one stored in CDPLAYER.INI).
; 1ch    04h     28d    04d     Beginning of the Track in HSG format.
; 20h    04h     32d    04d     Length of the Track in HSG format.
; 24h    04h     36d    04d     Beginning of the Track in Red-Book format.
; 28h    04h     40d    04d     Length of the Track in Red-Book format.
; 2ch    ---     44d    ---     Total structure size
;--------------------------------------------------------------------------------------------------------------------------------
; Red-book time format
; Offset Length  Description
; 00h    01h     Frame
; 01h    01h     Second
; 02h    01h     Minute
; 03h    01h     not used
;--------------------------------------------------------------------------------------------------------------------------------
; HSG time format               time = minute * 4500 + second * 75 + frame
; Offset Length  Description
; 00h    01h     Frame
; 01h    01h     Second
; 02h    01h     Minute
; 03h    01h     not used
;================================================================================================================================




Page Date
2004-05-18
DD-Software
Kapitel zurück / previous Chapter
Main Index
 
Seite zurück / previous page
Backward
Seite vor / next page
Forward
 
Seitenanfang/TopOfPage
Top
Seitenende/EndOfPage
Bottom
MyWbtHelp current version