Commit 2c635c806935ec91b659f522fdc4f93f82be75b2

  • Tree SHA1: 35a6c3d
  • Parent SHA1: 2fc5c59 (Give generated navigation urls a default name so they do not show up as empty in the breadcrumb bookmark menu)
  • raw diff | raw patch
Remove TagLib stuff from Ipod.
  
2828 ${AMAROK_COLLECTION_SUPPORT_DIR}
2929 ${KDE4_INCLUDE_DIR}
3030 ${QT_INCLUDES}
31 ${TAGLIB_INCLUDES}
3231)
3332
34if ( TAGLIB-EXTRAS_FOUND )
35 include_directories( ${include_directories} ${TAGLIB-EXTRAS_INCLUDE_DIR} )
36endif ( TAGLIB-EXTRAS_FOUND )
37
38add_definitions(${TAGLIB_CFLAGS})
39
4033########### set GDK var ################
4134 # Generate config-gdk.h.cmake
4235 configure_file(config-gdk.h.cmake
5757 ${KDE4_SOLID_LIBRARY}
5858 ${KDE4_THREADWEAVER_LIBRARIES}
5959 ${QT_QTGUI_LIBRARY}
60 ${TAGLIB_LIBRARIES}
61 ${TAGLIB-EXTRAS_LIBRARIES}
6260 ${GLIB2_LIBRARIES}
6361 ${GDK_LIBRARIES}
6462 ${IPOD_LIBRARIES}
  
6464#include <QStringList>
6565#include <QTime>
6666
67//Taglib:
68#include <apetag.h>
69#include <fileref.h>
70#include <flacfile.h>
71#include <id3v1tag.h>
72#include <id3v2tag.h>
73#include <mpcfile.h>
74#include <mpegfile.h>
75#include <oggfile.h>
76#include <oggflacfile.h>
77#include <speexfile.h>
78#include <tlist.h>
79#include <tstring.h>
80#include <vorbisfile.h>
81
82#ifdef TAGLIB_EXTRAS_FOUND
83#include <mp4file.h>
84#include <mp4tag.h>
85#include <mp4item.h>
86#include <audiblefiletyperesolver.h>
87#include <asffiletyperesolver.h>
88#include <wavfiletyperesolver.h>
89#include <realmediafiletyperesolver.h>
90#include <mp4filetyperesolver.h>
91#endif
92
9367using namespace Meta;
9468
9569/// IpodHandler
11631163 }
11641164
11651165 return orphanedTracks;
1166}
1167
1168AttributeHash
1169IpodHandler::readTags( const QString &path, TagLib::AudioProperties::ReadStyle readStyle )
1170{
1171 // Tests reveal the following:
1172 //
1173 // TagLib::AudioProperties Relative Time Taken
1174 //
1175 // No AudioProp Reading 1
1176 // Fast 1.18
1177 // Average Untested
1178 // Accurate Untested
1179
1180
1181#ifdef COMPLEX_TAGLIB_FILENAME
1182 const wchar_t * encodedName = reinterpret_cast<const wchar_t *>(path.utf16());
1183#else
1184 QByteArray fileName = QFile::encodeName( path );
1185 const char * encodedName = fileName.constData(); // valid as long as fileName exists
1186#endif
1187
1188 TagLib::FileRef fileref;
1189 TagLib::Tag *tag = 0;
1190 fileref = TagLib::FileRef( encodedName, true, readStyle );
1191
1192 AttributeHash attributes;
1193 bool isValid = false;
1194 FileType fileType = ogg;
1195 if( !fileref.isNull() )
1196 {
1197 tag = fileref.tag();
1198 if ( tag )
1199 {
1200 #define strip( x ) TStringToQString( x ).trimmed()
1201
1202 attributes["title"] = strip( tag->title() );
1203 attributes["artist"] = strip( tag->artist() );
1204 attributes["album"] = strip( tag->album() );
1205 attributes["comment"] = strip( tag->comment() );
1206 attributes["genre"] = strip( tag->genre() );
1207 attributes["year"] = QString::number( tag->year() );
1208 attributes["track"] = QString::number( tag->track() );
1209 isValid = true;
1210 }
1211/*
1212 Meta::ReplayGainTagMap replayGainTags = Meta::readReplayGainTags( fileref );
1213 if ( replayGainTags.contains( Meta::ReplayGain_Track_Gain ) )
1214 {
1215 attributes["trackgain"] = QString::number( replayGainTags[Meta::ReplayGain_Track_Gain] );
1216 if ( replayGainTags.contains( Meta::ReplayGain_Track_Peak ) )
1217 attributes["trackpeakgain"] = QString::number( replayGainTags[Meta::ReplayGain_Track_Peak] );
1218 }
1219 if ( replayGainTags.contains( Meta::ReplayGain_Album_Gain ) )
1220 {
1221 attributes["albumgain"] = QString::number( replayGainTags[Meta::ReplayGain_Album_Gain] );
1222 if ( replayGainTags.contains( Meta::ReplayGain_Album_Peak ) )
1223 attributes["albumpeakgain"] = QString::number( replayGainTags[Meta::ReplayGain_Album_Peak] );
1224 }
1225*/
1226 QString disc;
1227 QString compilation;
1228
1229 /* As mpeg implementation on TagLib uses a Tag class that's not defined on the headers,
1230 we have to cast the files, not the tags! */
1231 if ( TagLib::MPEG::File *file = dynamic_cast<TagLib::MPEG::File *>( fileref.file() ) )
1232 {
1233 fileType = mp3;
1234 if ( file->ID3v2Tag() )
1235 {
1236 if ( !file->ID3v2Tag()->frameListMap()["TPOS"].isEmpty() )
1237 disc = TStringToQString( file->ID3v2Tag()->frameListMap()["TPOS"].front()->toString() ).trimmed();
1238
1239 if ( !file->ID3v2Tag()->frameListMap()["TBPM"].isEmpty() )
1240 attributes["bpm"] = TStringToQString( file->ID3v2Tag()->frameListMap()["TBPM"].front()->toString() ).trimmed().toFloat();
1241
1242 if ( !file->ID3v2Tag()->frameListMap()["TCOM"].isEmpty() )
1243 attributes["composer"] = TStringToQString( file->ID3v2Tag()->frameListMap()["TCOM"].front()->toString() ).trimmed();
1244
1245 if ( !file->ID3v2Tag()->frameListMap()["TPE2"].isEmpty() ) // non-standard: Apple, Microsoft
1246 attributes["albumArtist"] = TStringToQString( file->ID3v2Tag()->frameListMap()["TPE2"].front()->toString() ).trimmed();
1247
1248 if ( !file->ID3v2Tag()->frameListMap()["TCMP"].isEmpty() )
1249 compilation = TStringToQString( file->ID3v2Tag()->frameListMap()["TCMP"].front()->toString() ).trimmed();
1250
1251 //FIXME: Port 2.0
1252// if( images )
1253// loadImagesFromTag( *file->ID3v2Tag(), *images );
1254 }
1255
1256 #undef strip
1257 }
1258
1259 if ( TagLib::Ogg::Vorbis::File *file = dynamic_cast<TagLib::Ogg::Vorbis::File *>( fileref.file() ) )
1260 {
1261 fileType = ogg;
1262 if ( file->tag() )
1263 {
1264 if ( !file->tag()->fieldListMap()[ "COMPOSER" ].isEmpty() )
1265 attributes["composer"] = TStringToQString( file->tag()->fieldListMap()["COMPOSER"].front() ).trimmed();
1266
1267 if ( !file->tag()->fieldListMap()[ "BPM" ].isEmpty() )
1268 attributes["bpm"] = TStringToQString( file->tag()->fieldListMap()["BPM"].front() ).trimmed().toFloat();
1269
1270 if ( !file->tag()->fieldListMap()[ "DISCNUMBER" ].isEmpty() )
1271 disc = TStringToQString( file->tag()->fieldListMap()["DISCNUMBER"].front() ).trimmed();
1272
1273 if ( !file->tag()->fieldListMap()[ "COMPILATION" ].isEmpty() )
1274 compilation = TStringToQString( file->tag()->fieldListMap()["COMPILATION"].front() ).trimmed();
1275 }
1276 }
1277 else if ( TagLib::FLAC::File *file = dynamic_cast<TagLib::FLAC::File *>( fileref.file() ) )
1278 {
1279 fileType = flac;
1280 if ( file->xiphComment() )
1281 {
1282 if ( !file->xiphComment()->fieldListMap()[ "COMPOSER" ].isEmpty() )
1283 attributes["composer"] = TStringToQString( file->xiphComment()->fieldListMap()["COMPOSER"].front() ).trimmed();
1284
1285 if ( !file->xiphComment()->fieldListMap()[ "BPM" ].isEmpty() )
1286 attributes["bpm"] = TStringToQString( file->xiphComment()->fieldListMap()["BPM"].front() ).trimmed().toFloat();
1287
1288 if ( !file->xiphComment()->fieldListMap()[ "DISCNUMBER" ].isEmpty() )
1289 disc = TStringToQString( file->xiphComment()->fieldListMap()["DISCNUMBER"].front() ).trimmed();
1290
1291 if ( !file->xiphComment()->fieldListMap()[ "COMPILATION" ].isEmpty() )
1292 compilation = TStringToQString( file->xiphComment()->fieldListMap()["COMPILATION"].front() ).trimmed();
1293 }
1294// if ( images && file->ID3v2Tag() )
1295// loadImagesFromTag( *file->ID3v2Tag(), *images );
1296 }
1297#ifdef TAGLIB_EXTRAS_FOUND
1298 else if ( TagLib::MP4::File *file = dynamic_cast<TagLib::MP4::File *>( fileref.file() ) )
1299 {
1300 fileType = mp4;
1301 TagLib::MP4::Tag *mp4tag = dynamic_cast<TagLib::MP4::Tag *>( file->tag() );
1302 if( mp4tag )
1303 {
1304 if ( mp4tag->itemListMap().contains( "\xA9wrt" ) )
1305 attributes["composer"] = TStringToQString( mp4tag->itemListMap()["\xa9wrt"].toStringList().front() );
1306
1307 if ( mp4tag->itemListMap().contains( "tmpo" ) )
1308 attributes["bpm"] = QString::number( mp4tag->itemListMap()["tmpo"].toInt() );
1309
1310 if ( mp4tag->itemListMap().contains( "disk" ) )
1311 disc = QString::number( mp4tag->itemListMap()["disk"].toIntPair().first );
1312
1313 if ( mp4tag->itemListMap().contains( "cpil" ) )
1314 compilation = QString::number( mp4tag->itemListMap()["cpil"].toBool() ? '1' : '0' );
1315
1316// if ( images && mp4tag->cover().size() )
1317// images->push_back( EmbeddedImage( mp4tag->cover(), "" ) );
1318 }
1319 }
1320#endif
1321
1322 if ( !disc.isEmpty() )
1323 {
1324 int i = disc.indexOf('/');
1325 // guard against b0rked tags
1326 int discnumber;
1327 if ( i != -1 )
1328 // disc.right( i ).toInt() is total number of discs, we don't use this at the moment
1329 discnumber = disc.left( i ).toInt();
1330 else
1331 discnumber = disc.toInt();
1332 attributes["discnumber"] = QString::number( discnumber );
1333 }
1334
1335 // Sometimes the file is explicitly tagged with compilation details. When it is not,
1336 // then we need to delegate checking whether this files is in a compilation to Amarok.
1337 if ( compilation.isEmpty() )
1338 {
1339 // well, it wasn't set, but if the artist is VA assume it's a compilation
1340 //TODO: If we get pure-Qt translation support, put this back in; else functionality moved to the processor
1341 //if ( attributes["artist"] == QObject::tr( "Various Artists" ) )
1342 // attributes["compilation"] = QString::number( 1 );
1343 attributes["compilation"] = "checkforvarious";
1344 }
1345 else
1346 {
1347 int i = compilation.toInt();
1348 attributes["compilation"] = QString::number( i );
1349 }
1350 }
1351
1352 if ( !isValid )
1353 {
1354 std::cout << "<dud/>";
1355 return attributes;
1356 }
1357
1358 attributes["filetype"] = QString::number( fileType );
1359
1360 static const int Undetermined = -2;
1361
1362 int bitrate = Undetermined;
1363 int length = Undetermined;
1364 int samplerate = Undetermined;
1365 if( fileref.audioProperties() )
1366 {
1367 bitrate = fileref.audioProperties()->bitrate();
1368 length = fileref.audioProperties()->length();
1369 samplerate = fileref.audioProperties()->sampleRate();
1370 }
1371 if ( bitrate == Undetermined || length == Undetermined || samplerate == Undetermined )
1372 attributes["audioproperties"] = "false";
1373 else
1374 {
1375 attributes["audioproperties"] = "true";
1376 attributes["bitrate"] = QString::number( bitrate );
1377 attributes["length"] = QString::number( length );
1378 attributes["samplerate"] = QString::number( samplerate );
1379 }
1380
1381 const int size = QFile( path ).size();
1382 if( size >= 0 )
1383 attributes["filesize"] = QString::number( size );
1384
1385 return attributes;
13861166}
13871167
13881168bool
  
254254 */
255255 QStringList orphanedTracks();
256256
257 // NOTE: readTags taken from CollectionScanner.cpp, not used directly since
258 // CollectionScanner is now a separate utility from Amarok, and we should
259 // not depend on it.
260
261 /**
262 * Read metadata tags of a given file.
263 * @track Track for the file.
264 * @return QMap containing tags, or empty QMap on failure.
265 */
266
267 AttributeHash readTags( const QString &path, TagLib::AudioProperties::ReadStyle readStyle = TagLib::AudioProperties::Fast );
268
269257 bool findStale();
270258 bool findOrphaned();
271259 bool addNextOrphaned();