forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Get CDDB info

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript Open Source Projects
View previous topic :: View next topic  
Author Message
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Fri May 31, 2002 12:09 pm    Post subject: Get CDDB info Reply with quote

Hi,

This is the "draft" code of how to get CDDB information from a musical CD. In order to use this code you need PGWARE VDSIPP.DLL that you get from

and of course an internet connection. Also note that this code is unfinished code. There's not alot of error handling and there certainly some of the CDDB features missing. Go to http://www.freedb.org for more info on the commands of CDDB.

The current code gets the Album name , number of tracks, CDDBID, Style, and the track names. Its a good start....

If you have 2 cdrom drives it doesnt seem to work well.Also sorry if there's not a lot of comments and junk code in there Wink

I started working on that code for VDSWORLD Media Player but stopped because I had other projects. If someone comes up with a clean modified version I may implement it VDSWORLD Media Player...
Woud be nice to see this project as an open source project...

Core code idea by : Ren Janseen (Easy Rider)
Modified/adapted by: Martin Bellefeuille (Me...Marty)



Well here it is:

Code:

Rem Credits for the core code goes to Easy Rider who nicely gave the code
rem The code was modified by me to support VDSIPP.DLL
rem If you use this code in your own app please give credit to both of us.
rem Idealy if you enchance this draft code if should be reposted on VDSWORLD
rem So everyone could use and again enhance it. Thanks you and enjoy


Title cddb get info
%%mciclose = @mci(close all cdaudio)
%%email = "xxxx@myserver.com"
%%server = "myserver.com"
%%cddbserver = "ca.freedb.org"
%%settime = @mci(set cdaudio time format tmsf)
%%SerNum = @hex(@volinfo(%%cdrom_drive,Z))
external @path(%0)\vdsipp.dll,demo
option errortrap,error
internet http,create,1
internet http,threads,1,off
option decimalsep,.
list create,4
list create,5
%Y = @curdir()

directory create,%Y\Albums

  DIALOG CREATE,CDDB Get,-1,0,478,368
  DIALOG ADD,LIST,LIST1,91,70,344,222
  DIALOG ADD,BUTTON,getcddb,326,210,64,24,getcddb
  DIALOG SHOW
:Evloop
  wait event
  goto @event()
:getcddbBUTTON
:cddbmenu
  %%SerNum = @hex(@volinfo(%%CDROM_DRIVE,Z))
  gosub cddbid
   if @zero(%%cddbid)
     info empty
     goto evloop
   end   
  internet http,get,1,http://%%CDDBSERVER/~cddb/cddb.cgi?cmd=cddb+query+%%CDDBID+%%NumTracks+%%Offsets+%%DiscLength&hello=%%email+%%server+TestPlayer+v10&proto=4
  list clear,list1
   %B = @internet(http,content,1)
      list create,16
    list add,16,%B
   file delete,c:\testcddb1.txt
   list savefile,16,c:\testcddb1.txt
   wait 1
   list add,list1,%b
   list seek,list1,0
    option fieldsep," "
  parse "%%Error;%%Style",@item(list1)
  rem 200 = exact match(es)
  rem 202 = no match
  rem 211 = inexact match(es)
  rem 403 = corrupt database entry
  rem 409 = no handshake
  if @equal(%%Error,202)
    warn No matches in CDDB database !
    goto evloop
  else
rem    if @not(@equal(%%Error,200))
rem      warn Error while retrieving disk information.@cr()Probably multiple matches.
rem      goto evloop
rem    end
  end
  internet http,get,1,http://%%CDDBSERVER/~cddb/cddb.cgi?cmd=cddb+read+%%style+%%CDDBID&hello=%%email+%%server+TestPlayer+v10&proto=4
 
  %c = @internet(http,content,1)
  list add,4,%c
  file delete,c:\testcddb.txt
  list savefile,4,c:\testcddb.txt
  wait 2
  list loadfile,list1,c:\testcddb.txt
  parse "%%Error;%%Style",@next(4)
  gosub errorcheck
  gosub removeunwanted
  gosub cleanuplist
 
goto evloop
 

  :errorcheck
  rem 210 = OK
  rem 401 = specified entry not found
  rem 402 = server error
  rem 403 = corrupt database entry
  rem 417 = access limit exceeded
  if @equal(%%Error,401)
    warn CDDB entry not found !
    option fieldsep,|
    goto evloop
  else
    if @equal(%%Error,402)
      warn Server error !
      option fieldsep,|
      goto evloop
    else
      if @equal(%%Error,403)
        warn Server error !
        option fieldsep,|
        goto evloop
      else
        if @equal(%%Error,403)
          warn Access limit exceeded !
          option fieldsep,|
          goto evloop
       else
         if @not(@equal(%%Error,210))
           warn An unknown error occured.
           option fieldsep,|
           goto evloop
         end
        end
      end
    end
  end
  exit
 
 
 
 
  option fieldsep,=
  %B =
   list seek,4,0
  repeat
    parse "%%Entry;%%Data",@next(4)
      if @equal(%%Entry,DTITLE)
        list add,5,%%data   
      else
        if @equal(@substr(%%Entry,1,6),TTITLE)
               list add,5,@substr(%%Entry,7,@len(%%Entry)). %%data
          if @greater(@substr(%%Entry,7,@len(%%Entry)),%B)
            %B = @substr(%%Entry,7,@len(%%Entry))
          end
        end
      end
  until @equal(@item(4),.)
  list seek,5,0
   %%item = @item(5)
   %%artist = @substr(%%item,1,@pos(/,%%item))
   %%len = @diff(@len(%%artist),2)
   %%artist = @substr(%%artist,1,%%len)
   %%album = @substr(%%item,@pos(/,%%item),@len(%%item))
   %%album = @substr(%%album,3,@len(%%album))
   dialog set,E1,%%artist
   dialog set,E2,%%album
   list delete,5,0
   list savefile,5,%Y\Albums\%%artist-%%album.txt
   list close,l1
   list clear,l1
   list create,1,sorted
   list loadfile,1,cd.txt
   gosub updaterec
   list savefile,1,cd.txt
   list clear,1
   list close,1
  option fieldsep,|
  goto loadlist
   
