From 64b805d78fd027a3bd7e46d26bf587ad3006d0dd Mon Sep 17 00:00:00 2001
From: Augustin Cavalier <waddlesplash@gmail.com>
Date: Tue, 8 Jul 2014 12:32:23 -0400
Subject: [PATCH] cddb_daemon: Various fixes.
* Add ".wav" to the ends of filenames
* Add a track number at the beginning of the filename, e.g. "01"
* Don't hard-fail if the FreeDB response contains an invalid year
---
src/servers/cddb_daemon/cddb_daemon.cpp | 24 ++++++++++++++++++------
src/servers/cddb_daemon/cddb_server.cpp | 4 ++--
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/servers/cddb_daemon/cddb_daemon.cpp b/src/servers/cddb_daemon/cddb_daemon.cpp
index f216173..87a1636 100644
a
|
b
|
CDDBDaemon::_CanLookup(const dev_t device, uint32* cddbId,
|
162 | 162 | if (directory.ReadAttr("CD:do_lookup", B_BOOL_TYPE, 0, (void *)&doLookup, |
163 | 163 | sizeof(bool)) < B_OK || !doLookup) |
164 | 164 | return false; |
165 | | |
| 165 | |
166 | 166 | // Does it have the CD:cddbid attribute? |
167 | 167 | if (directory.ReadAttr("CD:cddbid", B_UINT32_TYPE, 0, (void *)cddbId, |
168 | 168 | sizeof(uint32)) < B_OK) |
… |
… |
CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
|
237 | 237 | name = data->title; |
238 | 238 | name.ReplaceSet("/", " "); |
239 | 239 | |
| 240 | // Add track number to the beginning of the string. |
| 241 | int trackNum = index + 1; // index=0 is actually Track 1 |
| 242 | char trackNumString[3]; // 2 digits + '\0' |
| 243 | snprintf(trackNumString, 3, "%02d", trackNum); |
| 244 | name.Prepend(" "); |
| 245 | name.Prepend(trackNumString, 3); |
| 246 | name.Append(".wav"); |
| 247 | |
240 | 248 | if ((result = entry.Rename(name.String())) != B_OK) { |
241 | 249 | printf("Failed renaming entry at index %d to \"%s\".\n", index, |
242 | 250 | name.String()); |
… |
… |
CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
|
252 | 260 | node.WriteAttr("Audio:Album", B_STRING_TYPE, 0, |
253 | 261 | (readResponse->title).String(), |
254 | 262 | (readResponse->title).Length()); |
255 | | node.WriteAttr("Media:Genre", B_STRING_TYPE, 0, |
256 | | (readResponse->genre).String(), |
257 | | (readResponse->genre).Length()); |
258 | | node.WriteAttr("Media:Year", B_INT32_TYPE, 0, &(readResponse->year), |
259 | | sizeof(int32)); |
| 263 | if (readResponse->genre.Length() != 0) { |
| 264 | node.WriteAttr("Media:Genre", B_STRING_TYPE, 0, |
| 265 | (readResponse->genre).String(), |
| 266 | (readResponse->genre).Length()); |
| 267 | } |
| 268 | if (readResponse->year != 0) { |
| 269 | node.WriteAttr("Media:Year", B_INT32_TYPE, 0, |
| 270 | &(readResponse->year), sizeof(int32)); |
| 271 | } |
260 | 272 | |
261 | 273 | if (data->artist == "") { |
262 | 274 | node.WriteAttr("Audio:Artist", B_STRING_TYPE, 0, |
diff --git a/src/servers/cddb_daemon/cddb_server.cpp b/src/servers/cddb_daemon/cddb_server.cpp
index 46f369e..fef57bb 100644
a
|
b
|
CDDBServer::Read(QueryResponseData* diskData, ReadResponseData* readResponse)
|
217 | 217 | || (errno != 0 && year == 0)) { |
218 | 218 | // Year out of range. |
219 | 219 | printf("Year out of range: %s\n", line.String()); |
220 | | return B_ERROR; |
| 220 | year = 0; |
221 | 221 | } |
222 | 222 | |
223 | 223 | if (firstInvalid == line.String()) { |
224 | 224 | printf("Invalid year: %s\n", line.String()); |
225 | | return B_ERROR; |
| 225 | year = 0; |
226 | 226 | } |
227 | 227 | |
228 | 228 | readResponse->year = year; |