aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/PlayListFormats/m3u
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/PlayListFormats/m3u')
-rw-r--r--src/plugins/PlayListFormats/m3u/CMakeLists.txt49
-rw-r--r--src/plugins/PlayListFormats/m3u/m3u.pro33
-rw-r--r--src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp78
-rw-r--r--src/plugins/PlayListFormats/m3u/m3uplaylistformat.h48
4 files changed, 208 insertions, 0 deletions
diff --git a/src/plugins/PlayListFormats/m3u/CMakeLists.txt b/src/plugins/PlayListFormats/m3u/CMakeLists.txt
new file mode 100644
index 000000000..f7a18fb07
--- /dev/null
+++ b/src/plugins/PlayListFormats/m3u/CMakeLists.txt
@@ -0,0 +1,49 @@
+project(libm3uplaylistformat)
+
+cmake_minimum_required(VERSION 2.4.7)
+
+if(COMMAND cmake_policy)
+cmake_policy(SET CMP0003 NEW)
+endif(COMMAND cmake_policy)
+
+
+# qt plugin
+ADD_DEFINITIONS( -Wall )
+ADD_DEFINITIONS(${QT_DEFINITIONS})
+ADD_DEFINITIONS(-DQT_PLUGIN)
+ADD_DEFINITIONS(-DQT_NO_DEBUG)
+ADD_DEFINITIONS(-DQT_SHARED)
+ADD_DEFINITIONS(-DQT_THREAD)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+SET(QT_INCLUDES
+ ${QT_INCLUDES}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../
+)
+
+# libqmmpui
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
+link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui)
+
+SET(libm3uplaylistformat_SRCS
+ m3uplaylistformat.cpp
+)
+
+SET(libm3uplaylistformat_MOC_HDRS
+ m3uplaylistformat.h
+)
+
+QT4_ADD_RESOURCES(libm3uplaylistformat_RCC_SRCS ${libm3uplaylistformat_RCCS})
+
+QT4_WRAP_CPP(libm3uplaylistformat_MOC_SRCS ${libm3uplaylistformat_MOC_HDRS})
+
+
+# Don't forget to include output directory, otherwise
+# the UI file won't be wrapped!
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+ADD_LIBRARY(m3uplaylistformat MODULE ${libm3uplaylistformat_SRCS} ${libm3uplaylistformat_MOC_SRCS})
+add_dependencies(m3uplaylistformat qmmpui)
+target_link_libraries(m3uplaylistformat ${QT_LIBRARIES} -lqmmpui)
+install(TARGETS m3uplaylistformat DESTINATION ${LIB_DIR}/qmmp/PlaylistFormats)
diff --git a/src/plugins/PlayListFormats/m3u/m3u.pro b/src/plugins/PlayListFormats/m3u/m3u.pro
new file mode 100644
index 000000000..b4a435c7f
--- /dev/null
+++ b/src/plugins/PlayListFormats/m3u/m3u.pro
@@ -0,0 +1,33 @@
+include(../../plugins.pri)
+
+CONFIG += release \
+warn_on \
+plugin \
+ lib
+
+TARGET =$$PLUGINS_PREFIX/PlaylistFormats/m3uplaylistformat
+
+TEMPLATE = lib
+QMAKE_LIBDIR += ../../../../lib
+
+INCLUDEPATH += ../../../../src
+
+HEADERS += m3uplaylistformat.h
+
+SOURCES += m3uplaylistformat.cpp
+
+unix {
+ isEmpty(LIB_DIR){
+ LIB_DIR = /lib
+ }
+ target.path = $$LIB_DIR/qmmp/PlaylistFormats
+ INSTALLS += target
+
+ QMAKE_CLEAN =$$PLUGINS_PREFIX/General/libm3uplaylistformat.so
+ LIBS += -lqmmpui
+}
+
+win32 {
+ LIBS += -lqmmpui0
+ QMAKE_LIBDIR += ../../../../bin
+}
diff --git a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp
new file mode 100644
index 000000000..8349f1274
--- /dev/null
+++ b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * Copyright (C) 2008 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. *
+ ***************************************************************************/
+
+#include <QFileInfo>
+#include <QtPlugin>
+#include "m3uplaylistformat.h"
+
+bool M3UPlaylistFormat::hasFormat(const QString &f)
+{
+ return m_supported_formats.contains(f);
+}
+
+QStringList M3UPlaylistFormat::getExtensions() const
+{
+ return m_supported_formats;
+}
+
+M3UPlaylistFormat::M3UPlaylistFormat()
+{
+ m_supported_formats << "m3u";
+}
+
+QStringList M3UPlaylistFormat::decode(const QString & contents)
+{
+ QStringList out;
+ QStringList splitted = contents.split("\n");
+ if(splitted.isEmpty())
+ return QStringList();
+
+ foreach(QString str, splitted)
+ {
+ str = str.trimmed ();
+ if (str.startsWith("#EXTM3U") || str.startsWith("#EXTINF:") || str.isEmpty())
+ continue;//TODO: Let's skip it for now..
+ else if (str.startsWith("#") || str.isEmpty())
+ continue;
+ else
+ out << str;
+ }
+ return out;
+}
+
+QString M3UPlaylistFormat::encode(const QList<PlayListItem*> & contents)
+{
+ QStringList out;
+ out << QString("#EXTM3U");
+ foreach(PlayListItem* f,contents)
+ {
+ QString info = "#EXTINF:" + QString::number(f->length()) + "," + f->value(Qmmp::TITLE);
+ out.append(info);
+ out.append(f->url());
+ }
+ return out.join("\n");
+}
+
+QString M3UPlaylistFormat::name() const
+{
+ return "M3UPlaylistFormat";
+}
+
+Q_EXPORT_PLUGIN2(m3uplaylistformat,M3UPlaylistFormat)
diff --git a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.h b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.h
new file mode 100644
index 000000000..4a5414894
--- /dev/null
+++ b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (C) 2008 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. *
+ ***************************************************************************/
+#ifndef M3UPLAYLISTFORMAT_H
+#define M3UPLAYLISTFORMAT_H
+
+#include <QObject>
+#include <QString>
+#include <QStringList>
+#include <qmmpui/playlistformat.h>
+#include <qmmpui/playlistitem.h>
+
+/*!
+ * Class for M3U playlist format parsing
+ * @author Vladimir Kuznetsov <vovanec@gmail.com>
+ */
+class M3UPlaylistFormat : public QObject, public PlayListFormat
+{
+ Q_OBJECT
+ Q_INTERFACES(PlayListFormat)
+public:
+ M3UPlaylistFormat();
+ virtual QStringList getExtensions()const;
+ virtual bool hasFormat(const QString&);
+ virtual QStringList decode(const QString& contents);
+ virtual QString encode(const QList<PlayListItem*>& contents);
+ virtual QString name()const;
+protected:
+ QStringList m_supported_formats;
+};
+
+#endif