home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / musica / getcddb / source / getcdd~4.bb2 < prev    next >
Text File  |  2000-01-07  |  3KB  |  136 lines

  1. ;GetCDDB_BigFunc.bb2
  2.  
  3. INCDIR "misc:data_/data/blitz_projects/getcddb/"
  4. XINCLUDE GetCDDB_CDFuncs.bb2
  5. XINCLUDE GetCDDB_TCPFuncs.bb2
  6. XINCLUDE GetCDDB_ParseFuncs.bb2
  7. XINCLUDE GetCDDB_Consts.bb2
  8.  
  9. Function.b GetCDDB{email$,scsidev$,scsiid,cdplayer$,genre$}
  10.  
  11. SHARED discpath$
  12. SHARED TOCCDID$
  13. SHARED overwrite.b
  14.  
  15. server$="cddb.cddb.com"
  16. cddbfile$="t:cddb.tmp"
  17. cdplayer$="optycdplayer"
  18.  
  19. If Len(email$)<3 OR Instr(email$,"@")=0 OR Len(scsidev$)=0
  20.   ErrorReq{"Invalid email or device"}
  21.   Function Return #_ARGS_ERROR
  22. EndIf
  23.  
  24. SetStatus{"Opening device..."}
  25.  
  26. If InitCDDA{}=0
  27.   ErrorReq{"Unable to open CD"}
  28.   Function Return #_CD_ERROR
  29. EndIf
  30.  
  31. SetStatus{"Reading CD contents..."}
  32.  
  33. If CDDAReadContents{}
  34.   ErrorReq{"Unable to read CD contents"}
  35.   EndingCDDA{}
  36.   Function Return #_CD_ERROR
  37. EndIf
  38.  
  39.  
  40. If Exists(discpath$+TOCCDID$) AND overwrite.b=0
  41.   EndingCDDA{}
  42.   Function Return -1
  43. EndIf
  44.  
  45. SocketBase.l=OpenLibrary_("bsdsocket.library",0)
  46. If SocketBase.l
  47.   TCPenabled.b=-1
  48.   CloseLibrary_(SocketBase)
  49. Else
  50.   TCPenabled=0
  51. EndIf
  52.  
  53.  
  54. SetStatus{"Calculating disc id..."}
  55.  
  56. discid$=ComputeCDDBDiscId{}
  57.  
  58. EndingCDDA{}
  59.  
  60.   Dim stored_ids$(100)
  61.   Dim stored_genres$(100)
  62.  
  63. ;If NOT TCPenabled.b ;miami not running
  64. ;  If OpenFile(0,ProgsDir{}+"getcddb.ids")
  65. ;    FileOutput 0
  66. ;    NPrint discid$
  67. ;    NPrint genre$
  68. ;    CloseFile 0
  69. ;  Else
  70. ;    ErrorReq{"Unable to open getcddb.ids for writing"}
  71. ;    Function Return #_WRITE_ERROR
  72. ;  EndIf
  73. ;  Function Return #_TCP_ERROR
  74. ;Else
  75. ;;  miami is running
  76. ;  ids.b=1
  77. ;  If ReadFile(0,ProgsDir{}+"getcddb.ids")
  78. ;    FileInput 0
  79. ;    Repeat
  80. ;      stored_ids$(ids.b)=Edit$(80)
  81. ;      stored_genres$(ids.b)=Edit$(80)
  82. ;      ids+1
  83. ;    Until Eof(0) OR ids.b=99
  84. ;  EndIf
  85. ;EndIf
  86.  
  87. stored_ids$(0)=discid$
  88. stored_genres$(0)=genre$
  89. ids.b=0
  90.  
  91. Dim genrelist$(100)
  92.  
  93. genrelist$(0)=genre$
  94. maxgenre.b=1
  95.  
  96. If OpenFile(0,ProgsDir{}+"cddb.genres")
  97.   FileInput 0
  98.   Repeat
  99.     genrelist$(maxgenre.b)=Edit$(80)
  100.     If NOT Len(genrelist$(maxgenre.b))
  101.       maxgenre.b+1
  102.     EndIf
  103.   Until Eof(0) OR maxgenre.b=99
  104.   CloseFile 0
  105. EndIf
  106.  
  107. For i.b=0 To ids.b ; loop through all of the stored ids
  108.  
  109.   ; the loop below should loop through all of the different genres to check
  110.   ; to see if the cd is in any of them
  111.   ; checks the 'prefered' genre first
  112.  
  113.   res.b=#_NOENTRY_ERROR
  114.   g.b=0 ;genre number
  115.  
  116.   While res.b=#_NOENTRY_ERROR AND g.b<maxgenre.b
  117.     res.b=ReadCDDB{server$, cddbfile$, discid$, genrelist$(g.b), email$}
  118.     g.b+1
  119.   Wend
  120.   If res.b<>-1
  121. ;    Pop For
  122.     ;Function Return res.b
  123.   EndIf
  124.   If res.b=-1
  125.     res.b=ConvertCDDBFile{cdplayer$,cddbfile$, discpath$+TOCCDID$}
  126.     DeleteFile_ cddbfile$
  127.   EndIf
  128. Next
  129.  
  130. ;NOTE - ONLY RETURNS THE RESULT OF THE *LAST* DISCID
  131.  
  132. Function Return res.b
  133.  
  134. End Function
  135.  
  136.