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

Class: Net_CDDB

Source Location: /Net_CDDB-0.1.0/CDDB.php

Class Overview


Class for communication with CDDB/FreeDB.org servers


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 181]
Class for communication with CDDB/FreeDB.org servers


[ Top ]


Class Variables

$_backend =

[line 197]

CDDB protocol backend object
  • Access: protected

Type:   object


[ Top ]

$_buffer =

[line 237]

String buffer for calls to backend
  • Access: protected

Type:   string


[ Top ]

$_cdreader =

[line 205]

CD TOC reader backend object, reads TOC from a CD-ROM disc
  • Access: protected

Type:   array


[ Top ]

$_debug =

[line 189]

Status of debugging (enabled/disabled)
  • Access: protected

Type:   bool


[ Top ]

$_device =

[line 229]

Location of CD-ROM device ( /dev/acd0, etc. )
  • Access: protected

Type:   string


[ Top ]

$_email =

[line 253]

String email address to use for submitting CDDB records
  • Access: protected

Type:   string


[ Top ]

$_persist =

[line 213]

Connection should persist over multiple method calls or not (valid for HTTP only)
  • Access: protected

Type:   bool


[ Top ]

$_submit_server =

[line 245]

String server name for new submissions via HTTP
  • Access: protected

Type:   string


[ Top ]

$_sudo =

[line 221]

Whether or not to use sudo to access the CD-ROM device
  • Access: protected

Type:   bool


[ Top ]



Method Detail

Net_CDDB (Constructor)   [line 316]

Net_CDDB Net_CDDB( [string $protocol = 'cddbp://freedb.org:8880'], [string $cdreader = 'cddiscid:///dev/acd0'], [array $option_params = array()])

Construct a new CDDB object using the given backend/connection parameters

Create a new CDDB object which gives access to CDDB/FreeDB.org servers to allow a user to query the database for information about music CDs. You can use this class to submit discs to the FreeDB.org project or retrieve music CD information such as disc title, artist, track names, etc.

The class uses a driver architecture both for accessing remote CDDB servers and for reading the table of contents off a local CD-ROM drive so that new CDDB and CD-ROM access methods can be easily added in the future.

