diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-01-25 17:59:07 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-01-25 17:59:07 +0000 |
| commit | 896e79cfd5993010a4a5796205a24ab19fdd48e1 (patch) | |
| tree | 7665669fc6a3a8758f0bfc11f126e08605c5d39d /src/qmmpui/metadataformatter2.cpp | |
| parent | 068ff9837d49f6c92f26741f024981a9ccf83bb1 (diff) | |
| download | qmmp-896e79cfd5993010a4a5796205a24ab19fdd48e1.tar.gz qmmp-896e79cfd5993010a4a5796205a24ab19fdd48e1.tar.bz2 qmmp-896e79cfd5993010a4a5796205a24ab19fdd48e1.zip | |
prepare for new metadata formatter implementation
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4700 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui/metadataformatter2.cpp')
| -rw-r--r-- | src/qmmpui/metadataformatter2.cpp | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/src/qmmpui/metadataformatter2.cpp b/src/qmmpui/metadataformatter2.cpp new file mode 100644 index 000000000..c59151060 --- /dev/null +++ b/src/qmmpui/metadataformatter2.cpp @@ -0,0 +1,209 @@ +/*************************************************************************** + * Copyright (C) 2009-2014 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +/* +Syntax: +%p - artist, +%a - album, +%aa - album artist, +%t - title, +%n - track number, +%NN - 2-digit track number, +%g - genre, +%c - comment, +%C - composer, +%D - disc number, +%f - file name, +%F - full path, +%y - year, +%l - duration, +%if(A,B,C) or %if(A&B&C,D,E) - condition. +*/ + +#include <QStringList> +#include <QUrl> +#include "metadataformatter2.h" + +MetaDataFormatter2::MetaDataFormatter2(const QString &format) +{ + m_format = format; + //compile("%p - %a"); +} + +QString MetaDataFormatter2::parse(const PlayListTrack *item) +{ + return parse(*item, item->length()); +} + +QString MetaDataFormatter2::parse(const QMap<Qmmp::MetaData, QString> &metaData, qint64 length) +{ + /*QString title = m_format; + title.replace("\\(", "%28"); + title.replace("\\)", "%29"); + title.replace(")", "%)"); + title.replace("&", "%&"); + title.replace(",", "%,"); + title.replace("%p", metaData[Qmmp::ARTIST]); + title.replace("%aa", metaData[Qmmp::ALBUMARTIST]); + title.replace("%a", metaData[Qmmp::ALBUM]); + title.replace("%t", metaData[Qmmp::TITLE]); + title.replace("%n", metaData[Qmmp::TRACK]); + title.replace("%NN", QString("%1").arg(metaData[Qmmp::TRACK],2,'0')); + title.replace("%g", metaData[Qmmp::GENRE]); + title.replace("%c", metaData[Qmmp::COMMENT]); + title.replace("%C", metaData[Qmmp::COMPOSER]); + title.replace("%D", metaData[Qmmp::DISCNUMBER]); + title.replace("%f", metaData[Qmmp::URL].section('/',-1)); + title.replace("%F", metaData[Qmmp::URL]); + title.replace("%y", metaData[Qmmp::YEAR]); + if(title.contains("l")) + title.replace("%l",formatLength(length)); + if(title.contains("%if")) + title = processIfKeyWord(title); + title.replace("%28", "("); + title.replace("%29", ")"); + return title.trimmed();*/ + return QString(); +} + +QString MetaDataFormatter2::formatLength(qint64 length) const +{ + if(length <= 0) + return QString(); + QString str; + if(length >= 3600) + str = QString("%1:%2").arg(length/3600).arg(length%3600/60, 2, 10, QChar('0')); + else + str = QString("%1").arg(length%3600/60); + str += QString(":%1").arg(length%60, 2, 10, QChar('0')); + return str; +} + +bool MetaDataFormatter2::processKey(QList<Node> *nodes, QString::const_iterator i, QString::const_iterator end) +{ + QHash<QString, Qmmp::MetaData> key_map; + key_map.insert("p", Qmmp::ARTIST); + key_map.insert("aa", Qmmp::ALBUMARTIST); + key_map.insert("a", Qmmp::ALBUM); + key_map.insert("t", Qmmp::TITLE); + key_map.insert("n", Qmmp::TRACK); + key_map.insert("g", Qmmp::GENRE); + key_map.insert("c", Qmmp::COMMENT); + key_map.insert("C", Qmmp::COMPOSER); + key_map.insert("D", Qmmp::DISCNUMBER); + key_map.insert("F", Qmmp::URL); + key_map.insert("y", Qmmp::YEAR); + + QString token_name = (*i); //2 symbols + i++; //TODO check end + token_name.append(*i); + + Qmmp::MetaData key = key_map.value(token_name, Qmmp::UNKNOWN); + + if(key == Qmmp::UNKNOWN) + { + i--; + token_name = (*i); //1 symbol + key = key_map.value(token_name, Qmmp::UNKNOWN); + } + + if(key != Qmmp::UNKNOWN) + { + Node node; + node.command = Node::PRINT_TEXT; + Param param; + param.type = Param::KEY; + param.key = key; + node.params.append(param); + nodes->append(node); + return true; + } + return false; +} + +void MetaDataFormatter2::processText(QList<MetaDataFormatter2::Node> *nodes, QString::const_iterator i, QString::const_iterator end) +{ + Node node; + node.command = Node::PRINT_TEXT; + Param param; + param.type = Param::TEXT; + node.params.append(param); + + while (i != end) + { + node.params[0].text.append(*i); + i++; + if((*i) == QChar('%')) + { + i--; + nodes->append(node); + return; + } + } + nodes->append(node); +} + +void MetaDataFormatter2::compile(const QString &format) +{ + QString::const_iterator i = format.constBegin(); + + while (i != format.constEnd()) + { + i++; + if((*i) == QChar('%')) + { + i++; + if(processKey(&m_nodes, i, format.constEnd())) + { + continue; + } + } + else + { + processText(&m_nodes, i, format.constEnd()); + continue; + } + } +} + +/*QString MetaDataFormatter::processIfKeyWord(QString title) +{ + int pos = title.lastIndexOf("%if("); + int size = title.indexOf("%)",pos) - pos; + + QStringList args = title.mid (pos + 4, size - 4).split("%,"); + if(args.count() < 3) + { + qWarning("TitleFormatter: invalid title format"); + return title; + } + //process condition + bool cond = true; + foreach(QString arg, args.at(0).split("%&")) + { + cond &= !arg.isEmpty(); + } + QString r_str = cond ? args.at(1) : args.at(2); + title.replace (pos, size + 2, r_str); + if(title.contains("%if")) + return processIfKeyWord(title); + return title; +}*/ |
