File indexing completed on 2024-04-21 05:51:47
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2008 Dominik Seichter <domseichter@web.de> 0003 0004 #include "taglibplugin.h" 0005 0006 // taglib includes 0007 #include <taglib.h> 0008 #include <fileref.h> 0009 #include <tfile.h> 0010 #include <tstring.h> 0011 #include <tag.h> 0012 0013 #include <KLocalizedString> 0014 0015 #include "batchrenamer.h" 0016 0017 TagLibPlugin::TagLibPlugin(PluginLoader *loader) 0018 : FilePlugin(loader) 0019 { 0020 this->addSupportedToken("tagTitle"); 0021 this->addSupportedToken("tagArtist"); 0022 this->addSupportedToken("tagAlbum"); 0023 this->addSupportedToken("tagComment"); 0024 this->addSupportedToken("tagGenre"); 0025 this->addSupportedToken("tagYear"); 0026 this->addSupportedToken("tagTrack"); 0027 0028 m_help.append("[tagTitle];;" + i18n("Insert the title of a track")); 0029 m_help.append("[tagArtist];;" + i18n("Insert the artist of a track")); 0030 m_help.append("[tagAlbum];;" + i18n("Insert the album of a track")); 0031 m_help.append("[tagComment];;" + i18n("Insert the comment of a track")); 0032 m_help.append("[tagGenre];;" + i18n("Insert the genre of a track")); 0033 m_help.append("[tagYear];;" + i18n("Insert the year of a track")); 0034 m_help.append("[tagTrack];;" + i18n("Insert the number of a track")); 0035 m_help.append("[##tagTrack];;" + i18n("Insert the number of a track formatted with a leading 0")); 0036 0037 m_name = i18n("TagLib (MP3/Ogg) Plugin"); 0038 m_comment = i18n("<qt>This plugin supports reading tags for " 0039 "MP3, Ogg Vorbis, FLAC, MPC, Speex WavPack " 0040 "and TrueAudio files.</qt>"); 0041 m_icon = "audio-x-generic"; 0042 } 0043 0044 QString TagLibPlugin::processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType) 0045 { 0046 QString token(filenameOrToken.toLower()); 0047 QString filename = (*b->files())[index].srcUrl().path(); 0048 0049 TagLib::FileRef g(TagLib::FileName(filename.toUtf8().data())); 0050 TagLib::String result; 0051 0052 if (g.isNull()) { 0053 return QString(""); 0054 } 0055 0056 if (token == "tagtitle") { 0057 result = g.tag()->title(); 0058 } else if (token == "tagartist") { 0059 result = g.tag()->artist(); 0060 } else if (token == "tagalbum") { 0061 result = g.tag()->album(); 0062 } else if (token == "tagcomment") { 0063 result = g.tag()->comment(); 0064 } else if (token == "taggenre") { 0065 result = g.tag()->genre(); 0066 } else if (token == "tagyear") { 0067 unsigned int year = g.tag()->year(); 0068 return QString::number(year); 0069 } else if (token == "tagtrack") { 0070 unsigned int track = g.tag()->track(); 0071 return QString::number(track); 0072 } 0073 0074 return TStringToQString(result); 0075 }