:cddbid
  option fieldsep,:
  %A = @mci(open cdaudio)
  if @not(@ok())
    if %A
      warn "MCI error (1):"@cr()@cr()%A
      %%CDDBID =
      option fieldsep,|
      exit
    end
  end
  %A = @mci(set cdaudio time format msf)
  %%NumTracks = @mci(status cdaudio number of tracks)
  if @not(@ok())
    if %%NumTracks
      warn "MCI error (2):"@cr()@cr()%%NumTracks
      %%CDDBID =
      option fieldsep,|
      exit
    end
  end
  if @equal(%%NumTracks,0)
    warn Empty disc!
    %%CDDBID =
    option fieldsep,|
   exit
  end
  %N =
  %%Offsets =
  %%Track =
  repeat
    %%Track = @succ(%%Track)
    %M =
    %S =
    %F =
    parse "%M;%S;%F",@mci(status cdaudio position track %%Track)
    %%string = @sum(@prod(%M,60),%S)
    rem 60 * 75 = 4500
    rem 60 is the number of seconds in a minute.
    rem 75 is the number of frames in a seconds.
    %F = @sum(@prod(%M,4500),@prod(%S,75),%F)
    if %%Offsets
      %%Offsets = %%Offsets+%F
    else
      %%Offsets = %F
    end
    if @equal(%%Track,1)
      %%StartOffset = %%string
    end
 
    rem This will give the total of all digits together, so eg. 165 will be 1 + 6 + 5 = 12.
    %%total =
    repeat
      %%total = @sum(%%total,@substr(%%string,@len(%%string),@len(%%string)))
      %%string = @strdel(%%string,@len(%%string),@len(%%string))
    until @not(%%string)
    %N = @sum(%N,%%total)
 
  until @equal(%%Track,%%NumTracks)
  %M =
  %S =
  %F =
  parse "%M;%S;%F",@mci(status cdaudio position track %%NumTracks)
  %D = @sum(@prod(%M,4500),@prod(%S,75),%F)
  %M =
  %S =
  %F =
  parse "%M;%S;%F",@mci(status cdaudio length track %%NumTracks)
  %A = @mci(close cdaudio)
  if @not(@ok())
    if %A
      warn "MCI error (3):"@cr()@cr()%A
      %%CDDBID =
      option fieldsep,|
      exit
    end
  end
  %D = @sum(%D,@prod(%M,4500),@prod(%S,75),%F,1)
  %D = @div(%D,75)
  %D = @hex(@diff(%D,%%StartOffset),4)
  %%DiscLength = @diff($%D,0)
  %N = @hex(@mod(%N,$FF),2)
  %T = @hex(%%NumTracks,2)
  rem The ID should always be LOWERCASE.
  %%CDDBID = @lower(%N%D%T)
   option fieldsep,|
  exit
:removeunwanted
list seek,list1,1

repeat
  if @MATCH(list1,#)
    LIST DELETE,list1
  end
until @not(@MATCH(list1,#))
     LIST  SAVEFILE,list1,%y\albums\finalcddb.txt
 
   wait .1
   list clear,list1
 
    list loadfile,list1,%y\albums\finalcddb.txt
 
end
  exit
:cleanuplist
list create,15
list seek,list1,2
%%Bandalbum =  @item(list1)
%%Result = @strdel(%%bandalbum,1,7)
List add,15,Total of tracks : %%numtracks
list add,15,%%result
list seek,list1,3
repeat
 if @MATCH(list1,ttitle)
   %%track = @strdel(@item(list1),1,8)
   list add,15,%%track
   list delete,list1
  end
until @not(@match(list1,ttitle))
 file delete,c:\trackscddb.txt
 LIST  SAVEFILE,15,c:\trackscddb.txt
   wait .1
    list clear,list1
   list loadfile,list1,c:\trackscddb.txt
 
   list close,15
exit


:Close
 internet http,destroy,1
  exit
:errorsection
internet http,destroy,1
stop


Last edited by marty on Sat Mar 27, 2004 4:39 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Wed Oct 23, 2002 12:27 pm    Post subject: Reply with quote

Another example of CDDB has been posted by Tommy :

http://www.vdsworld.com/forum/viewtopic.php?t=335

Ciao


Last edited by marty on Thu Oct 24, 2002 11:32 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Wed Oct 23, 2002 12:55 pm    Post subject: Reply with quote

I am having a problem with it. It gets the tracks but it keeps loading the list with TONS of numbers and then crashes. I am trying to find out why, but, no luck as of yet. Anyideas?
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Wed Oct 23, 2002 1:38 pm    Post subject: Reply with quote

Sorry I couldnt test at 100% Tommy's code because of the proxy here..

I figured it would work by looking at it.

Will try at home tonight Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript Open Source Projects All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group