diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2020-02-17 20:06:06 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2020-02-17 20:06:06 +0000 |
| commit | 019a22234ad4f16a9a6a1122f9627b26edb0d377 (patch) | |
| tree | ba41077e4177749438168f600baf48432e212048 | |
| parent | e1017affecb9519173db73fefa6152b9bdef26e8 (diff) | |
| download | qmmp-019a22234ad4f16a9a6a1122f9627b26edb0d377.tar.gz qmmp-019a22234ad4f16a9a6a1122f9627b26edb0d377.tar.bz2 qmmp-019a22234ad4f16a9a6a1122f9627b26edb0d377.zip | |
mpeg: feature to merge tags (#262)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9228 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/Input/mpeg/decodermpegfactory.cpp | 110 | ||||
| -rw-r--r-- | src/plugins/Input/mpeg/settingsdialog.cpp | 2 | ||||
| -rw-r--r-- | src/plugins/Input/mpeg/settingsdialog.ui | 14 |
3 files changed, 74 insertions, 52 deletions
diff --git a/src/plugins/Input/mpeg/decodermpegfactory.cpp b/src/plugins/Input/mpeg/decodermpegfactory.cpp index e0ce11944..c13a15145 100644 --- a/src/plugins/Input/mpeg/decodermpegfactory.cpp +++ b/src/plugins/Input/mpeg/decodermpegfactory.cpp @@ -212,7 +212,6 @@ QList<TrackInfo *> DecoderMPEGFactory::createPlayList(const QString &path, Track if(parts == TrackInfo::Parts()) return QList<TrackInfo*>() << info; - TagLib::Tag *tag = nullptr; TagLib::FileStream stream(QStringToFileName(path), true); TagLib::MPEG::File fileRef(&stream, TagLib::ID3v2::FrameFactory::instance()); @@ -221,17 +220,19 @@ QList<TrackInfo *> DecoderMPEGFactory::createPlayList(const QString &path, Track QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("MPEG"); - QTextCodec *codec = nullptr; - + QList< QMap<Qmmp::MetaData, QString> > metaData; uint tag_array[3]; tag_array[0] = settings.value("tag_1", SettingsDialog::ID3v2).toInt(); tag_array[1] = settings.value("tag_2", SettingsDialog::APE).toInt(); tag_array[2] = settings.value("tag_3", SettingsDialog::ID3v1).toInt(); + bool merge = settings.value("merge_tags", false).toBool(); - QByteArray codecName; for (int i = 0; i < 3; ++i) { - codecName.clear(); + QTextCodec *codec = nullptr; + TagLib::Tag *tag = nullptr; + QByteArray codecName; + switch ((uint) tag_array[i]) { case SettingsDialog::ID3v1: @@ -249,61 +250,70 @@ QList<TrackInfo *> DecoderMPEGFactory::createPlayList(const QString &path, Track case SettingsDialog::Disabled: break; } - if (tag && !tag->isEmpty()) - { - if(codecName.contains("UTF")) - codecName = "UTF-8"; - if(!codecName.isEmpty()) - codec = QTextCodec::codecForName(codecName); - break; - } - } - settings.endGroup(); - if(m_using_rusxmms) - codec = QTextCodec::codecForName("UTF-8"); + if(m_using_rusxmms || codecName.contains("UTF")) + codec = QTextCodec::codecForName("UTF-8"); + else if(!codecName.isEmpty()) + codec = QTextCodec::codecForName(codecName); - if (!codec) - codec = QTextCodec::codecForName("UTF-8"); + if (!codec) + codec = QTextCodec::codecForName("UTF-8"); - if (tag && codec) - { - bool utf = codec->name().contains("UTF"); - info->setValue(Qmmp::ALBUM, CSTR_TO_QSTR(tag->album(), utf)); - info->setValue(Qmmp::ARTIST, CSTR_TO_QSTR(tag->artist(), utf)); - info->setValue(Qmmp::COMMENT, CSTR_TO_QSTR(tag->comment(), utf)); - info->setValue(Qmmp::GENRE, CSTR_TO_QSTR(tag->genre(), utf)); - info->setValue(Qmmp::TITLE, CSTR_TO_QSTR(tag->title(), utf)); - info->setValue(Qmmp::YEAR, tag->year()); - info->setValue(Qmmp::TRACK, tag->track()); - - if(tag == fileRef.ID3v2Tag()) + if (tag && codec && !tag->isEmpty()) { - if(!fileRef.ID3v2Tag()->frameListMap()["TPE2"].isEmpty()) + bool utf = codec->name().contains("UTF"); + QMap<Qmmp::MetaData, QString> tags = { + { Qmmp::ARTIST, CSTR_TO_QSTR(tag->artist(), utf) }, + { Qmmp::ALBUM, CSTR_TO_QSTR(tag->album(), utf) }, + { Qmmp::COMMENT, CSTR_TO_QSTR(tag->comment(), utf) }, + { Qmmp::GENRE, CSTR_TO_QSTR(tag->genre(), utf) }, + { Qmmp::TITLE, CSTR_TO_QSTR(tag->title(), utf) }, + { Qmmp::YEAR, QString::number(tag->year()) }, + { Qmmp::TRACK, QString::number(tag->track()) }, + }; + + if(tag == fileRef.ID3v2Tag()) { - TagLib::String albumArtist; - albumArtist = fileRef.ID3v2Tag()->frameListMap()["TPE2"].front()->toString(); - info->setValue(Qmmp::ALBUMARTIST, CSTR_TO_QSTR(albumArtist, utf)); + if(!fileRef.ID3v2Tag()->frameListMap()["TPE2"].isEmpty()) + { + TagLib::String albumArtist = fileRef.ID3v2Tag()->frameListMap()["TPE2"].front()->toString(); + tags.insert(Qmmp::ALBUMARTIST, CSTR_TO_QSTR(albumArtist, utf)); + } + if(!fileRef.ID3v2Tag()->frameListMap()["TCOM"].isEmpty()) + { + TagLib::String composer = fileRef.ID3v2Tag()->frameListMap()["TCOM"].front()->toString(); + tags.insert(Qmmp::COMPOSER, CSTR_TO_QSTR(composer, utf)); + } + if(!fileRef.ID3v2Tag()->frameListMap()["TPOS"].isEmpty()) + { + TagLib::String disc = fileRef.ID3v2Tag()->frameListMap()["TPOS"].front()->toString(); + tags.insert(Qmmp::DISCNUMBER, CSTR_TO_QSTR(disc, utf)); + } } - if(!fileRef.ID3v2Tag()->frameListMap()["TCOM"].isEmpty()) + else if(tag == fileRef.APETag()) { - TagLib::String composer; - composer = fileRef.ID3v2Tag()->frameListMap()["TCOM"].front()->toString(); - info->setValue(Qmmp::COMPOSER, CSTR_TO_QSTR(composer, utf)); - } - if(!fileRef.ID3v2Tag()->frameListMap()["TPOS"].isEmpty()) - { - TagLib::String disc = fileRef.ID3v2Tag()->frameListMap()["TPOS"].front()->toString(); - info->setValue(Qmmp::DISCNUMBER, CSTR_TO_QSTR(disc, utf)); + TagLib::APE::Item fld; + if(!(fld = fileRef.APETag()->itemListMap()["ALBUM ARTIST"]).isEmpty()) + tags.insert(Qmmp::ALBUMARTIST, CSTR_TO_QSTR(fld.toString(), true)); + if(!(fld = fileRef.APETag()->itemListMap()["COMPOSER"]).isEmpty()) + tags.insert(Qmmp::COMPOSER, CSTR_TO_QSTR(fld.toString(), true)); } + + metaData << tags; + + if(!merge) + break; } - else if(tag == fileRef.APETag()) + } + settings.endGroup(); + + for(const QMap<Qmmp::MetaData, QString> &tags : qAsConst(metaData)) + { + for(int i = Qmmp::TITLE; i < Qmmp::DISCNUMBER; ++i) { - TagLib::APE::Item fld; - if(!(fld = fileRef.APETag()->itemListMap()["ALBUM ARTIST"]).isEmpty()) - info->setValue(Qmmp::ALBUMARTIST, CSTR_TO_QSTR(fld.toString(), true)); - if(!(fld = fileRef.APETag()->itemListMap()["COMPOSER"]).isEmpty()) - info->setValue(Qmmp::COMPOSER, CSTR_TO_QSTR(fld.toString(), true)); + Qmmp::MetaData key = static_cast<Qmmp::MetaData>(i); + if(info->value(key).length() < tags.value(key).length()) + info->setValue(key, tags.value(key)); } } } diff --git a/src/plugins/Input/mpeg/settingsdialog.cpp b/src/plugins/Input/mpeg/settingsdialog.cpp index eccb5d1e2..3e969729b 100644 --- a/src/plugins/Input/mpeg/settingsdialog.cpp +++ b/src/plugins/Input/mpeg/settingsdialog.cpp @@ -59,6 +59,7 @@ SettingsDialog::SettingsDialog(bool using_rusxmms, QWidget *parent) m_ui.firstTagComboBox->setCurrentIndex(settings.value("tag_1", ID3v2).toInt()); m_ui.secondTagComboBox->setCurrentIndex(settings.value("tag_2", APE).toInt()); m_ui.thirdTagComboBox->setCurrentIndex(settings.value("tag_3", ID3v1).toInt()); + m_ui.mergeTagsCheckBox->setChecked(settings.value("merge_tags", false).toBool()); settings.endGroup(); @@ -83,6 +84,7 @@ void SettingsDialog::accept() settings.setValue("tag_1", m_ui.firstTagComboBox->currentIndex()); settings.setValue("tag_2", m_ui.secondTagComboBox->currentIndex()); settings.setValue("tag_3", m_ui.thirdTagComboBox->currentIndex()); + settings.setValue("merge_tags", m_ui.mergeTagsCheckBox->isChecked()); settings.endGroup(); QDialog::accept(); } diff --git a/src/plugins/Input/mpeg/settingsdialog.ui b/src/plugins/Input/mpeg/settingsdialog.ui index d7463f350..7465f5373 100644 --- a/src/plugins/Input/mpeg/settingsdialog.ui +++ b/src/plugins/Input/mpeg/settingsdialog.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>294</width> - <height>362</height> + <width>380</width> + <height>391</height> </rect> </property> <property name="windowTitle"> @@ -237,6 +237,16 @@ </property> </spacer> </item> + <item row="3" column="0" colspan="4"> + <widget class="QCheckBox" name="mergeTagsCheckBox"> + <property name="text"> + <string>Merge selected tag types</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> </layout> </widget> </item> |
