@@ -44,7 +44,7 @@ bool AsxIniParser::TryMagic(const QByteArray &data) const {
|
||||
return data.toLower().contains("[reference]");
|
||||
}
|
||||
|
||||
SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const {
|
||||
SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
Q_UNUSED(playlist_path);
|
||||
|
||||
@@ -57,7 +57,7 @@ SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, con
|
||||
QString value = line.mid(equals + 1);
|
||||
|
||||
if (key.startsWith("ref")) {
|
||||
Song song = LoadSong(value, 0, dir);
|
||||
Song song = LoadSong(value, 0, dir, collection_search);
|
||||
if (song.is_valid()) {
|
||||
ret << song;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class AsxIniParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class CollectionBackendInterface;
|
||||
ASXParser::ASXParser(CollectionBackendInterface *collection, QObject *parent)
|
||||
: XMLParser(collection, parent) {}
|
||||
|
||||
SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const {
|
||||
SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
Q_UNUSED(playlist_path);
|
||||
|
||||
@@ -73,7 +73,7 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
|
||||
while (!reader.atEnd() && Utilities::ParseUntilElementCI(&reader, "entry")) {
|
||||
Song song = ParseTrack(&reader, dir);
|
||||
Song song = ParseTrack(&reader, dir, collection_search);
|
||||
if (song.is_valid()) {
|
||||
ret << song;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
}
|
||||
|
||||
Song ASXParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir) const {
|
||||
Song ASXParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
QString title, artist, album, ref;
|
||||
|
||||
@@ -117,7 +117,7 @@ Song ASXParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir) const {
|
||||
}
|
||||
|
||||
return_song:
|
||||
Song song = LoadSong(ref, 0, dir);
|
||||
Song song = LoadSong(ref, 0, dir, collection_search);
|
||||
|
||||
// Override metadata with what was in the playlist
|
||||
if (song.source() != Song::Source_Collection) {
|
||||
|
||||
@@ -48,11 +48,11 @@ class ASXParser : public XMLParser {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
|
||||
private:
|
||||
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir) const;
|
||||
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -58,7 +58,7 @@ const char *CueParser::kDisc = "discnumber";
|
||||
CueParser::CueParser(CollectionBackendInterface *collection, QObject *parent)
|
||||
: ParserBase(collection, parent) {}
|
||||
|
||||
SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const {
|
||||
SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
SongList ret;
|
||||
|
||||
@@ -230,7 +230,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
for (int i = 0; i < entries.length(); i++) {
|
||||
CueEntry entry = entries.at(i);
|
||||
|
||||
Song song = LoadSong(entry.file, IndexToMarker(entry.index), dir);
|
||||
Song song = LoadSong(entry.file, IndexToMarker(entry.index), dir, collection_search);
|
||||
|
||||
// Cue song has mtime equal to qMax(media_file_mtime, cue_sheet_mtime)
|
||||
if (cue_mtime.isValid()) {
|
||||
|
||||
@@ -67,7 +67,7 @@ class CueParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -42,7 +42,7 @@ class CollectionBackendInterface;
|
||||
M3UParser::M3UParser(CollectionBackendInterface *collection, QObject *parent)
|
||||
: ParserBase(collection, parent) {}
|
||||
|
||||
SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const {
|
||||
SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
Q_UNUSED(playlist_path);
|
||||
|
||||
@@ -75,7 +75,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
}
|
||||
else if (!line.isEmpty()) {
|
||||
Song song = LoadSong(line, 0, dir);
|
||||
Song song = LoadSong(line, 0, dir, collection_search);
|
||||
if (!current_metadata.title.isEmpty()) {
|
||||
song.set_title(current_metadata.title);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class M3UParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
ParserBase::ParserBase(CollectionBackendInterface *collection, QObject *parent)
|
||||
: QObject(parent), collection_(collection) {}
|
||||
|
||||
void ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir, Song *song) const {
|
||||
void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning, const QDir &dir, Song *song, const bool collection_search) const {
|
||||
|
||||
if (filename_or_url.isEmpty()) {
|
||||
return;
|
||||
@@ -78,25 +78,24 @@ void ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, cons
|
||||
const QUrl url = QUrl::fromLocalFile(filename);
|
||||
|
||||
// Search in the collection
|
||||
Song collection_song(Song::Source_Collection);
|
||||
if (collection_) {
|
||||
collection_song = collection_->GetSongByUrl(url, beginning);
|
||||
if (collection_ && collection_search) {
|
||||
Song collection_song = collection_->GetSongByUrl(url, beginning);
|
||||
// If it was found in the collection then use it, otherwise load metadata from disk.
|
||||
if (collection_song.is_valid()) {
|
||||
*song = collection_song;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If it was found in the collection then use it, otherwise load metadata from disk.
|
||||
if (collection_song.is_valid()) {
|
||||
*song = collection_song;
|
||||
}
|
||||
else {
|
||||
TagReaderClient::Instance()->ReadFileBlocking(filename, song);
|
||||
}
|
||||
TagReaderClient::Instance()->ReadFileBlocking(filename, song);
|
||||
|
||||
}
|
||||
|
||||
Song ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir) const {
|
||||
Song ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
Song song(Song::Source_LocalFile);
|
||||
LoadSong(filename_or_url, beginning, dir, &song);
|
||||
LoadSong(filename_or_url, beginning, dir, &song, collection_search);
|
||||
|
||||
return song;
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class ParserBase : public QObject {
|
||||
// This method might not return all of the songs found in the playlist.
|
||||
// Any playlist parser may decide to leave out some entries if it finds them incomplete or invalid.
|
||||
// This means that the final resulting SongList should be considered valid (at least from the parser's point of view).
|
||||
virtual SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const = 0;
|
||||
virtual SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_lookup = true) const = 0;
|
||||
virtual void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const = 0;
|
||||
|
||||
protected:
|
||||
@@ -62,8 +62,8 @@ class ParserBase : public QObject {
|
||||
// If it is a filename or a file:// URL then it is made absolute and canonical and set as a file:// url on the song.
|
||||
// Also sets the song's metadata by searching in the Collection, or loading from the file as a fallback.
|
||||
// This function should always be used when loading a playlist.
|
||||
Song LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir) const;
|
||||
void LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir, Song *song) const;
|
||||
Song LoadSong(const QString &filename_or_url, const qint64 beginning, const QDir &dir, const bool collection_search) const;
|
||||
void LoadSong(const QString &filename_or_url, const qint64 beginning, const QDir &dir, Song *song, const bool collection_search) const;
|
||||
|
||||
// If the URL is a file:// URL then returns its path, absolute or relative to the directory depending on the path_type option.
|
||||
// Otherwise returns the URL as is. This function should always be used when saving a playlist.
|
||||
|
||||
@@ -44,7 +44,7 @@ class CollectionBackendInterface;
|
||||
PLSParser::PLSParser(CollectionBackendInterface *collection, QObject *parent)
|
||||
: ParserBase(collection, parent) {}
|
||||
|
||||
SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const {
|
||||
SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
Q_UNUSED(playlist_path);
|
||||
|
||||
@@ -61,7 +61,7 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
int n = re_match.captured(0).toInt();
|
||||
|
||||
if (key.startsWith("file")) {
|
||||
Song song = LoadSong(value, 0, dir);
|
||||
Song song = LoadSong(value, 0, dir, collection_search);
|
||||
|
||||
// Use the title and length we've already loaded if any
|
||||
if (!songs[n].title().isEmpty()) song.set_title(songs[n].title());
|
||||
|
||||
@@ -47,7 +47,7 @@ class PLSParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ bool WplParser::TryMagic(const QByteArray &data) const {
|
||||
return data.contains("<?wpl") || data.contains("<smil>");
|
||||
}
|
||||
|
||||
SongList WplParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const {
|
||||
SongList WplParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
Q_UNUSED(playlist_path);
|
||||
|
||||
@@ -53,13 +53,13 @@ SongList WplParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
|
||||
while (!reader.atEnd() && Utilities::ParseUntilElement(&reader, "seq")) {
|
||||
ParseSeq(dir, &reader, &ret);
|
||||
ParseSeq(dir, &reader, &ret, collection_search);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs) const {
|
||||
void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs, const bool collection_search) const {
|
||||
|
||||
while (!reader->atEnd()) {
|
||||
QXmlStreamReader::TokenType type = reader->readNext();
|
||||
@@ -69,7 +69,7 @@ void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *so
|
||||
if (name == "media") {
|
||||
QString src = reader->attributes().value("src").toString();
|
||||
if (!src.isEmpty()) {
|
||||
Song song = LoadSong(src, 0, dir);
|
||||
Song song = LoadSong(src, 0, dir, collection_search);
|
||||
if (song.is_valid()) {
|
||||
songs->append(song);
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ class WplParser : public XMLParser {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
|
||||
private:
|
||||
void ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs) const;
|
||||
void ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs, const bool collection_search = true) const;
|
||||
void WriteMeta(const QString &name, const QString &content, QXmlStreamWriter *writer) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class CollectionBackendInterface;
|
||||
XSPFParser::XSPFParser(CollectionBackendInterface *collection, QObject *parent)
|
||||
: XMLParser(collection, parent) {}
|
||||
|
||||
SongList XSPFParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir) const {
|
||||
SongList XSPFParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
Q_UNUSED(playlist_path);
|
||||
|
||||
@@ -54,7 +54,7 @@ SongList XSPFParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
|
||||
while (!reader.atEnd() && Utilities::ParseUntilElement(&reader, "track")) {
|
||||
Song song = ParseTrack(&reader, dir);
|
||||
Song song = ParseTrack(&reader, dir, collection_search);
|
||||
if (song.is_valid()) {
|
||||
ret << song;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ SongList XSPFParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
}
|
||||
|
||||
Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir) const {
|
||||
Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const {
|
||||
|
||||
QString title, artist, album, location;
|
||||
qint64 nanosec = -1;
|
||||
@@ -121,7 +121,7 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir) const {
|
||||
}
|
||||
|
||||
return_song:
|
||||
Song song = LoadSong(location, 0, dir);
|
||||
Song song = LoadSong(location, 0, dir, collection_search);
|
||||
|
||||
// Override metadata with what was in the playlist
|
||||
if (song.source() != Song::Source_Collection) {
|
||||
|
||||
@@ -48,11 +48,11 @@ class XSPFParser : public XMLParser {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
|
||||
private:
|
||||
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir) const;
|
||||
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user