1 /* This file is part of Clementine. 2 Copyright 2010, David Sansome <me@davidsansome.com> 3 4 Clementine is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 Clementine is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with Clementine. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef M3UPARSER_H 19 #define M3UPARSER_H 20 21 #include <QUrl> 22 23 #include "gtest/gtest_prod.h" 24 25 #include "parserbase.h" 26 27 class M3UParser : public ParserBase { 28 Q_OBJECT 29 30 public: 31 M3UParser(LibraryBackendInterface* library, QObject* parent = nullptr); 32 name()33 QString name() const { return "M3U"; } file_extensions()34 QStringList file_extensions() const { 35 return QStringList() << "m3u" 36 << "m3u8"; 37 } mime_type()38 QString mime_type() const { return "text/uri-list"; } 39 40 bool TryMagic(const QByteArray& data) const; 41 42 SongList Load(QIODevice* device, const QString& playlist_path = "", 43 const QDir& dir = QDir()) const; 44 void Save(const SongList& songs, QIODevice* device, const QDir& dir = QDir(), 45 Playlist::Path path_type = Playlist::Path_Automatic) const; 46 47 private: 48 enum M3UType { 49 STANDARD = 0, 50 EXTENDED, // Includes extended info (track, artist, etc.) 51 LINK, // Points to a directory. 52 }; 53 54 struct Metadata { MetadataMetadata55 Metadata() : length(-1) {} 56 QString artist; 57 QString title; 58 qint64 length; 59 }; 60 61 bool ParseMetadata(const QString& line, Metadata* metadata) const; 62 63 FRIEND_TEST(M3UParserTest, ParsesMetadata); 64 FRIEND_TEST(M3UParserTest, ParsesTrackLocation); 65 FRIEND_TEST(M3UParserTest, ParsesTrackLocationRelative); 66 FRIEND_TEST(M3UParserTest, ParsesTrackLocationHttp); 67 #ifdef Q_OS_WIN32 68 FRIEND_TEST(M3UParserTest, ParsesTrackLocationAbsoluteWindows); 69 #endif // Q_OS_WIN32 70 }; 71 72 #endif // M3UPARSER_H 73