comparison data/fileio/MP3FileReader.cpp @ 1170:6877f4200912 3.0-integration

Merge from default branch
author Chris Cannam
date Wed, 02 Mar 2016 16:16:36 +0000
parents 134ce7667256
children 6b847a59d908
comparison
equal deleted inserted replaced
1160:ea636412f9fe 1170:6877f4200912
30 #include <unistd.h> 30 #include <unistd.h>
31 31
32 #ifdef HAVE_ID3TAG 32 #ifdef HAVE_ID3TAG
33 #include <id3tag.h> 33 #include <id3tag.h>
34 #endif 34 #endif
35
35 //#define DEBUG_ID3TAG 1 36 //#define DEBUG_ID3TAG 1
36 37
37 #include <QFileInfo> 38 #include <QFileInfo>
38 39
39 MP3FileReader::MP3FileReader(FileSource source, DecodeMode decodeMode, 40 MP3FileReader::MP3FileReader(FileSource source, DecodeMode decodeMode,
176 // when we implement support for more than just the one tag! 177 // when we implement support for more than just the one tag!
177 178
178 id3_tag *tag = id3_file_tag(file); 179 id3_tag *tag = id3_file_tag(file);
179 if (!tag) { 180 if (!tag) {
180 #ifdef DEBUG_ID3TAG 181 #ifdef DEBUG_ID3TAG
181 SVDEBUG << "MP3FileReader::loadTags: No ID3 tag found" << endl; 182 cerr << "MP3FileReader::loadTags: No ID3 tag found" << endl;
182 #endif 183 #endif
183 id3_file_close(file); 184 id3_file_close(file);
184 return; 185 return;
185 } 186 }
186 187
199 200
200 id3_file_close(file); 201 id3_file_close(file);
201 202
202 #else 203 #else
203 #ifdef DEBUG_ID3TAG 204 #ifdef DEBUG_ID3TAG
204 SVDEBUG << "MP3FileReader::loadTags: ID3 tag support not compiled in" 205 cerr << "MP3FileReader::loadTags: ID3 tag support not compiled in"
205 << endl; 206 << endl;
206 #endif 207 #endif
207 #endif 208 #endif
208 } 209 }
209 210
214 id3_tag *tag = (id3_tag *)vtag; 215 id3_tag *tag = (id3_tag *)vtag;
215 216
216 id3_frame *frame = id3_tag_findframe(tag, name, 0); 217 id3_frame *frame = id3_tag_findframe(tag, name, 0);
217 if (!frame) { 218 if (!frame) {
218 #ifdef DEBUG_ID3TAG 219 #ifdef DEBUG_ID3TAG
219 SVDEBUG << "MP3FileReader::loadTags: No \"" << name << "\" in ID3 tag" << endl; 220 cerr << "MP3FileReader::loadTags: No \"" << name << "\" in ID3 tag" << endl;
220 #endif 221 #endif
221 return ""; 222 return "";
222 } 223 }
223 224
224 if (frame->nfields < 2) { 225 if (frame->nfields < 2) {
225 SVDEBUG << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << endl; 226 cerr << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << endl;
226 return ""; 227 return "";
227 } 228 }
228 229
229 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); 230 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]);
230 if (nstrings == 0) { 231 if (nstrings == 0) {
231 #ifdef DEBUG_ID3TAG 232 #ifdef DEBUG_ID3TAG
232 SVDEBUG << "MP3FileReader::loadTags: No strings for \"" << name << "\" in ID3 tag" << endl; 233 cerr << "MP3FileReader::loadTags: No strings for \"" << name << "\" in ID3 tag" << endl;
233 #endif 234 #endif
234 return ""; 235 return "";
235 } 236 }
236 237
237 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); 238 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0);
238 if (!ustr) { 239 if (!ustr) {
239 #ifdef DEBUG_ID3TAG 240 #ifdef DEBUG_ID3TAG
240 SVDEBUG << "MP3FileReader::loadTags: Invalid or absent data for \"" << name << "\" in ID3 tag" << endl; 241 cerr << "MP3FileReader::loadTags: Invalid or absent data for \"" << name << "\" in ID3 tag" << endl;
241 #endif 242 #endif
242 return ""; 243 return "";
243 } 244 }
244 245
245 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); 246 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr);
250 251
251 QString rv = QString::fromUtf8((const char *)u8str); 252 QString rv = QString::fromUtf8((const char *)u8str);
252 free(u8str); 253 free(u8str);
253 254
254 #ifdef DEBUG_ID3TAG 255 #ifdef DEBUG_ID3TAG
255 SVDEBUG << "MP3FileReader::loadTags: tag \"" << name << "\" -> \"" 256 cerr << "MP3FileReader::loadTags: tag \"" << name << "\" -> \""
256 << rv << "\"" << endl; 257 << rv << "\"" << endl;
257 #endif 258 #endif
258 259
259 260
260 return rv; 261 return rv;