CDDB: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: CDDB
| Old | New | Line | |
|---|---|---|---|
| 1 | + | > **Warning:** The source mentioned here is no longer available. However FPC itself provides a unit for CDDB as [fpcddb](https://www.freepascal.org/daily/packages/cdrom/fpcddb/index.html). An article that explains its use is available [here](https://www.freepascal.org/~michael/articles/cddb/cddb.pdf). | |
| 2 | + | ||
| 3 | + | > **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/). | |
| 4 | + | ||
| 5 | + | ### About | |
| 6 | + | ||
| 7 | + | *CDDB* is a simple unit for accessing CD track information from CDDB/FreeDB. There is little documentation but sample code is provided below. | |
| 8 | + | ||
| 9 | + | ### License | |
| 10 | + | ||
| 11 | + | [BSD](http://www.opensource.org/licenses/bsd-license.php) | |
| 12 | + | ||
| 13 | + | ### Download | |
| 14 | + | ||
| 15 | + | The latest can be found [here](http://www.simmonsclan.net/fpc/cddb.pas) - This link appears to be dead. Is there an active copy of this somewhere? | |
| 16 | + | ||
| 17 | + | ### Dependencies / System Requirements | |
| 18 | + | ||
| 19 | + | - Linux | |
| 20 | + | - Synapse httpsend unit | |
| 21 | + | ||
| 22 | + | ### Installation | |
| 23 | + | ||
| 24 | + | Copy the unit into the source directory for your project. | |
| 25 | + | ||
| 26 | + | ### Use | |
| 27 | + | ||
| 28 | + | 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](http://freedb.freedb.org). | |
| 29 | + | ||
| 30 | + | ``` pascal | |
| 31 | + | procedure CreateCDDB; | |
| 32 | + | var | |
| 33 | + | CDDB: TCDDB; | |
| 34 | + | begin | |
| 35 | + | CDDB := TCDDB.Create; | |
| 36 | + | CDDB.ServerURL := 'http://freedb.freedb.org/~cddb/cddb.cgi'; // this is the server to access | |
| 37 | + | CDDB.ClientName := 'fpccddb'; // your application name that is passed to the server | |
| 38 | + | end; | |
| 39 | + | ``` | |
| 40 | + | ||
| 41 | + | First try using the MOTD (Message of the Day) command. | |
| 42 | + | ||
| 43 | + | ``` pascal | |
| 44 | + | procedure TForm1.btnMOTDClick(Sender: TObject); | |
| 45 | + | var | |
| 46 | + | CDDB: TCDDB; | |
| 47 | + | cmd: TCDDBMOTD; | |
| 48 | + | begin | |
| 49 | + | CDDB := TCDDB.Create; | |
| 50 | + | cmd := TCDDBMOTD.Create(CDDB); | |
| 51 | + | try | |
| 52 | + | cmd.Execute; | |
| 53 | + | Memo1.Lines.Assign(cmd.MOTDResponse.Response); | |
| 54 | + | finally | |
| 55 | + | cmd.Free; | |
| 56 | + | CDDB.Free; | |
| 57 | + | end; | |
| 58 | + | end; | |
| 59 | + | ``` | |
| 60 | + | ||
| 61 | + | You can get a list of supported categories using TCDDBListCategories | |
| 62 | + | ||
| 63 | + | ``` pascal | |
| 64 | + | procedure TForm1.btnCategoriesClick(Sender: TObject); | |
| 65 | + | var | |
| 66 | + | CDDB: TCDDB; | |
| 67 | + | cmd: TCDDBListCategories; | |
| 68 | + | begin | |
| 69 | + | CDDB := TCDDB.Create; | |
| 70 | + | cmd := TCDDBListCategories.Create(CDDB); | |
| 71 | + | try | |
| 72 | + | cmd.Execute; | |
| 73 | + | lbxCategories.Items.Assign(cmd.ListCategoriesResponse.Categories); | |
| 74 | + | finally | |
| 75 | + | cmd.Free; | |
| 76 | + | CDDB.Free; | |
| 77 | + | end; | |
| 78 | + | end; | |
| 79 | + | ``` | |
| 80 | + | ||
| 81 | + | This last example will query the database using the cdrom '/dev/cdrom'. The result is loaded into a TStringGrid named grdQueryResponse. | |
| 82 | + | ||
| 83 | + | ``` pascal | |
| 84 | + | procedure TForm1.btnQueryClick(Sender: TObject); | |
| 85 | + | var | |
| 86 | + | CDDB: TCDDB; | |
| 87 | + | Cmd: TCDDBQuery; | |
| 88 | + | i: Integer; | |
| 89 | + | begin | |
| 90 | + | CDDB := TCDDB.Create; | |
| 91 | + | Cmd := TCDDBQuery.Create(CDDB); | |
| 92 | + | try | |
| 93 | + | Cmd.Device := '/dev/cdrom' | |
| 94 | + | try | |
| 95 | + | Cmd.Execute; | |
| 96 | + | except on E:Exception do | |
| 97 | + | begin | |
| 98 | + | ShowMessage(E.Message); | |
| 99 | + | Exit; | |
| 100 | + | end; | |
| 101 | + | end; | |
| 102 | + | ||
| 103 | + | with Cmd.QueryResponse do | |
| 104 | + | begin | |
| 105 | + | for i := 0 to ResponseCount-1 do | |
| 106 | + | begin | |
| 107 | + | grdQueryResponse.RowCount := grdQueryResponse.RowCount+1; | |
| 108 | + | grdQueryResponse.Cells[0,i+1] := Artist[i]; | |
| 109 | + | grdQueryResponse.Cells[1,i+1] := Album[i]; | |
| 110 | + | grdQueryResponse.Cells[2,i+1] := Category[i]; | |
| 111 | + | grdQueryResponse.Cells[3,i+1] := DiscID[i]; | |
| 112 | + | end; | |
| 113 | + | end; | |
| 114 | + | finally | |
| 115 | + | cmd.Free; | |
| 116 | + | CDDB.Free | |
| 117 | + | end; | |
| 118 | + | end; | |
| 119 | + | ``` | |
| 120 | + | ||
| 121 | + | --- | |
| 122 | + | *From the Free Pascal wiki, page "CDDB", as it stood on 2020-12-02 after a change by PascalDragon, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 123 | + | Category: Components |
