2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-03-01 16:40:12 +01:00
|
|
|
#ifndef M3UPARSER_H
|
|
|
|
#define M3UPARSER_H
|
|
|
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
#include "gtest/gtest_prod.h"
|
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
#include "parserbase.h"
|
2010-03-01 16:40:12 +01:00
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
class M3UParser : public ParserBase {
|
2010-03-01 16:40:12 +01:00
|
|
|
Q_OBJECT
|
2010-05-22 22:06:19 +02:00
|
|
|
|
2010-03-01 16:40:12 +01:00
|
|
|
public:
|
2010-05-22 22:06:19 +02:00
|
|
|
M3UParser(QObject* parent = 0);
|
2010-03-01 16:40:12 +01:00
|
|
|
|
2010-05-23 00:29:52 +02:00
|
|
|
QString name() const { return "M3U"; }
|
2010-05-22 22:06:19 +02:00
|
|
|
QStringList file_extensions() const { return QStringList() << "m3u"; }
|
2010-06-15 15:24:17 +02:00
|
|
|
QString mime_type() const { return "text/uri-list"; }
|
|
|
|
|
|
|
|
bool TryMagic(const QByteArray &data) const;
|
2010-03-01 16:40:12 +01:00
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
SongList Load(QIODevice* device, const QDir& dir = QDir()) const;
|
|
|
|
void Save(const SongList &songs, QIODevice* device, const QDir& dir = QDir()) const;
|
2010-03-01 16:40:12 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum M3UType {
|
|
|
|
STANDARD = 0,
|
|
|
|
EXTENDED, // Includes extended info (track, artist, etc.)
|
2010-03-01 17:31:19 +01:00
|
|
|
LINK, // Points to a directory.
|
2010-03-01 16:40:12 +01:00
|
|
|
};
|
|
|
|
|
2010-05-22 22:06:19 +02:00
|
|
|
struct Metadata {
|
|
|
|
Metadata() : length(-1) {}
|
|
|
|
QString artist;
|
|
|
|
QString title;
|
|
|
|
int length;
|
|
|
|
};
|
|
|
|
|
2010-03-01 17:31:19 +01:00
|
|
|
bool ParseMetadata(const QString& line, Metadata* metadata) const;
|
2010-03-01 16:40:12 +01:00
|
|
|
|
|
|
|
FRIEND_TEST(M3UParserTest, ParsesMetadata);
|
|
|
|
FRIEND_TEST(M3UParserTest, ParsesTrackLocation);
|
2010-03-01 17:31:19 +01:00
|
|
|
FRIEND_TEST(M3UParserTest, ParsesTrackLocationRelative);
|
|
|
|
FRIEND_TEST(M3UParserTest, ParsesTrackLocationHttp);
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
FRIEND_TEST(M3UParserTest, ParsesTrackLocationAbsoluteWindows);
|
|
|
|
#endif // Q_OS_WIN32
|
2010-03-01 16:40:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // M3UPARSER_H
|