aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui/metadataformatter.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-11-21 17:13:34 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-11-21 17:13:34 +0000
commit90b71df1362b7e128ca99ee09cc8402b8421f76d (patch)
tree24faee1a7b7b0f7610015a8f57ffa60b2865f7c9 /src/qmmpui/metadataformatter.cpp
parentbfda47d04f9f520638f652bdb7fffb6de3dfd992 (diff)
downloadqmmp-90b71df1362b7e128ca99ee09cc8402b8421f76d.tar.gz
qmmp-90b71df1362b7e128ca99ee09cc8402b8421f76d.tar.bz2
qmmp-90b71df1362b7e128ca99ee09cc8402b8421f76d.zip
added metadata formatter
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1389 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui/metadataformatter.cpp')
-rw-r--r--src/qmmpui/metadataformatter.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/qmmpui/metadataformatter.cpp b/src/qmmpui/metadataformatter.cpp
new file mode 100644
index 000000000..9a055f4e9
--- /dev/null
+++ b/src/qmmpui/metadataformatter.cpp
@@ -0,0 +1,98 @@
+/***************************************************************************
+ * Copyright (C) 2009 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+
+/*
+Syntax:
+%p - artist
+%a - album
+%t - title
+%n - track,
+%NN - 2-digit track
+%g - genre
+%c - comment
+%C - composer
+%D - disc number
+%f - file name
+%F - full path
+%y - year
+%if(A,B,C)
+%if(A&B&C,D,E)
+*/
+
+#include <QStringList>
+#include <QUrl>
+#include "metadataformatter.h"
+
+MetaDataFormatter::MetaDataFormatter(const QString &format)
+{
+ m_format = format;
+}
+
+QString MetaDataFormatter::parse(const QMap<Qmmp::MetaData, QString> metaData)
+{
+ QString title = m_format;
+ title.replace("\\(", "%28");
+ title.replace("\\)", "%29");
+ title.replace(")", "%)");
+ title.replace("&", "%&");
+ title.replace("%p", metaData[Qmmp::ARTIST]);
+ 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("%if"))
+ title = processIfKeyWord(title);
+ title.replace("%28", "(");
+ title.replace("%29", ")");
+ return title;
+}
+
+QString MetaDataFormatter::processIfKeyWord(QString title)
+{
+ int pos = title.indexOf("%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;
+}