com.tuneology.avm
Class FreeDb

java.lang.Object
  |
  +--com.tuneology.avm.FreeDb

public class FreeDb
extends java.lang.Object

An API for the FreeDb song database.

This API is single threaded; if you want to use it in a multithreaded program, create an instance of the FreeDb object for each thread.

Version:
$Id: FreeDb.java,v 1.12 2003/07/10 19:52:12 xnarf Exp $
Author:
Fran Taylor

Inner Class Summary
static class FreeDb.Site
          A class to represent a FreeDb server site.
 
Constructor Summary
FreeDb(java.lang.String host, int port, java.lang.String appName, java.lang.String version, java.lang.String url, java.lang.String encoding, boolean useHttp, java.lang.String proxyHost, int proxyPort)
          Create a FreeDb object, ready to make queries.
 
Method Summary
 void close()
           
 void get(java.lang.String categStr, DiscInfo ent)
          Fills in information about the album, given its discid key,
 java.lang.String[] getCateg(java.lang.String trackStr)
          Returns a list of the possible entries for the disc.
static java.lang.String getDefaultFreedbHost()
           
static java.lang.String getDefaultFreedbUrl()
           
static java.lang.String getHexId(int discId)
          Translated a discid value from an integer to an 8-digit hex number .
 java.lang.String getLogOutput()
          Returns the latest query and the result returned.
 java.lang.String getMotd()
          Returns the server's message of the day.
static java.lang.String getSepChar(DiscInfo tracks)
          Returns a good guess for the character that separates the artist from the title in the information received from freedb regarding multi-artist CDs.
 FreeDb.Site[] getServers()
          Returns a list of available servers.
 java.lang.String getServerStatus()
          Returns the server's status.
 java.lang.String getServerVersion()
          Returns the server's version information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreeDb

public FreeDb(java.lang.String host,
              int port,
              java.lang.String appName,
              java.lang.String version,
              java.lang.String url,
              java.lang.String encoding,
              boolean useHttp,
              java.lang.String proxyHost,
              int proxyPort)
Create a FreeDb object, ready to make queries.
Parameters:
host - The hostname of the freedb server. If null, uses "freedb.freedb.org"
port - The port number to use, or the default port if -1 is specified. The default port for http service is 80, and the default port for TCP service is 8880.
appName - The name of the application.
version - The version of the application.
url - The URL to use for the request. If null, uses "/~cddb/cddb.cgi".
encoding - The name of the character encoding to use when translating characters in FreeDb responses. If null, the default encoding is used.
useHttp - If true, uses the http service. If false, uses the TCP service.
proxyHost - The http proxy host (optional).
proxyPort - The http proxy port number.
Method Detail

getHexId

public static java.lang.String getHexId(int discId)
Translated a discid value from an integer to an 8-digit hex number .
Parameters:
discId - the integer value.
Returns:
a hex string representing the value.

getCateg

public java.lang.String[] getCateg(java.lang.String trackStr)
                            throws java.io.IOException,
                                   java.lang.InterruptedException,
                                   FreeDbException
Returns a list of the possible entries for the disc. The user chooses one and then get() is called to fetch the cddb data.
Parameters:
trackStr - The list of tracks, formatted as required for freedb.
Returns:
The list of category entries for the disc.
Throws:
java.io.IOException - if there is an error reading from the network.
java.lang.InterruptedException - if the thread is interrupted.
FreeDbException - if an error is returned by FreeDb.

getServers

public FreeDb.Site[] getServers()
                         throws java.io.IOException,
                                java.lang.InterruptedException,
                                FreeDbException
Returns a list of available servers.
Returns:
An array containing the available servers.
Throws:
java.io.IOException - if there is an error reading from the network.
java.lang.InterruptedException - if the thread is interrupted.
FreeDbException - if an error is returned by FreeDb.

get

public void get(java.lang.String categStr,
                DiscInfo ent)
         throws java.io.IOException,
                java.lang.InterruptedException,
                FreeDbException
Fills in information about the album, given its discid key,
Parameters:
categ - the category string.
ent - the entry to fill in.
Throws:
java.io.IOException - if there is an error reading from the network.
java.lang.InterruptedException - if the thread is interrupted.
FreeDbException - if an error is returned by FreeDb.

getMotd

public java.lang.String getMotd()
                         throws java.lang.Exception
Returns the server's message of the day.
Returns:
the server's message of the day.
Throws:
java.lang.Exception -  

getServerStatus

public java.lang.String getServerStatus()
                                 throws java.lang.Exception
Returns the server's status.
Returns:
the server's status.
Throws:
java.lang.Exception -  

getServerVersion

public java.lang.String getServerVersion()
                                  throws java.lang.Exception
Returns the server's version information.
Returns:
the server's version information.
Throws:
java.lang.Exception -  

getSepChar

public static java.lang.String getSepChar(DiscInfo tracks)
Returns a good guess for the character that separates the artist from the title in the information received from freedb regarding multi-artist CDs.
Parameters:
tracks - the array of tracks.
Returns:
the separator character.

getLogOutput

public java.lang.String getLogOutput()
Returns the latest query and the result returned.
Returns:
the output of the network request.

getDefaultFreedbHost

public static java.lang.String getDefaultFreedbHost()

getDefaultFreedbUrl

public static java.lang.String getDefaultFreedbUrl()

close

public void close()
           throws java.io.IOException