Mercurial > hg > svcore
comparison data/fileio/MP3FileReader.cpp @ 1287:97f21b03269b 3.0-integration
Tag load diagnostic
author | Chris Cannam |
---|---|
date | Wed, 23 Nov 2016 14:51:03 +0000 |
parents | 16a8e97179d7 |
children | 5ef9b4d4bbdb |
comparison
equal
deleted
inserted
replaced
1286:40c042780bc9 | 1287:97f21b03269b |
---|---|
29 #include <cstdlib> | 29 #include <cstdlib> |
30 | 30 |
31 #ifdef HAVE_ID3TAG | 31 #ifdef HAVE_ID3TAG |
32 #include <id3tag.h> | 32 #include <id3tag.h> |
33 #endif | 33 #endif |
34 | |
35 //#define DEBUG_ID3TAG 1 | |
36 | 34 |
37 #include <QFileInfo> | 35 #include <QFileInfo> |
38 | 36 |
39 #ifdef _MSC_VER | 37 #ifdef _MSC_VER |
40 #include <io.h> | 38 #include <io.h> |
193 return; | 191 return; |
194 } | 192 } |
195 | 193 |
196 m_title = loadTag(tag, "TIT2"); // work title | 194 m_title = loadTag(tag, "TIT2"); // work title |
197 if (m_title == "") m_title = loadTag(tag, "TIT1"); | 195 if (m_title == "") m_title = loadTag(tag, "TIT1"); |
196 if (m_title == "") SVDEBUG << "MP3FileReader::loadTags: No title found" << endl; | |
198 | 197 |
199 m_maker = loadTag(tag, "TPE1"); // "lead artist" | 198 m_maker = loadTag(tag, "TPE1"); // "lead artist" |
200 if (m_maker == "") m_maker = loadTag(tag, "TPE2"); | 199 if (m_maker == "") m_maker = loadTag(tag, "TPE2"); |
200 if (m_maker == "") SVDEBUG << "MP3FileReader::loadTags: No artist/maker found" << endl; | |
201 | 201 |
202 for (unsigned int i = 0; i < tag->nframes; ++i) { | 202 for (unsigned int i = 0; i < tag->nframes; ++i) { |
203 if (tag->frames[i]) { | 203 if (tag->frames[i]) { |
204 QString value = loadTag(tag, tag->frames[i]->id); | 204 QString value = loadTag(tag, tag->frames[i]->id); |
205 if (value != "") m_tags[tag->frames[i]->id] = value; | 205 if (value != "") { |
206 m_tags[tag->frames[i]->id] = value; | |
207 } | |
206 } | 208 } |
207 } | 209 } |
208 | 210 |
209 id3_file_close(file); | 211 id3_file_close(file); |
210 | 212 |
211 #else | 213 #else |
212 SVDEBUG << "MP3FileReader::loadTags: ID3 tag support not compiled in" | 214 SVDEBUG << "MP3FileReader::loadTags: ID3 tag support not compiled in" << endl; |
213 << endl; | |
214 #endif | 215 #endif |
215 } | 216 } |
216 | 217 |
217 QString | 218 QString |
218 MP3FileReader::loadTag(void *vtag, const char *name) | 219 MP3FileReader::loadTag(void *vtag, const char *name) |
220 #ifdef HAVE_ID3TAG | 221 #ifdef HAVE_ID3TAG |
221 id3_tag *tag = (id3_tag *)vtag; | 222 id3_tag *tag = (id3_tag *)vtag; |
222 | 223 |
223 id3_frame *frame = id3_tag_findframe(tag, name, 0); | 224 id3_frame *frame = id3_tag_findframe(tag, name, 0); |
224 if (!frame) { | 225 if (!frame) { |
225 #ifdef DEBUG_ID3TAG | 226 SVDEBUG << "MP3FileReader::loadTag: No \"" << name << "\" frame found in ID3 tag" << endl; |
226 cerr << "MP3FileReader::loadTags: No \"" << name << "\" in ID3 tag" << endl; | |
227 #endif | |
228 return ""; | 227 return ""; |
229 } | 228 } |
230 | 229 |
231 if (frame->nfields < 2) { | 230 if (frame->nfields < 2) { |
232 cerr << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << endl; | 231 cerr << "MP3FileReader::loadTag: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << endl; |
233 return ""; | 232 return ""; |
234 } | 233 } |
235 | 234 |
236 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); | 235 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); |
237 if (nstrings == 0) { | 236 if (nstrings == 0) { |
238 #ifdef DEBUG_ID3TAG | 237 SVDEBUG << "MP3FileReader::loadTag: No strings for \"" << name << "\" in ID3 tag" << endl; |
239 cerr << "MP3FileReader::loadTags: No strings for \"" << name << "\" in ID3 tag" << endl; | |
240 #endif | |
241 return ""; | 238 return ""; |
242 } | 239 } |
243 | 240 |
244 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); | 241 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); |
245 if (!ustr) { | 242 if (!ustr) { |
246 #ifdef DEBUG_ID3TAG | 243 SVDEBUG << "MP3FileReader::loadTag: Invalid or absent data for \"" << name << "\" in ID3 tag" << endl; |
247 cerr << "MP3FileReader::loadTags: Invalid or absent data for \"" << name << "\" in ID3 tag" << endl; | |
248 #endif | |
249 return ""; | 244 return ""; |
250 } | 245 } |
251 | 246 |
252 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); | 247 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); |
253 if (!u8str) { | 248 if (!u8str) { |
254 cerr << "MP3FileReader::loadTags: ERROR: Internal error: Failed to convert UCS4 to UTF8 in ID3 title" << endl; | 249 SVDEBUG << "MP3FileReader::loadTag: ERROR: Internal error: Failed to convert UCS4 to UTF8 in ID3 tag" << endl; |
255 return ""; | 250 return ""; |
256 } | 251 } |
257 | 252 |
258 QString rv = QString::fromUtf8((const char *)u8str); | 253 QString rv = QString::fromUtf8((const char *)u8str); |
259 free(u8str); | 254 free(u8str); |
260 | 255 |
261 #ifdef DEBUG_ID3TAG | 256 SVDEBUG << "MP3FileReader::loadTag: Tag \"" << name << "\" -> \"" |
262 cerr << "MP3FileReader::loadTags: tag \"" << name << "\" -> \"" | 257 << rv << "\"" << endl; |
263 << rv << "\"" << endl; | |
264 #endif | |
265 | |
266 | 258 |
267 return rv; | 259 return rv; |
268 | 260 |
269 #else | 261 #else |
270 return ""; | 262 return ""; |
327 | 319 |
328 #ifdef HAVE_ID3TAG | 320 #ifdef HAVE_ID3TAG |
329 if (length > ID3_TAG_QUERYSIZE) { | 321 if (length > ID3_TAG_QUERYSIZE) { |
330 ssize_t taglen = id3_tag_query(start, ID3_TAG_QUERYSIZE); | 322 ssize_t taglen = id3_tag_query(start, ID3_TAG_QUERYSIZE); |
331 if (taglen > 0) { | 323 if (taglen > 0) { |
332 // cerr << "ID3 tag length to skip: " << taglen << endl; | 324 SVDEBUG << "MP3FileReader: ID3 tag length to skip: " << taglen << endl; |
333 start += taglen; | 325 start += taglen; |
334 length -= taglen; | 326 length -= taglen; |
335 } | 327 } |
336 } | 328 } |
337 #endif | 329 #endif |