mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Add Python bindings for PlaylistParser
This commit is contained in:
parent
1344103515
commit
c6d724f53a
@ -116,6 +116,17 @@ SongList PlaylistParser::Load(const QString &filename, const QString& playlist_p
|
||||
return parser->Load(&file, playlist_path, info.absolutePath());
|
||||
}
|
||||
|
||||
SongList PlaylistParser::Load(QIODevice* device, const QString& path_hint,
|
||||
const QDir& dir_hint) const {
|
||||
// Find a parser that supports this data
|
||||
ParserBase* parser = MaybeGetParserForMagic(device->peek(kMagicSize));
|
||||
if (!parser) {
|
||||
return SongList();
|
||||
}
|
||||
|
||||
return parser->Load(device, path_hint, dir_hint);
|
||||
}
|
||||
|
||||
void PlaylistParser::Save(const SongList &songs, const QString &filename) const {
|
||||
QFileInfo info(filename);
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef PLAYLISTPARSER_H
|
||||
#define PLAYLISTPARSER_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QObject>
|
||||
|
||||
#include "core/song.h"
|
||||
@ -44,6 +45,7 @@ public:
|
||||
ParserBase* ParserForExtension(const QString& suffix) const;
|
||||
|
||||
SongList Load(const QString& filename, const QString& playlist_path = "", ParserBase* parser = 0) const;
|
||||
SongList Load(QIODevice* device, const QString& path_hint = "", const QDir& dir_hint = QDir()) const;
|
||||
void Save(const SongList& songs, const QString& filename) const;
|
||||
|
||||
private:
|
||||
|
@ -11,10 +11,12 @@
|
||||
%Include libraryquery.sip
|
||||
%Include mergedproxymodel.sip
|
||||
%Include network.sip
|
||||
%Include parserbase.sip
|
||||
%Include player.sip
|
||||
%Include playlist.sip
|
||||
%Include playlistitem.sip
|
||||
%Include playlistmanager.sip
|
||||
%Include playlistparser.sip
|
||||
%Include playlistsequence.sip
|
||||
%Include pythonengine.sip
|
||||
%Include radiomodel.sip
|
||||
|
17
src/scripting/python/parserbase.sip
Normal file
17
src/scripting/python/parserbase.sip
Normal file
@ -0,0 +1,17 @@
|
||||
class ParserBase : QObject {
|
||||
%TypeHeaderCode
|
||||
#include "playlistparsers/parserbase.h"
|
||||
%End
|
||||
|
||||
public:
|
||||
ParserBase(LibraryBackend* library, QObject* parent /TransferThis/ = 0);
|
||||
|
||||
virtual QString name() const = 0;
|
||||
virtual QStringList file_extensions() const = 0;
|
||||
virtual QString mime_type() const;
|
||||
|
||||
virtual bool TryMagic(const QByteArray& data) const = 0;
|
||||
|
||||
virtual SongList Load(QIODevice* device, const QString& playlist_path = "", const QDir& dir = QDir()) const = 0;
|
||||
virtual void Save(const SongList& songs, QIODevice* device, const QDir& dir = QDir()) const = 0;
|
||||
};
|
24
src/scripting/python/playlistparser.sip
Normal file
24
src/scripting/python/playlistparser.sip
Normal file
@ -0,0 +1,24 @@
|
||||
class PlaylistParser : QObject {
|
||||
%TypeHeaderCode
|
||||
#include "playlistparsers/playlistparser.h"
|
||||
%End
|
||||
|
||||
public:
|
||||
PlaylistParser(LibraryBackend* library, QObject* parent /TransferThis/ = 0);
|
||||
|
||||
static const int kMagicSize;
|
||||
|
||||
QStringList file_extensions() const;
|
||||
QString filters() const;
|
||||
|
||||
QString default_extension() const;
|
||||
QString default_filter() const;
|
||||
|
||||
ParserBase* MaybeGetParserForMagic(const QByteArray& data,
|
||||
const QString& mime_type = QString()) const;
|
||||
ParserBase* ParserForExtension(const QString& suffix) const;
|
||||
|
||||
SongList Load(const QString& filename, const QString& playlist_path = "", ParserBase* parser = 0) const;
|
||||
SongList Load(QIODevice* device, const QString& path_hint = "", const QDir& dir_hint = QDir()) const;
|
||||
void Save(const SongList& songs, const QString& filename) const;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user