home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / CDROM / GetCDDB / src / GEA008~1.BB2 < prev    next >
Text File  |  2000-01-07  |  7KB  |  244 lines

  1. ;GetCDDB_TCPFuncs.bb2
  2.  
  3.  ;-----------------------------------------------------------
  4.  ; GetCDDB_TCPFuncs V0.07b by Roger Light (c)1999
  5.  
  6.  ; Retrieves CDDB information from online and saves it in the
  7.  ; specified file.
  8.  ; ;-----------------------------------------------------------
  9.  
  10. XINCLUDE "Cut_TCPFuncs.bb2"
  11. XINCLUDE "GetCDDB_CDFuncs.bb2"
  12. XINCLUDE "GetCDDB_Consts.bb2"
  13.  
  14. ;server$="cddb.cddb.com"
  15.  
  16. Function.b ReadCDDB{server$, cddbfile$, discid$, genre$, email$}
  17.  
  18.   SHARED v$
  19.  
  20.   If Instr(email$,"@")=0 OR Len(email$)<3
  21.     ErrorReq{"Invalid email address"}
  22.     Function Return #_ARGS_ERROR
  23.   EndIf
  24.  
  25.   If Len(server$)=0 OR Len(cddbfile$)=0 OR Len(discid$)=0
  26.     ErrorReq{"Invalid server, output file or discid.|Please contact author about this problem."}
  27.     Function Return #_ARGS_ERROR
  28.   EndIf
  29.  
  30.   If NOT Len(genre$)
  31.     genre$="rock"
  32.   EndIf
  33.  
  34.   username$=Left$(email$,Instr(email$,"@")-1)
  35.   hostname$=Right$(email$,Len(email$)-Instr(email$,"@"))
  36.  
  37.  
  38.   If NOT ConnectTCP{server$,80};#_FALSE
  39.     ErrorReq{"Unable to connect to CDDB server"}
  40.     Function Return #_TCP_ERROR
  41.   EndIf
  42.  
  43.   If NOT WriteFile(0,cddbfile$);#_FALSE
  44.     ErrorReq{"Unable to open output file for writing"}
  45.     Function Return #_WRITE_ERROR
  46.   EndIf
  47.   FileOutput 0
  48.  
  49.   cmdstr$="GET /"+Chr$(126)+"cddb/cddb.cgi?cmd=cddb+read+"
  50.   cmdstr$+genre$+"+"+discid$+"&hello="+username$+"+"+hostname$+"+GetCDDB+"+v$+"&proto=4 HTTP/1.0"
  51.   cmdstr$+Chr$(10)+Chr$(13)+"From: "+email$
  52.   cmdstr$+Chr$(10)+Chr$(13)+"User-Agent: GetCDDB"
  53.   cmdstr$+Chr$(10)+Chr$(13)+Chr$(10)+Chr$(13)
  54.   WriteMemTCP{&cmdstr$, Len(cmdstr$)}
  55.   Delay_(50)
  56.   Repeat
  57.     inputstr$=ReadTCP{}
  58.     inputstr$=Replace$(inputstr$,Chr$(13),"")
  59. ;    Request "o","@"+inputstr$+"@","OK"
  60. ;    FileOutput 0
  61.     Print inputstr$
  62.  
  63.     lastchar$=Mid$(inputstr$,Len(inputstr$)-1,1)
  64.   Until lastchar$="."; OR Len(lastchar$)=0
  65.   CloseFile 0
  66.  
  67.   CloseTCP{}
  68.  
  69.   Function Return -1;#_TRUE
  70. End Function
  71.  
  72. ;-----------------------------------------------------------------------
  73. ; This function doesn't seem to return any results due to a slight 
  74. ; incompatibility between the values that I get for the track offsets 
  75. ; and the ones that are in the CDDB archives. Hence I asked people 
  76. ; to use the SaveCDOffsets program to see if the problem was just one 
  77. ; that occured with my setup. 
  78. ; According to the CDDB protocol, a Query should be sent before a Read 
  79. ; to verify that the file exists. Obviously this is not possible at the
  80. ; moment.
  81.  
  82. Function.b QueryCDDB{server$, cddbfile$, discid$, email$}
  83. ;
  84.  
  85.   SHARED TOClength
  86.   SHARED TOCaddr()
  87.   SHARED v$
  88.  
  89.   Dim trackpos.l(100) ; position of tracks, in frame format
  90.  
  91.   ;calculate position of tracks
  92.   For i.l=0 To TOClength
  93.     trackpos(i)=TOCaddr(i)+150
  94.   Next
  95.  
  96.   If Instr(email$,"@")=0 OR Len(email$)<3
  97.     ErrorReq{"Invalid email address"}
  98.     Function Return #_ARGS_ERROR
  99.   EndIf
  100.  
  101.   If Len(server$)=0 OR Len(cddbfile$)=0 OR Len(discid$)=0
  102.     ErrorReq{"Invalid server, output file or discid.|Please contact author about this problem."}
  103.     Function Return #_ARGS_ERROR
  104.   EndIf
  105.  
  106.   If NOT Len(genre$)
  107.     genre$="rock"
  108.   EndIf
  109.  
  110.   username$=Left$(email$,Instr(email$,"@")-1)
  111.   hostname$=Right$(email$,Len(email$)-Instr(email$,"@"))
  112.  
  113.   If NOT ConnectTCP{server$,80};#_FALSE
  114.     ErrorReq{"Unable to connect to CDDB server"}
  115.     Function Return #_TCP_ERROR
  116.   EndIf
  117.  
  118.   If NOT WriteFile(0,cddbfile$);#_FALSE
  119.     ErrorReq{"Unable to open output file for writing"}
  120.     CloseTCP{}
  121.     Function Return #_WRITE_ERROR
  122.   EndIf
  123.  
  124.   FileOutput 0
  125.  
  126.   cmdstr$="GET /"+Chr$(126)+"cddb/cddb.cgi?cmd=cddb+query+"
  127.   cmdstr$+discid$+"+"+Str$(TOClength)
  128.   For i.l=0 To TOClength
  129.     cmdstr$+"+"+Str$(trackpos(i))
  130.   Next
  131.   cmdstr$+Str$(t.l)
  132.   cmdstr$+"&hello="+username$+"+"+hostname$+"+GetCDDB+"+v$+"&proto=4 HTTP/1.0"
  133.   cmdstr$+Chr$(10)+Chr$(13)+"From: "+email$
  134.   cmdstr$+Chr$(10)+Chr$(13)+"User-Agent: GetCDDB"
  135.   cmdstr$+Chr$(10)+Chr$(13)+Chr$(10)+Chr$(13)
  136.  
  137.   WriteMemTCP{&cmdstr$, Len(cmdstr$)}
  138.   Delay_(50) ;required?
  139.   Repeat
  140.     inputstr$=ReadTCP{}
  141.     inputstr$=Replace$(inputstr$,Chr$(13),"")
  142.     FileOutput 0
  143.     Print inputstr$
  144.  
  145.     lastchar$=Mid$(inputstr$,Len(inputstr$)-1,1)
  146.   Until lastchar$="."
  147.   CloseFile 0
  148.  
  149.   CloseTCP{}
  150.  
  151.   Function Return -1;#_TRUE
  152. End Function
  153.  
  154. ;-----------------------------------------------------------------------
  155.  
  156. Function.b GetCDDBGenres{server$, cddbfile$, genrefile$, email$}
  157.  
  158.   SHARED v$
  159.  
  160.   If Instr(email$,"@")=0 OR Len(email$)<3
  161.     ErrorReq{"Invalid email address"}
  162.     Function Return #_ARGS_ERROR
  163.   EndIf
  164.  
  165.   If Len(server$)=0 OR Len(cddbfile$)=0
  166.     ErrorReq{"Invalid server or output file|Please contact author about this problem."}
  167.     Function Return #_ARGS_ERROR
  168.   EndIf
  169.  
  170.   username$=Left$(email$,Instr(email$,"@")-1)
  171.   hostname$=Right$(email$,Len(email$)-Instr(email$,"@"))
  172.  
  173.   SetStatus{"Connecting..."}
  174.  
  175.   If NOT ConnectTCP{server$,80};#_FALSE
  176.     ErrorReq{"Unable to connect to CDDB server"}
  177.     Function Return #_TCP_ERROR
  178.   EndIf
  179.  
  180.   If NOT WriteFile(0,cddbfile$)
  181.     ErrorReq{"Unable to open output file for writing"}
  182.     CloseTCP{}
  183.     Function Return #_WRITE_ERROR
  184.   EndIf
  185.  
  186.   FileOutput 0
  187.  
  188.   cmdstr$="GET /"+Chr$(126)+"cddb/cddb.cgi?cmd=cddb+lscat+"
  189.   cmdstr$+"&hello="+username$+"+"+hostname$+"+GetCDDB+"+v$+"&proto=4 HTTP/1.0"
  190.   cmdstr$+Chr$(10)+Chr$(13)+"From: "+username$+"@"+hostname$
  191.   cmdstr$+Chr$(10)+Chr$(13)+"User-Agent: GetCDDB"
  192.   cmdstr$+Chr$(10)+Chr$(13)+Chr$(10)+Chr$(13)
  193.  
  194.   WriteMemTCP{&cmdstr$, Len(cmdstr$)}
  195. ;  Delay_(50) ;required?
  196.   VWait 50
  197.   Repeat
  198.     inputstr$=ReadTCP{}
  199.     inputstr$=Replace$(inputstr$,Chr$(13),"")
  200.     FileOutput 0
  201.     Print inputstr$
  202.  
  203.     lastchar$=Mid$(inputstr$,Len(inputstr$)-1,1)
  204.   Until lastchar$="."
  205.   CloseFile 0
  206.  
  207.   CloseTCP{}
  208.   SetStatus{"Parsing..."}
  209.  
  210.   If WriteFile(0,genrefile$) AND OpenFile(1,cddbfile$)
  211.     FileInput 1
  212.     FileOutput 0
  213.  
  214.     Repeat
  215.       inputstr$=Edit$(80)
  216.     Until Instr(inputstr$,"category list follows") OR Eof(1)
  217.  
  218.     If Eof(1)
  219.       CloseFile 0
  220.       CloseFile 1
  221.       ErrorReq{"Unable to obtain genre list"}
  222.       Function Return #_SERVER_ERROR
  223.     EndIf
  224.  
  225.     inputstr$=Edit$(80)
  226.     While Mid$(inputstr$,Len(inputstr$)-1,1)<>"."
  227.       NPrint inputstr$
  228.       inputstr$=Edit$(80)
  229.     Wend
  230.  
  231.     CloseFile 0
  232.     CloseFile 1
  233.   Else
  234.     ErrorReq{"Unable to open input/output file"}
  235.     Function Return #_FILE_ERROR
  236.   EndIf
  237.  
  238.   DeleteFile_ cddbfile$
  239.  
  240.   Function Return -1;#_TRUE
  241.  
  242. End Function
  243.  
  244.