cddb_lookup: Support multiline track response.
* This fixes bug #12808. * Also, don't accept track numbers above 99, as that's the maximum a CD supports.
This commit is contained in:
@@ -244,43 +244,36 @@ CDDBServer::Read(const BString& category, const BString& cddbID,
|
|||||||
BString index;
|
BString index;
|
||||||
prefix.MoveInto(index, 6, prefix.Length() - 6);
|
prefix.MoveInto(index, 6, prefix.Length() - 6);
|
||||||
|
|
||||||
TrackData* trackData = new TrackData;
|
|
||||||
|
|
||||||
char* firstInvalid;
|
char* firstInvalid;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
uint32 track = strtoul(index.String(), &firstInvalid, 10);
|
uint32 track = strtoul(index.String(), &firstInvalid, 10);
|
||||||
if ((errno == ERANGE &&
|
if (errno != 0 || track > 99) {
|
||||||
(track == (uint32)LONG_MAX || track == (uint32)LONG_MIN))
|
|
||||||
|| (errno != 0 && track == 0)) {
|
|
||||||
// Track out of range.
|
// Track out of range.
|
||||||
printf("Track out of range: %s\n", index.String());
|
printf("Track out of range: %s\n", index.String());
|
||||||
delete trackData;
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstInvalid == index.String()) {
|
if (firstInvalid == index.String()) {
|
||||||
printf("Invalid track: %s\n", index.String());
|
printf("Invalid track: %s\n", index.String());
|
||||||
delete trackData;
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
trackData->trackNumber = track;
|
BString trackArtist;
|
||||||
|
|
||||||
int32 pos = line.FindFirst(" / ");
|
int32 pos = line.FindFirst(" / ");
|
||||||
if (pos >= 0 && artist.ICompare("Various") == 0) {
|
if (pos >= 0 && artist.ICompare("Various") == 0) {
|
||||||
// Disk is set to have a compilation artist and
|
// Disk is set to have a compilation artist and
|
||||||
// we have track specific artist information.
|
// we have track specific artist information.
|
||||||
line.MoveInto(trackData->artist, 0, pos);
|
line.MoveInto(trackArtist, 0, pos);
|
||||||
// Move artist information from line to artist.
|
// Move artist information from line to artist.
|
||||||
line.Remove(0, 3);
|
line.Remove(0, 3);
|
||||||
// Remove " / " from line.
|
// Remove " / " from line.
|
||||||
} else {
|
} else {
|
||||||
trackData->artist = artist;
|
trackArtist = artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
trackData->title = line;
|
TrackData* trackData = _Track(readResponse, track);
|
||||||
|
trackData->artist += trackArtist;
|
||||||
readResponse.tracks.AddItem(trackData);
|
trackData->title += line;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output == "" || output == ".\r\n") {
|
if (output == "" || output == ".\r\n") {
|
||||||
@@ -401,3 +394,20 @@ CDDBServer::_SendCommand(const BString& command, BString& output)
|
|||||||
|
|
||||||
return B_ERROR;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ private:
|
|||||||
|
|
||||||
status_t _SendCommand(const BString& command,
|
status_t _SendCommand(const BString& command,
|
||||||
BString& output);
|
BString& output);
|
||||||
|
TrackData* _Track(ReadResponseData& response,
|
||||||
|
uint32 track) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fLocalHostName;
|
BString fLocalHostName;
|
||||||
|
|||||||
Reference in New Issue
Block a user