Difference between revisions of "CDDB"

From Free Pascal wiki
Jump to navigationJump to search
(→‎Download: added note about dead link)
Line 8: Line 8:
 
   
 
   
 
=== Download ===
 
=== Download ===
The latest can be found [http://www.simmonsclan.net/fpc/cddb.pas here].
+
The latest can be found [http://www.simmonsclan.net/fpc/cddb.pas here] - This link appears to be dead. Is there an active copy of this somewhere?
  
 
=== Dependencies / System Requirements ===
 
=== Dependencies / System Requirements ===

Revision as of 00:45, 19 December 2010

English (en)

About

CDDB is a simple unit for accessing CD track information from CDDB/FreeDB. There is little documentation but sample code is provided below.

License

BSD

Download

The latest can be found here - This link appears to be dead. Is there an active copy of this somewhere?

Dependencies / System Requirements

  • Linux
  • Synapse httpsend unit

Installation

Copy the unit into the source directory for your project.

Use

The first step to accessing CDDB is creating TCDDB. This is where the connection and application information is defined. TCDDB has some default values so you don't have to define them all. The default server is FreeDB. <delphi> procedure CreateCDDB; var

 CDDB: TCDDB;

begin

 CDDB := TCDDB.Create;
 CDDB.ServerURL := 'http://freedb.freedb.org/~cddb/cddb.cgi'; // this is the server to access
 CDDB.ClientName := 'fpccddb'; // your application name that is passed to the server

end; </delphi>

First try using the MOTD (Message of the Day) command. <delphi> procedure TForm1.btnMOTDClick(Sender: TObject); var

 CDDB: TCDDB;
 cmd: TCDDBMOTD;

begin

 CDDB := TCDDB.Create;
 cmd := TCDDBMOTD.Create(CDDB);
 try
   cmd.Execute;
   Memo1.Lines.Assign(cmd.MOTDResponse.Response);
 finally
   cmd.Free;
   CDDB.Free;
 end;

end; </delphi>

You can get a list of supported categories using TCDDBListCategories <delphi> procedure TForm1.btnCategoriesClick(Sender: TObject); var

 CDDB: TCDDB;
 cmd: TCDDBListCategories;

begin

 CDDB := TCDDB.Create;
 cmd := TCDDBListCategories.Create(CDDB);
 try
   cmd.Execute;
   lbxCategories.Items.Assign(cmd.ListCategoriesResponse.Categories);
 finally
   cmd.Free;
   CDDB.Free;
 end;

end; </delphi>

This last example will query the database using the cdrom '/dev/cdrom'. The result is loaded into a TStringGrid named grdQueryResponse. <delphi> procedure TForm1.btnQueryClick(Sender: TObject); var

 CDDB: TCDDB;
 Cmd: TCDDBQuery;
 i: Integer;

begin

 CDDB := TCDDB.Create;
 Cmd := TCDDBQuery.Create(CDDB);
 try
   Cmd.Device := '/dev/cdrom'
   try
     Cmd.Execute;
   except on E:Exception do
     begin
       ShowMessage(E.Message);
       Exit;
     end;
   end;
 
   with Cmd.QueryResponse do
   begin
     for i := 0 to ResponseCount-1 do
     begin
       grdQueryResponse.RowCount := grdQueryResponse.RowCount+1;
       grdQueryResponse.Cells[0,i+1] := Artist[i];
       grdQueryResponse.Cells[1,i+1] := Album[i];
       grdQueryResponse.Cells[2,i+1] := Category[i];
       grdQueryResponse.Cells[3,i+1] := DiscID[i];
     end;
   end;
 finally
   cmd.Free;
   CDDB.Free
 end;

end;