The class currently offers two different driver protocols to access this the CDDB/FreeDB.org database: CDDBP or HTTP.

    • cddbp:// - CDDBP/Telnet style protocol to query database (default)
    The class also offers a few different drivers to read the table of contents from the audio-CD in your CD/DVD drive:
    • cddiscid:// - Use the Linux/UNIX 'cd-discid' binary
    • cdparanoia:// - Use the Linux/UNIX 'cdparanoia' binary
    • test:// - Testing class to make sure things work like they should
    You may optionally provide an array of options parameters and CD TOC reader parameters to the class which specify options. Here are the valid array keys for each protocol:

    For CDDBP:

    • persist (defaults to false, set to true to reuse connection for multiple CDDB queries)
    • sudo (defaults to false, set to true if you want to execute the callback binary using sudo)
    • submit_uri (defaults to /~cddb/submit.cgi)
    For HTTP:
    • sudo (defaults to false, set to true if you want to execute the callback binary using sudo)
    • submit_uri (defaults to /~cddb/submit.cgi)
    1.  $params_cddbp = array(
    2.      'persist' => true,
    3.  );
    4.  
    5.  $cddb = new Net_CDDB('cddbp://my_username@freedb.org:8880''cddiscid:///dev/acd0'$params_cddbp);
    6.  //$cddb = new Net_CDDB('http://my_username@freedb.org:80/~cddb/cddb.cgi', 'cddiscid:///dev/acd0');
    7.  
    8.  print("\n\nSearching for the CD in the CD-ROM drive:\n");
    9.  $discs $cddb->searchDatabaseForCD();
    10.  print_r($discs);

    • Todo: Net_CDDB::listSupportedProtocols()
    • Todo: Sudo to a specific user? (use user key of cdreader dsn?)
    • Todo: Net_CDDB::listSupportedReaders()
    • Todo: Net_CDDB::addObserver()
    • Access: public

    Parameters:

    string   $protocol   —  A DSN string specifying the protocol and server to connect to (i.e.: cddbp://freedb.org:8880)
    string   $cdreader   —  A DSN string specifying which CD-ROM TOC reader to use (i.e.: cddiscid:///dev/acd0)
    array   $option_params   —  An array of options / connection parameters

    [ Top ]

    calculateDiscId   [line 949]

    string calculateDiscId( array $track_offsets, int $length, [bool $query = false])

    Calculate a disc ID based on the track offsets and the disc length
    • Return: 8-character disc ID value

    Parameters:

    array   $track_offsets   —  The offsets of the tracks on the CD
    int   $length   —  The total number of seconds for the disc
    bool   $query   — 

    [ Top ]

    calculateDiscIdForCD   [line 733]

    string calculateDiscIdForCD( [string $device = null])

    Calculate the 8-byte disc id from the CD-ROM drive

    Parameters:

    string   $device   — 

    [ Top ]

    calculateLengthForCD   [line 782]

    integer calculateLengthForCD( [string $device = null])

    Calculate the length in seconds of the disc in the CD-ROM drive
    • Access: public

    Parameters:

    string   $device   — 

    [ Top ]

    calculateTrackOffsetsForCD   [line 753]

    array calculateTrackOffsetsForCD( [string $device = null])

    Calculate the track offsets from the TOC of the disc in the CD-ROM drive

    Parameters:

    string   $device   — 

    [ Top ]

    connect   [line 398]

    bool connect( )

    Establish connection to CDDB server

    You *do not* need to manually call this, the other public methods of this class will ensure a connection is established before querying the database on their own. This is provided as a convience method just in case someone needs it.

    • Access: public

    [ Top ]

    debug   [line 365]

    void debug( bool $true_or_false)

    Enables or disables debugging ( prints out all responses/requests )
    • Access: public

    Parameters:

    bool   $true_or_false   — 

    [ Top ]

    disconnect   [line 414]

    bool disconnect( )

    Disconnect from CDDB server
    • Access: public

    [ Top ]

    getDetails   [line 710]

    object getDetails( object $disc)

    Fill a CDDBDisc object with detailed information about the disc

    After searching the CDDB database for discs matching yours by discid and track offsets, you can use this function to get detailed information about one of the CDDBDisc objects. This function will fill and return the CDDBDisc object with information about track offsets, song titles, etc.

    • Access: public

    Parameters:

    object   $disc   — 

    [ Top ]

    getDetailsByDiscId   [line 659]

    object getDetailsByDiscId( string $genre, string $discid, [ $obj = true])

    Get CD information by genre and disc id value

    Searches the CDDB database for a CD matching the given genre and discid and returns a CDDBDisc object containing information for that CD. Returns false if the disc was not found in the database or an error occurs.


    Parameters:

    string   $genre   — 
    string   $discid   — 
       $obj   — 

    [ Top ]

    getGenres   [line 430]

    array getGenres( )

    Retrieve list of genre's from CDDB server
    • Access: public

    [ Top ]

    help   [line 1150]

    string help( [string $cmd = ''], [string $subcmd = ''])

    Get protocol help from the CDDB server
    • Access: public

    Parameters:

    string   $cmd   — 
    string   $subcmd   — 

    [ Top ]

    motd   [line 1164]

    string motd( )

    Get the message of the day from the CDDB server
    • Access: public

    [ Top ]

    searchDatabase   [line 849]

    object searchDatabase( array $track_offsets, integer $length, [ $obj = true])

    Search and return CDDBDisc objects for CDs matching given length/offsets
    • Access: public

    Parameters:

    array   $track_offsets   — 
    integer   $length   — 
       $obj   — 

    [ Top ]

    searchDatabaseForCD   [line 809]

    array searchDatabaseForCD( [string $device = null])

    Search and return CDDBDisc objects matching the disc in the CD-ROM drive
    • Access: public

    Parameters:

    string   $device   — 

    [ Top ]

    searchDatabaseWithRawQuery   [line 886]

    array searchDatabaseWithRawQuery( string $query, [ $obj = true])

    Utility method to search for CDDB discs using a raw 'cddb query ...' command

    This is provided as a utility method for anyone who might want to search the CDDB database with a raw CDDB query command. It returns an array of CDDBDisc objects which match the query.

    1.  // CDDB queries look like this:
    2.  // cddb query [discid] [num_tracks] [offset_1] [offset_2] ... [offset_n] [length]
    3.  // Replace [discid] with the 8-char discid, [num_tracks] with the number of tracks, [offset_*] with the track offsets, and [length] with the total length of the CD in seconds
    4.  $query "cddb query 50dd30f 15 150 21052 43715 58057 71430 92865 117600 131987 150625 163292 181490 195685 210197 233230 249257 3541";
    5.  print_r($cddbsearchDatabaseWithRawQuery($query));

    • Access: public

    Parameters:

    string   $query   — 
       $obj   — 

    [ Top ]

    sites   [line 1259]

    array sites( )

    Get a list of CDDB mirrors
    • Access: public

    [ Top ]

    statistics   [line 1178]

    array statistics( )

    Get CDDB database server statistics
    • Access: public

    [ Top ]

    submitDisc   [line 993]

    bool submitDisc( object $obj, [string $email = null], [bool $test = false])

    Submit a revised/new Net_CDDB_Disc object to the FreeDB.org database

    Note that at this time only submission via HTTP is supported. The only other option is SMTP, which may be supported in the future. This method uses the HTTP_Request class to make the request. I chose to include the HTTP_Request class here instead of globally because most users will use the Net_CDDB package for read-only access to CDDB servers, and thus won't be using this method.

    • Access: public
    • Uses: HTTP_Request

    Parameters:

    object   $obj   —  A CDDBDisc object containing CD information
    string   $email   — 
    bool   $test   —  Whether or not this should be a test submission

    [ Top ]

    version   [line 1289]

    string version( )

    Get the CDDB server version string
    • Access: public

    [ Top ]

    _createProtocol   [line 1093]

    object _createProtocol( $dsn, $options, string $type, array $params)

    Create a protocol instance of the given type with the given parameters

    Creates a protocol object instance of a given type by protocol type. The array of connection parameters will be passed directly to the protocol instance.


    Parameters:

    string   $type   — 
    array   $params   — 
       $dsn   — 
       $options   — 

    [ Top ]

    _createReader   [line 1124]

    object _createReader( string $type, array $params)

    Create a cd reader instance of a given type with the parameters

    Parameters:

    string   $type   — 
    array   $params   — 

    [ Top ]

    _debug   [line 379]

    void _debug( string $msg)

    Prints/logs debugging messages
    • Access: protected

    Parameters:

    string   $msg   —  The debugging message

    [ Top ]

    _parseRecord   [line 518]

    array _parseRecord( string $str)

    Parse a CDDB style database record

    Parameters:

    string   $str   — 

    [ Top ]

    _parseResult   [line 614]

    array _parseResult( string $str)

    Parse a result string returned by a CDDB query into an array

    Parameters:

    string   $str   — 

    [ Top ]

    _readLine   [line 488]

    string _readLine( )

    Read a line from the response buffer
    • Access: protected

    [ Top ]

    _readResponseStatus   [line 476]

    int _readResponseStatus( )

    Reads the return status for the last command ( 200, 210, 500, etc. )
    • Access: protected

    [ Top ]

    _send   [line 457]

    void _send( string $query)

    Send a query to the backend and retrieve the result from the query
    • Access: protected

    Parameters:

    string   $query   —  The command string to send

    [ Top ]


    Documentation generated on Mon, 11 Mar 2019 14:39:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.