File trinity-taglib2.patch of Package kde3-amarok
From 460320e57786ec9a708ac7ba4191b15a305f9394 Mon Sep 17 00:00:00 2001
From: mio <stigma@disroot.org>
Date: Thu, 26 Sep 2024 21:42:32 +1000
Subject: Replace custom MP4 metadata parser with TagLib
TagLib supports MP4 metadata since version 1.6 (2009). The custom
parser code caused problems because there was a mismatch between
the definition of TagLib::Tag and TagLib::MP4::Tag, and the
implementation of the custom TagLib::MP4::Tag.
This requires TagLib 1.11 and above.
diff --git a/amarok/src/metabundle.cpp b/amarok/src/metabundle.cpp
index aa27b4d2..eb4ee327 100644
--- a/amarok/src/metabundle.cpp
+++ b/amarok/src/metabundle.cpp
@@ -35,11 +35,13 @@
#include <taglib/id3v1genres.h> //used to load genre list
#include <taglib/mpegfile.h>
#include <taglib/tag.h>
+#include <taglib/tpropertymap.h>
#include <taglib/tstring.h>
#include <taglib/tlist.h>
#include <taglib/apetag.h>
#include <taglib/id3v2tag.h>
#include <taglib/id3v1tag.h>
+#include <taglib/mp4file.h>
#include <taglib/mpcfile.h>
#include <taglib/mpegfile.h>
#include <taglib/oggfile.h>
@@ -51,13 +53,6 @@
#include <taglib/xiphcomment.h>
#include <config.h>
-#ifdef HAVE_MP4V2
-#include "metadata/mp4/mp4file.h"
-#include "metadata/mp4/mp4tag.h"
-#else
-#include "metadata/m4a/mp4file.h"
-#include "metadata/m4a/mp4itunestag.h"
-#endif
#include "lastfm.h"
#include "metabundle.h"
@@ -484,8 +479,14 @@ MetaBundle::embeddedImages( MetaBundle::EmbeddedImageList& images ) const
loadImagesFromTag( *file->ID3v2Tag(), images );
} else if ( TagLib::MP4::File *file = dynamic_cast<TagLib::MP4::File *>( fileref.file() ) ) {
TagLib::MP4::Tag *mp4tag = dynamic_cast<TagLib::MP4::Tag *>( file->tag() );
- if( mp4tag && mp4tag->cover().size() ) {
- images.push_back( EmbeddedImage( mp4tag->cover(), "" ) );
+ if (mp4tag)
+ {
+ TagLib::MP4::Item coverItem = mp4tag->item("covr");
+ if (coverItem.isValid())
+ {
+ TagLib::MP4::CoverArt coverArt = coverItem.toCoverArtList().front();
+ images.push_back(EmbeddedImage(coverArt.data(), ""));
+ }
}
}
}
@@ -600,14 +601,39 @@ MetaBundle::readTags( TagLib::AudioProperties::ReadStyle readStyle, EmbeddedImag
{
m_type = mp4;
TagLib::MP4::Tag *mp4tag = dynamic_cast<TagLib::MP4::Tag *>( file->tag() );
- if( mp4tag )
+ if (mp4tag)
{
- setComposer( TStringToQString( mp4tag->composer() ) );
- setBpm( QString::number( mp4tag->bpm() ).toFloat() );
- disc = QString::number( mp4tag->disk() );
- compilation = QString::number( mp4tag->compilation() );
- if ( images && mp4tag->cover().size() ) {
- images->push_back( EmbeddedImage( mp4tag->cover(), "" ) );
+ TagLib::PropertyMap properties = mp4tag->properties();
+
+ auto property = properties.find("COMPOSER");
+ if (property != properties.end())
+ {
+ setComposer(TStringToQString(property->second.front()).stripWhiteSpace());
+ }
+
+ property = properties.find("BPM");
+ if (property != properties.end())
+ {
+ setBpm(TStringToQString(property->second.front()).toFloat());
+ }
+
+ property = properties.find("DISCNUMBER");
+ if (property != properties.end())
+ {
+ disc = TStringToQString(property->second.front());
+ }
+
+ property = properties.find("COMPILATION");
+ if (property != properties.end())
+ {
+ compilation = TStringToQString(property->second.front());
+ }
+
+ TagLib::MP4::Item coverItem = mp4tag->item("covr");
+ if (images && coverItem.isValid())
+ {
+ TagLib::MP4::CoverArt coverArt = coverItem.toCoverArtList().front();
+ images->push_back(EmbeddedImage(coverArt.data(), ""));
}
}
}
@@ -1360,18 +1386,47 @@ MetaBundle::setExtendedTag( TagLib::File *file, int tag, const TQString value )
flacFile->xiphComment()->addField( id, QStringToTString( value ), true );
}
}
- else if ( m_type == mp4 )
+ else if (m_type == mp4)
{
TagLib::MP4::Tag *mp4tag = dynamic_cast<TagLib::MP4::Tag *>( file->tag() );
- if( mp4tag )
+ if (mp4tag)
{
- switch( tag )
+ TagLib::PropertyMap properties = mp4tag->properties();
+
+ switch (tag)
{
- case ( composerTag ): mp4tag->setComposer( QStringToTString( value ) ); break;
- case ( discNumberTag ): mp4tag->setDisk( value.toInt() );
- case ( bpmTag ): mp4tag->setBpm( value.toInt() ); // mp4 doesn't support float bpm
- case ( compilationTag ): mp4tag->setCompilation( value.toInt() == CompilationYes );
+ case composerTag:
+ {
+ properties.replace("COMPOSER", QStringToTString(value));
+ break;
+ }
+ case discNumberTag:
+ {
+ properties.replace("DISCNUMBER", QStringToTString(value));
+ break;
+ }
+ case bpmTag:
+ {
+ /* MP4 doesn't support float BPM */
+ properties.replace("BPM", QStringToTString(value));
+ break;
+ }
+ case albumArtistTag:
+ {
+ properties.replace("ALBUMARTIST", QStringToTString(value));
+ break;
+ }
+ case compilationTag:
+ {
+ mp4tag->setItem("cpil", TagLib::MP4::Item(value.toInt() == CompilationYes));
+ break;
+ }
+ default:
+ {
+ break;
+ }
}
+ file->setProperties(properties);
}
}
}
diff --git a/amarok/src/metadata/tplugins.cpp b/amarok/src/metadata/tplugins.cpp
index 0af1eaf9..eb96243e 100644
--- a/amarok/src/metadata/tplugins.cpp
+++ b/amarok/src/metadata/tplugins.cpp
@@ -28,14 +28,6 @@
#include <taglib/fileref.h>
#include <taglib/tfile.h>
-#ifdef HAVE_MP4V2
-#include "mp4/taglib_mp4filetyperesolver.h"
-#include "mp4/mp4file.h"
-#else
-#include "m4a/taglib_mp4filetyperesolver.h"
-#include "m4a/mp4file.h"
-#endif
-
#ifndef TAGLIB_15
#include "trueaudio/taglib_trueaudiofiletyperesolver.h"
#include "trueaudio/ttafile.h"
@@ -62,6 +54,7 @@
#include <taglib/vorbisfile.h>
#include <taglib/flacfile.h>
#include <taglib/mpcfile.h>
+#include <taglib/mp4file.h>
class MimeTypeFileTypeResolver : public TagLib::FileRef::FileTypeResolver
@@ -133,7 +126,6 @@ TagLib::File *MimeTypeFileTypeResolver::createFile(const char *fileName,
void registerTaglibPlugins()
{
//TagLib::FileRef::addFileTypeResolver(new MimeTypeFileTypeResolver);
- TagLib::FileRef::addFileTypeResolver(new MP4FileTypeResolver);
TagLib::FileRef::addFileTypeResolver(new ASFFileTypeResolver);
TagLib::FileRef::addFileTypeResolver(new RealMediaFileTypeResolver);
TagLib::FileRef::addFileTypeResolver(new AudibleFileTypeResolver);