Difference between revisions of "CDDB"

From Free Pascal wiki
Jump to navigationJump to search
(Added a warning regarding FreeDB no longer existing)
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{CDDB}}
 
{{CDDB}}
 +
 +
{{Warning|The source mentioned here is no longer available. However FPC itself provides a unit for CDDB as [https://www.freepascal.org/daily/packages/cdrom/fpcddb/index.html fpcddb]. An article that explains its use is available [https://www.freepascal.org/~michael/articles/cddb/cddb.pdf here]. }}
 +
 +
{{Warning|The CDDB service on FreeDB is no longer available. An alternative is provided by GNUDB as [http://gnudb.gnudb.org/ http://gnudb.gnudb.org].}}
 +
  
 
=== About ===
 
=== About ===
Line 8: Line 13:
 
   
 
   
 
=== 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 ===
Line 19: Line 24:
 
=== Use ===
 
=== 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 [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>
+
 
 +
<syntaxhighlight lang="pascal">
 
procedure CreateCDDB;
 
procedure CreateCDDB;
 
var
 
var
Line 27: Line 33:
 
   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;  
+
end;</syntaxhighlight>
</delphi>
 
  
 
First try using the MOTD (Message of the Day) command.
 
First try using the MOTD (Message of the Day) command.
<delphi>
+
 
 +
<syntaxhighlight lang="pascal">
 
procedure TForm1.btnMOTDClick(Sender: TObject);
 
procedure TForm1.btnMOTDClick(Sender: TObject);
 
var
 
var
Line 46: Line 52:
 
     CDDB.Free;
 
     CDDB.Free;
 
   end;
 
   end;
end;
+
end;</syntaxhighlight>
</delphi>
 
  
 
You can get a list of supported categories using TCDDBListCategories
 
You can get a list of supported categories using TCDDBListCategories
<delphi>
+
 
 +
<syntaxhighlight lang="pascal">
 
procedure TForm1.btnCategoriesClick(Sender: TObject);
 
procedure TForm1.btnCategoriesClick(Sender: TObject);
 
var
 
var
Line 65: Line 71:
 
     CDDB.Free;
 
     CDDB.Free;
 
   end;
 
   end;
end;
+
end;</syntaxhighlight>
</delphi>
 
  
 
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>
+
 
 +
<syntaxhighlight lang="pascal">
 
procedure TForm1.btnQueryClick(Sender: TObject);
 
procedure TForm1.btnQueryClick(Sender: TObject);
 
var
 
var
Line 104: Line 110:
 
     CDDB.Free
 
     CDDB.Free
 
   end;
 
   end;
end;
+
end;</syntaxhighlight>
 +
 
 +
[[Category:Components]]

Latest revision as of 10:39, 2 December 2020

English (en)

Warning-icon.png

Warning: The source mentioned here is no longer available. However FPC itself provides a unit for CDDB as fpcddb. An article that explains its use is available here.

Warning-icon.png

Warning: The CDDB service on FreeDB is no longer available. An alternative is provided by GNUDB as http://gnudb.gnudb.org.


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;