/// <summary>Decodes the disc informations sent by the CDDB server</summary> /// <param name="line">Line containing the disc informations</param> /// <param name="startIndex"> /// Characer Index at which the disc informations begin /// </param> /// <returns>The decoded CDDB disc informations</returns> private Cddb.Disc decodeDisc(string line, int startIndex) { // Locate where in the string the current protocol level starts int categoryEndIndex = -1; bool hasCategory = (line.Length >= startIndex) && ((categoryEndIndex = line.IndexOf(SP, startIndex)) != -1); if(!hasCategory) { throw makeBadResponseException("missing category name in query result"); } // Locate where in the string the current protocol level starts int discIdEndIndex = -1; bool hasDiscId = (line.Length >= categoryEndIndex + 1) && ((discIdEndIndex = line.IndexOf(SP, categoryEndIndex + 1)) != -1); if(!hasDiscId) { throw makeBadResponseException("missing disc id in query result"); } bool hasDiscTitle = (line.Length >= discIdEndIndex + 1) && (line[discIdEndIndex] == SP); if(!hasDiscTitle) { throw makeBadResponseException("missing disc title in query result"); } string discId = line.Substring( categoryEndIndex + 1, discIdEndIndex - categoryEndIndex - 1 ); Cddb.DTitle artistAndAlbum = Cddb.SplitDiscTitle( line.Substring(discIdEndIndex + 1) ); return new Cddb.Disc( line.Substring(startIndex, categoryEndIndex - startIndex), Convert.ToInt32(discId, 16), artistAndAlbum.Artist, artistAndAlbum.Title ); }
/// <summary> /// Queries the AccurateRip database for the CRCs of the tracks on the specified CD /// </summary> /// <param name="totalLengthSeconds"> /// Total length of the CD (from the beginning of the first track to the end of the /// last track) in seconds /// </param> /// <param name="trackOffsetsSeconds"> /// Offsets of the individual tracks on the CD in seconds /// </param> /// <returns></returns> public static Request <CdInfo[]> QueryDatabase( int totalLengthSeconds, int[] trackOffsetsSeconds ) { try { // Calculate the three IDs required by a query to the AccurateRip database. AccurateRip // improves (marginally) on the flawed CDDB disc id by providing two additional ids, // however, this doesn't hurt AccurateRip nearly as much as it would a CDDB service. int discId1 = CalculateDiscId1(trackOffsetsSeconds); int discId2 = CalculateDiscId2(trackOffsetsSeconds); int cddbDiscId = Cddb.CalculateDiscId(totalLengthSeconds, trackOffsetsSeconds); int trackCount = trackOffsetsSeconds.Length; return(QueryDatabase(discId1, discId2, cddbDiscId, trackCount)); } catch (Exception exception) { return(Request <CdInfo[]> .CreateFailedDummy(exception)); } }
/// <summary>Sends the query to the CDDB server</summary> private void sendQuery() { StringBuilder builder = new StringBuilder(192); // Build the initial query string consisting of the command, CDDB disc id // and the number of tracks on the CD builder.AppendFormat( "cddb query {0:x8} {1} ", Cddb.CalculateDiscId(this.discLengthSeconds, this.trackOffsetsSeconds), this.trackOffsetsSeconds.Length ); // Append the start offsets for(int index = 0; index < this.trackOffsetsSeconds.Length; ++index) { builder.AppendFormat("{0} ", this.trackOffsetsSeconds[index] * 75); } builder.Append(this.discLengthSeconds); this.protocol.SendLine(builder.ToString(), 5000); }