Net_CDDB
[ class tree: Net_CDDB ] [ index: Net_CDDB ] [ all elements ]

Source for file CDDB_client_example.php

Documentation is available at CDDB_client_example.php

  1. <?php
  2.  
  3. /**
  4.  * Example file showing Net_CDDB_Client usage
  5.  * 
  6.  * @author Keith Palmer <Keith@UglySlug.com>
  7.  * @category Net
  8.  * @package Net_CDDB
  9.  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  10.  */
  11.  
  12. header('Content-type: text/plain');
  13.  
  14. require_once 'Net/CDDB/Client.php';
  15.  
  16. $params_cddbp = array(
  17.     'host' => 'bsdslug'
  18.     'persist' => true
  19.     );
  20.  
  21. $cddb_cddbp = new Net_CDDB_Client('cddbp://keithpalmerjr@freedb.org:8880''test:///dev/acd0'$params_cddbp);
  22.  
  23. $params_http = array(
  24.     'host' => 'bsdslug'
  25.     );
  26.  
  27. $cddb_http = new Net_CDDB_Client('http://keithpalmerjr@freedb.org:80''test:///dev/acd0'$params_http);
  28.  
  29. $params_filesystem = array();
  30. $cddb_filesystem = new Net_CDDB_Client('filesystem:///Users/keith/Sites/Net/docs/FreeDB''test:///dev/acd0'$params_filesystem);
  31.  
  32. $cddb_mdb2 = new Net_CDDB_Client('mdb2.mysql://root@localhost/freedb''test:///dev/acd0');
  33.  
  34. print("\n\nHTTP PROTOCOL RESPONSE:\n\n")flush();
  35. print(Net_CDDB_example($cddb_http));
  36.     
  37. print("\n\nCDDBP PROTOCOL RESPONSE:\n\n")flush();
  38. //print(Net_CDDB_example($cddb_cddbp));
  39. /*
  40.  * You can only use the filesystem one if you make sure that the configuration 
  41.  * DSNs about point to a valid local CDDB database dump
  42.  */
  43. print("\n\nFILESYSTEM PROTOCOL RESPONSE:\n\n")flush();
  44. //print(Net_CDDB_example($cddb_filesystem));
  45. /*
  46.  * You can only use the MDB2 one if you have an SQL database loaded with 
  47.  * the FreeDB information
  48.  */
  49. print("\n\nMDB2 PROTOCOL RESPONSE:\n\n")flush();
  50. //print(Net_CDDB_example($cddb_mdb2));
  51.  
  52. function Net_CDDB_example($cddb)
  53. {
  54.     print("Searching for the CD in the CD-ROM drive:\n");
  55.     $discs $cddb->searchDatabaseForCD();
  56.     print_r($discs);
  57.     
  58.     print("\n\nDetails for the first CD from the search are: \n");
  59.     $details $cddb->getDetails($discs[0]);
  60.     print_r($details);
  61.     
  62.     print("\n\nDumping that disc back to a string looks like this: \n");
  63.     print($details->toString());
  64.     
  65.     print("\n\nDoing a test submit of that disc back to the CDDB server: \n");
  66.     //$cddb->submitDisc($details, 'keith@uglyslug.com', true);
  67.  
  68.     print("\n\nThe CDDB music genres are: \n");
  69.     print_r($cddb->getCategories());
  70.  
  71.     print("\n\nThe details for disk id: 'rock' '7708d309' are: \n");
  72.     print_r($cddb->getDetailsByDiscId('rock''7708d309'false));
  73.     
  74.     print("\n\nThe details for disk id: 'misc' '83085c0b' are: \n");
  75.     $disc $cddb->getDetailsByDiscId('misc''83085c0b');
  76.     print_r($disc);
  77.     
  78.     print("\n\nThe length of the first three tracks on that disc are: \n");
  79.     print('    1. ' $disc->getTrackTitle(0': ' $disc->getTrackLength(0true' (' $disc->getTrackLength(0")\n");
  80.     print('    2. ' $disc->getTrackTitle(1': ' $disc->getTrackLength(1true' (' $disc->getTrackLength(1")\n");
  81.     print('    3. ' $disc->getTrackTitle(2': ' $disc->getTrackLength(2true' (' $disc->getTrackLength(2")\n");
  82.     
  83.     print("\n\nThe length of the last track is: \n");
  84.     $num_tracks $disc->numTracks();
  85.     print('    ' $num_tracks '. ' $disc->getTrackTitle($num_tracks - 1': ' $disc->getTrackLength($num_tracks - 1true' (' $disc->getTrackLength($num_tracks - 1")\n");
  86.     
  87.     print("\n\nThe length of the whole disc is: \n");
  88.     print('    Disc length: ' $disc->getDiscLength(true"\n");
  89.     
  90.     print("\n\nThe disc id for this record is: \n");
  91.     $arr_track_offsets = array(
  92.         150
  93.         21052
  94.         43715
  95.         58057,
  96.         71430
  97.         92865
  98.         117600
  99.         131987
  100.         150625
  101.         163292
  102.         181490
  103.         195685
  104.         210197
  105.         233230
  106.         249257
  107.         );
  108.     print_r($cddb->calculateDiscId($arr_track_offsets3541));
  109.     
  110.     print("\n\nDiscs which match the description of that record are: \n");
  111.     $discs $cddb->searchDatabase($arr_track_offsets3541);
  112.     print_r($discs);
  113.     
  114.     print("\n\nLet's see a dump of that first disc: \n");
  115.     $disc $cddb->getDetails($discs[0]);
  116.     print($disc->toString());
  117.     
  118.     print("\n\nCDDB server message of the day: \n");
  119.     print($cddb->motd());
  120.     
  121.     print("\n\nCDDB server protocol help: \n");
  122.     print($cddb->help());
  123.     
  124.     print("\n\nCDDB server version is: \n");
  125.     print($cddb->version());
  126.     
  127.     print("\n\nCDDB server statistics look like this: \n");
  128.     print_r($cddb->statistics());
  129.     
  130.     print("\n\nCDDB server site list looks like this: \n");
  131.     print_r($cddb->sites());
  132.     
  133.     print("\n\n");
  134. }
  135.  
  136. ?>

Documentation generated on Sun, 25 Feb 2007 14:00:10 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.