home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 6
/
AACD06.ISO
/
AACD
/
CDROM
/
GetCDDB
/
src
/
GEA008~1.BB2
< prev
next >
Wrap
Text File
|
2000-01-07
|
7KB
|
244 lines
;GetCDDB_TCPFuncs.bb2
;-----------------------------------------------------------
; GetCDDB_TCPFuncs V0.07b by Roger Light (c)1999
; Retrieves CDDB information from online and saves it in the
; specified file.
; ;-----------------------------------------------------------
XINCLUDE "Cut_TCPFuncs.bb2"
XINCLUDE "GetCDDB_CDFuncs.bb2"
XINCLUDE "GetCDDB_Consts.bb2"
;server$="cddb.cddb.com"
Function.b ReadCDDB{server$, cddbfile$, discid$, genre$, email$}
SHARED v$
If Instr(email$,"@")=0 OR Len(email$)<3
ErrorReq{"Invalid email address"}
Function Return #_ARGS_ERROR
EndIf
If Len(server$)=0 OR Len(cddbfile$)=0 OR Len(discid$)=0
ErrorReq{"Invalid server, output file or discid.|Please contact author about this problem."}
Function Return #_ARGS_ERROR
EndIf
If NOT Len(genre$)
genre$="rock"
EndIf
username$=Left$(email$,Instr(email$,"@")-1)
hostname$=Right$(email$,Len(email$)-Instr(email$,"@"))
If NOT ConnectTCP{server$,80};#_FALSE
ErrorReq{"Unable to connect to CDDB server"}
Function Return #_TCP_ERROR
EndIf
If NOT WriteFile(0,cddbfile$);#_FALSE
ErrorReq{"Unable to open output file for writing"}
Function Return #_WRITE_ERROR
EndIf
FileOutput 0
cmdstr$="GET /"+Chr$(126)+"cddb/cddb.cgi?cmd=cddb+read+"
cmdstr$+genre$+"+"+discid$+"&hello="+username$+"+"+hostname$+"+GetCDDB+"+v$+"&proto=4 HTTP/1.0"
cmdstr$+Chr$(10)+Chr$(13)+"From: "+email$
cmdstr$+Chr$(10)+Chr$(13)+"User-Agent: GetCDDB"
cmdstr$+Chr$(10)+Chr$(13)+Chr$(10)+Chr$(13)
WriteMemTCP{&cmdstr$, Len(cmdstr$)}
Delay_(50)
Repeat
inputstr$=ReadTCP{}
inputstr$=Replace$(inputstr$,Chr$(13),"")
; Request "o","@"+inputstr$+"@","OK"
; FileOutput 0
Print inputstr$
lastchar$=Mid$(inputstr$,Len(inputstr$)-1,1)
Until lastchar$="."; OR Len(lastchar$)=0
CloseFile 0
CloseTCP{}
Function Return -1;#_TRUE
End Function
;-----------------------------------------------------------------------
; This function doesn't seem to return any results due to a slight
; incompatibility between the values that I get for the track offsets
; and the ones that are in the CDDB archives. Hence I asked people
; to use the SaveCDOffsets program to see if the problem was just one
; that occured with my setup.
; According to the CDDB protocol, a Query should be sent before a Read
; to verify that the file exists. Obviously this is not possible at the
; moment.
Function.b QueryCDDB{server$, cddbfile$, discid$, email$}
;
SHARED TOClength
SHARED TOCaddr()
SHARED v$
Dim trackpos.l(100) ; position of tracks, in frame format
;calculate position of tracks
For i.l=0 To TOClength
trackpos(i)=TOCaddr(i)+150
Next
If Instr(email$,"@")=0 OR Len(email$)<3
ErrorReq{"Invalid email address"}
Function Return #_ARGS_ERROR
EndIf
If Len(server$)=0 OR Len(cddbfile$)=0 OR Len(discid$)=0
ErrorReq{"Invalid server, output file or discid.|Please contact author about this problem."}
Function Return #_ARGS_ERROR
EndIf
If NOT Len(genre$)
genre$="rock"
EndIf
username$=Left$(email$,Instr(email$,"@")-1)
hostname$=Right$(email$,Len(email$)-Instr(email$,"@"))
If NOT ConnectTCP{server$,80};#_FALSE
ErrorReq{"Unable to connect to CDDB server"}
Function Return #_TCP_ERROR
EndIf
If NOT WriteFile(0,cddbfile$);#_FALSE
ErrorReq{"Unable to open output file for writing"}
CloseTCP{}
Function Return #_WRITE_ERROR
EndIf
FileOutput 0
cmdstr$="GET /"+Chr$(126)+"cddb/cddb.cgi?cmd=cddb+query+"
cmdstr$+discid$+"+"+Str$(TOClength)
For i.l=0 To TOClength
cmdstr$+"+"+Str$(trackpos(i))
Next
cmdstr$+Str$(t.l)
cmdstr$+"&hello="+username$+"+"+hostname$+"+GetCDDB+"+v$+"&proto=4 HTTP/1.0"
cmdstr$+Chr$(10)+Chr$(13)+"From: "+email$
cmdstr$+Chr$(10)+Chr$(13)+"User-Agent: GetCDDB"
cmdstr$+Chr$(10)+Chr$(13)+Chr$(10)+Chr$(13)
WriteMemTCP{&cmdstr$, Len(cmdstr$)}
Delay_(50) ;required?
Repeat
inputstr$=ReadTCP{}
inputstr$=Replace$(inputstr$,Chr$(13),"")
FileOutput 0
Print inputstr$
lastchar$=Mid$(inputstr$,Len(inputstr$)-1,1)
Until lastchar$="."
CloseFile 0
CloseTCP{}
Function Return -1;#_TRUE
End Function
;-----------------------------------------------------------------------
Function.b GetCDDBGenres{server$, cddbfile$, genrefile$, email$}
SHARED v$
If Instr(email$,"@")=0 OR Len(email$)<3
ErrorReq{"Invalid email address"}
Function Return #_ARGS_ERROR
EndIf
If Len(server$)=0 OR Len(cddbfile$)=0
ErrorReq{"Invalid server or output file|Please contact author about this problem."}
Function Return #_ARGS_ERROR
EndIf
username$=Left$(email$,Instr(email$,"@")-1)
hostname$=Right$(email$,Len(email$)-Instr(email$,"@"))
SetStatus{"Connecting..."}
If NOT ConnectTCP{server$,80};#_FALSE
ErrorReq{"Unable to connect to CDDB server"}
Function Return #_TCP_ERROR
EndIf
If NOT WriteFile(0,cddbfile$)
ErrorReq{"Unable to open output file for writing"}
CloseTCP{}
Function Return #_WRITE_ERROR
EndIf
FileOutput 0
cmdstr$="GET /"+Chr$(126)+"cddb/cddb.cgi?cmd=cddb+lscat+"
cmdstr$+"&hello="+username$+"+"+hostname$+"+GetCDDB+"+v$+"&proto=4 HTTP/1.0"
cmdstr$+Chr$(10)+Chr$(13)+"From: "+username$+"@"+hostname$
cmdstr$+Chr$(10)+Chr$(13)+"User-Agent: GetCDDB"
cmdstr$+Chr$(10)+Chr$(13)+Chr$(10)+Chr$(13)
WriteMemTCP{&cmdstr$, Len(cmdstr$)}
; Delay_(50) ;required?
VWait 50
Repeat
inputstr$=ReadTCP{}
inputstr$=Replace$(inputstr$,Chr$(13),"")
FileOutput 0
Print inputstr$
lastchar$=Mid$(inputstr$,Len(inputstr$)-1,1)
Until lastchar$="."
CloseFile 0
CloseTCP{}
SetStatus{"Parsing..."}
If WriteFile(0,genrefile$) AND OpenFile(1,cddbfile$)
FileInput 1
FileOutput 0
Repeat
inputstr$=Edit$(80)
Until Instr(inputstr$,"category list follows") OR Eof(1)
If Eof(1)
CloseFile 0
CloseFile 1
ErrorReq{"Unable to obtain genre list"}
Function Return #_SERVER_ERROR
EndIf
inputstr$=Edit$(80)
While Mid$(inputstr$,Len(inputstr$)-1,1)<>"."
NPrint inputstr$
inputstr$=Edit$(80)
Wend
CloseFile 0
CloseFile 1
Else
ErrorReq{"Unable to open input/output file"}
Function Return #_FILE_ERROR
EndIf
DeleteFile_ cddbfile$
Function Return -1;#_TRUE
End Function