Difference between revisions of "CDDB"

From Free Pascal wiki
Jump to navigationJump to search
(category)
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 20: Line 20:
 
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 [http://freedb.freedb.org FreeDB].
 
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 [http://freedb.freedb.org FreeDB].
  
<delphi>procedure CreateCDDB;
+
<syntaxhighlight>procedure CreateCDDB;
 
var
 
var
 
   CDDB: TCDDB;
 
   CDDB: TCDDB;
Line 27: Line 27:
 
   CDDB.ServerURL := 'http://freedb.freedb.org/~cddb/cddb.cgi'; // this is the server to access
 
   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
 
   CDDB.ClientName := 'fpccddb'; // your application name that is passed to the server
end;</delphi>
+
end;</syntaxhighlight>
  
 
First try using the MOTD (Message of the Day) command.
 
First try using the MOTD (Message of the Day) command.
<delphi>procedure TForm1.btnMOTDClick(Sender: TObject);
+
<syntaxhighlight>procedure TForm1.btnMOTDClick(Sender: TObject);
 
var
 
var
 
   CDDB: TCDDB;
 
   CDDB: TCDDB;
Line 44: Line 44:
 
     CDDB.Free;
 
     CDDB.Free;
 
   end;
 
   end;
end;</delphi>
+
end;</syntaxhighlight>
  
 
You can get a list of supported categories using TCDDBListCategories
 
You can get a list of supported categories using TCDDBListCategories
<delphi>procedure TForm1.btnCategoriesClick(Sender: TObject);
+
<syntaxhighlight>procedure TForm1.btnCategoriesClick(Sender: TObject);
 
var
 
var
 
   CDDB: TCDDB;
 
   CDDB: TCDDB;
Line 61: Line 61:
 
     CDDB.Free;
 
     CDDB.Free;
 
   end;
 
   end;
end;</delphi>
+
end;</syntaxhighlight>
  
 
This last example will query the database using the cdrom '/dev/cdrom'. The result is loaded into a TStringGrid named grdQueryResponse.
 
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);
+
<syntaxhighlight>procedure TForm1.btnQueryClick(Sender: TObject);
 
var
 
var
 
   CDDB: TCDDB;
 
   CDDB: TCDDB;
Line 98: Line 98:
 
     CDDB.Free
 
     CDDB.Free
 
   end;
 
   end;
end;</delphi>
+
end;</syntaxhighlight>
  
 
[[Category:Components]]
 
[[Category:Components]]

Revision as of 14:56, 24 March 2012

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.

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;

First try using the MOTD (Message of the Day) command.

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;

You can get a list of supported categories using TCDDBListCategories

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;

This last example will query the database using the cdrom '/dev/cdrom'. The result is loaded into a TStringGrid named grdQueryResponse.

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;