strawberry-audio-player-win.../src/playlistparsers/m3uparser.h

78 lines
2.5 KiB
C
Raw Permalink Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef M3UPARSER_H
#define M3UPARSER_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QStringList>
2020-02-08 15:03:11 +01:00
#include <QDir>
2024-10-22 18:12:33 +02:00
#include "includes/shared_ptr.h"
#include "constants/playlistsettings.h"
#include "core/song.h"
2018-02-27 18:06:05 +01:00
#include "parserbase.h"
2020-02-08 15:03:11 +01:00
class QIODevice;
2024-10-22 18:12:33 +02:00
class TagReaderClient;
class CollectionBackendInterface;
2018-02-27 18:06:05 +01:00
class M3UParser : public ParserBase {
Q_OBJECT
public:
2024-10-22 18:12:33 +02:00
explicit M3UParser(const SharedPtr<TagReaderClient> tagreader_client, const SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent = nullptr);
2018-02-27 18:06:05 +01:00
2024-04-09 23:20:26 +02:00
QString name() const override { return QStringLiteral("M3U"); }
QStringList file_extensions() const override { return QStringList() << QStringLiteral("m3u") << QStringLiteral("m3u8"); }
QString mime_type() const override { return QStringLiteral("text/uri-list"); }
bool load_supported() const override { return true; }
bool save_supported() const override { return true; }
2018-02-27 18:06:05 +01:00
2020-06-15 21:55:05 +02:00
bool TryMagic(const QByteArray &data) const override;
2018-02-27 18:06:05 +01:00
2024-10-18 20:17:23 +02:00
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
2024-10-22 18:12:33 +02:00
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettings::PathType path_type = PlaylistSettings::PathType::Automatic) const override;
2018-02-27 18:06:05 +01:00
private:
2023-02-18 14:09:27 +01:00
enum class M3UType {
2018-02-27 18:06:05 +01:00
STANDARD = 0,
EXTENDED, // Includes extended info (track, artist, etc.)
LINK, // Points to a directory.
};
struct Metadata {
Metadata() : length(-1) {}
QString artist;
QString title;
qint64 length;
};
2021-07-11 09:49:38 +02:00
static bool ParseMetadata(const QString &line, Metadata *metadata);
2018-02-27 18:06:05 +01:00
};
#endif // M3UPARSER_H