Search

Advertising

Home Downloads Components

Components

Folder Path: \ Components \

File: CDDB Protocol Client in C#

file.png
Uploaded:
April.06.09
Modified:
June.21.10
File Size:
70 KB
Downloads:
556
Version
1.0

An asynchronous CDDB protocol client written in C#. Connects to CDDB servers using the CDDB protocol instead of HTTP and supports protocol level 1-6 (including UTF-8 text). Can query the server for a list of matching albums and decode the CDDB database entry when a specific album is queried.

Details

I needed a CDDB client to be able to verify my audio collection (ripped to the FLAC format) against the AccurateRip database because I ripped my CDs as individual tracks, so the exact track offsets of the songs were lost.

There seemed to be no C# implementations of the CDDB protocol available, so I rolled my own!

Because accessing the web can take time, this code makes uses of my asynchronous transaction API. All methods return Requests which you can wait on (using .Join()) or register to be notified when they finish.

First, you need to connect to a CDDB server. Nuclex.Cddb uses freedb by default:

// Credentials with which we are going to log in to the server
Cddb.Credentials credentials = new Cddb.Credentials(
  "johndoe",
  "abc.fubar.com",
  "testing",
  "v0.0PL0"
);

// Log in to a random freedb server
CddbConnection connection = Cddb.Connect(credentials).Join();

Next, you should upgrade the protocol level to get UTF-8 support:

connection.ChangeProtocolLevel(newLevel).Join();

Then you can query the server for the album of your choice:

// Query the server for all albums which might match our description
Request<Cddb.Disc[]> queryRequest = connection.Query(
  totalPlayingTime, trackOffsets
);
Cddb.Disc[] matchingDiscs = queryRequest.Join();

// Read the CDDB database entry of the first returned album
Cddb.DatabaseEntry entry = connection.Read(
  matchingDiscs[0].Category, matchingDiscs[0].DiscId
).Join();

// Print out some informations about the album
Console.WriteLine("\tArtist name: " + entry.Artist);
Console.WriteLine("\tAlbum title: " + entry.Album);
Console.WriteLine("\tProduction year: " + entry.Year.ToString());
Console.WriteLine("\tLength: " + entry.DiscLengthSeconds.ToString() + " seconds");

Simple, isn't it?

Features

  • Calculates CDDB disc ids from track offset lists
  • Connects to CDDB servers using the CDDB protocol (not HTTP)
  • Support for CDDB protocol levels 1-6 (including UTF-8 text)
  • Lists album categories supported by a CDDB server
  • Queries CDDB servers for any albums matching a list of track offsets
  • Reads and decodes CDDB database entries so they can be processed by code
  • Specific exceptions for each error and capturing of error messages from the server

The CDDB protocol client is part of the Nuclex.Audio library from the Nuclex Framework. You can find the most recent release of the code on the framework's CodePlex site: http://nuclexframework.codeplex.com/



Joomla Template by Joomlashack