diff --git a/src/bin/cddb_lookup/cddb_server.cpp b/src/bin/cddb_lookup/cddb_server.cpp index a4baab6ffc..381a192bd4 100644 --- a/src/bin/cddb_lookup/cddb_server.cpp +++ b/src/bin/cddb_lookup/cddb_server.cpp @@ -244,43 +244,36 @@ CDDBServer::Read(const BString& category, const BString& cddbID, BString index; prefix.MoveInto(index, 6, prefix.Length() - 6); - TrackData* trackData = new TrackData; - char* firstInvalid; errno = 0; uint32 track = strtoul(index.String(), &firstInvalid, 10); - if ((errno == ERANGE && - (track == (uint32)LONG_MAX || track == (uint32)LONG_MIN)) - || (errno != 0 && track == 0)) { + if (errno != 0 || track > 99) { // Track out of range. printf("Track out of range: %s\n", index.String()); - delete trackData; return B_ERROR; } if (firstInvalid == index.String()) { printf("Invalid track: %s\n", index.String()); - delete trackData; return B_ERROR; } - trackData->trackNumber = track; - + BString trackArtist; int32 pos = line.FindFirst(" / "); if (pos >= 0 && artist.ICompare("Various") == 0) { // Disk is set to have a compilation artist and // we have track specific artist information. - line.MoveInto(trackData->artist, 0, pos); + line.MoveInto(trackArtist, 0, pos); // Move artist information from line to artist. line.Remove(0, 3); // Remove " / " from line. } else { - trackData->artist = artist; + trackArtist = artist; } - trackData->title = line; - - readResponse.tracks.AddItem(trackData); + TrackData* trackData = _Track(readResponse, track); + trackData->artist += trackArtist; + trackData->title += line; } if (output == "" || output == ".\r\n") { @@ -401,3 +394,20 @@ CDDBServer::_SendCommand(const BString& command, BString& output) return B_ERROR; } + + +TrackData* +CDDBServer::_Track(ReadResponseData& response, uint32 track) const +{ + for (int32 i = 0; i < response.tracks.CountItems(); i++) { + TrackData* trackData = response.tracks.ItemAt(i); + if (trackData->trackNumber == track) + return trackData; + } + + TrackData* trackData = new TrackData(); + trackData->trackNumber = track; + response.tracks.AddItem(trackData); + + return trackData; +} diff --git a/src/bin/cddb_lookup/cddb_server.h b/src/bin/cddb_lookup/cddb_server.h index 1066b552a5..ed0f9f3a7b 100644 --- a/src/bin/cddb_lookup/cddb_server.h +++ b/src/bin/cddb_lookup/cddb_server.h @@ -77,6 +77,8 @@ private: status_t _SendCommand(const BString& command, BString& output); + TrackData* _Track(ReadResponseData& response, + uint32 track) const; private: BString fLocalHostName;