playlistparsers: Rename collection_search to collection_lookup

This commit is contained in:
Jonas Kvinge 2024-07-01 01:51:48 +02:00
parent c1f66b1885
commit ad9f3ce078
16 changed files with 41 additions and 40 deletions

View File

@ -46,7 +46,7 @@ bool AsxIniParser::TryMagic(const QByteArray &data) const {
return data.toLower().contains("[reference]"); return data.toLower().contains("[reference]");
} }
SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const { SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup) const {
Q_UNUSED(playlist_path); Q_UNUSED(playlist_path);
@ -59,7 +59,7 @@ SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, con
QString value = line.mid(equals + 1); QString value = line.mid(equals + 1);
if (key.startsWith(QLatin1String("ref"))) { if (key.startsWith(QLatin1String("ref"))) {
Song song = LoadSong(value, 0, 0, dir, collection_search); Song song = LoadSong(value, 0, 0, dir, collection_lookup);
if (song.is_valid()) { if (song.is_valid()) {
ret << song; ret << song;
} }

View File

@ -50,7 +50,7 @@ class AsxIniParser : public ParserBase {
bool TryMagic(const QByteArray &data) const override; bool TryMagic(const QByteArray &data) const override;
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_search = true) const override; SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override; void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
}; };

View File

@ -40,7 +40,7 @@ class CollectionBackendInterface;
ASXParser::ASXParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent) ASXParser::ASXParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
: XMLParser(collection_backend, parent) {} : XMLParser(collection_backend, parent) {}
SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const { SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup) const {
Q_UNUSED(playlist_path); Q_UNUSED(playlist_path);
@ -71,7 +71,7 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
SongList ret; SongList ret;
while (!reader.atEnd() && Utilities::ParseUntilElementCI(&reader, QStringLiteral("entry"))) { while (!reader.atEnd() && Utilities::ParseUntilElementCI(&reader, QStringLiteral("entry"))) {
Song song = ParseTrack(&reader, dir, collection_search); Song song = ParseTrack(&reader, dir, collection_lookup);
if (song.is_valid()) { if (song.is_valid()) {
ret << song; 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 bool collection_search) const { Song ASXParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_lookup) const {
QString title, artist, album, ref; QString title, artist, album, ref;
@ -117,7 +117,7 @@ Song ASXParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool
} }
return_song: return_song:
Song song = LoadSong(ref, 0, 0, dir, collection_search); Song song = LoadSong(ref, 0, 0, dir, collection_lookup);
// Override metadata with what was in the playlist // Override metadata with what was in the playlist
if (song.source() != Song::Source::Collection) { if (song.source() != Song::Source::Collection) {

View File

@ -52,11 +52,11 @@ class ASXParser : public XMLParser {
bool TryMagic(const QByteArray &data) const override; bool TryMagic(const QByteArray &data) const override;
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_search = true) const override; SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override; void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
private: private:
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const; Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_lookup) const;
}; };
#endif #endif

View File

@ -68,7 +68,7 @@ constexpr char kDisc[] = "discnumber";
CueParser::CueParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent) CueParser::CueParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
: ParserBase(collection_backend, parent) {} : ParserBase(collection_backend, parent) {}
SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const { SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup) const {
SongList ret; SongList ret;
@ -266,7 +266,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
for (int i = 0; i < entries.length(); i++) { for (int i = 0; i < entries.length(); i++) {
CueEntry entry = entries.at(i); CueEntry entry = entries.at(i);
Song song = LoadSong(entry.file, IndexToMarker(entry.index), 0, dir, collection_search); Song song = LoadSong(entry.file, IndexToMarker(entry.index), 0, dir, collection_lookup);
// Cue song has mtime equal to qMax(media_file_mtime, cue_sheet_mtime) // Cue song has mtime equal to qMax(media_file_mtime, cue_sheet_mtime)
if (cue_mtime.isValid()) { if (cue_mtime.isValid()) {

View File

@ -55,7 +55,7 @@ class CueParser : public ParserBase {
bool TryMagic(const QByteArray &data) const override; bool TryMagic(const QByteArray &data) const override;
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_search = true) const override; SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override; void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
static QString FindCueFilename(const QString &filename); static QString FindCueFilename(const QString &filename);

View File

@ -40,7 +40,7 @@ class CollectionBackendInterface;
M3UParser::M3UParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent) M3UParser::M3UParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
: ParserBase(collection_backend, parent) {} : ParserBase(collection_backend, parent) {}
SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const { SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup) const {
Q_UNUSED(playlist_path); Q_UNUSED(playlist_path);
@ -72,7 +72,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
} }
} }
else if (!line.isEmpty()) { else if (!line.isEmpty()) {
Song song = LoadSong(line, 0, 0, dir, collection_search); Song song = LoadSong(line, 0, 0, dir, collection_lookup);
if (!current_metadata.title.isEmpty()) { if (!current_metadata.title.isEmpty()) {
song.set_title(current_metadata.title); song.set_title(current_metadata.title);
} }

View File

@ -52,7 +52,7 @@ class M3UParser : public ParserBase {
bool TryMagic(const QByteArray &data) const override; bool TryMagic(const QByteArray &data) const override;
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_search = true) const override; SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override; void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
private: private:

View File

@ -37,7 +37,7 @@
ParserBase::ParserBase(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent) ParserBase::ParserBase(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
: QObject(parent), collection_backend_(collection_backend) {} : QObject(parent), collection_backend_(collection_backend) {}
void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, Song *song, const bool collection_search) const { void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, Song *song, const bool collection_lookup) const {
if (filename_or_url.isEmpty()) { if (filename_or_url.isEmpty()) {
return; return;
@ -74,7 +74,7 @@ void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning
const QUrl url = QUrl::fromLocalFile(filename); const QUrl url = QUrl::fromLocalFile(filename);
// Search the collection // Search the collection
if (collection_backend_ && collection_search) { if (collection_backend_ && collection_lookup) {
Song collection_song; Song collection_song;
if (track > 0) { if (track > 0) {
collection_song = collection_backend_->GetSongByUrlAndTrack(url, track); collection_song = collection_backend_->GetSongByUrlAndTrack(url, track);
@ -106,10 +106,10 @@ void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning
} }
Song ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, const bool collection_search) const { Song ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, const bool collection_lookup) const {
Song song(Song::Source::LocalFile); Song song(Song::Source::LocalFile);
LoadSong(filename_or_url, beginning, track, dir, &song, collection_search); LoadSong(filename_or_url, beginning, track, dir, &song, collection_lookup);
return song; return song;

View File

@ -68,8 +68,8 @@ class ParserBase : public QObject {
// Loads a song. If filename_or_url is a URL (with a scheme other than "file") then it is set on the song and the song marked as a stream. // Loads a song. If filename_or_url is a URL (with a scheme other than "file") then it is set on the song and the song marked as a stream.
// Also sets the song's metadata by searching in the Collection, or loading from the file as a fallback. // 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. // This function should always be used when loading a playlist.
Song LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, const bool collection_search) const; Song LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, const bool collection_lookup) const;
void LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, Song *song, const bool collection_search) const; void LoadSong(const QString &filename_or_url, const qint64 beginning, const int track, const QDir &dir, Song *song, const bool collection_lookup) const;
// If the URL is a file:// URL then returns its path, absolute or relative to the directory depending on the path_type option. // 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. // Otherwise, returns the URL as is. This function should always be used when saving a playlist.

View File

@ -45,7 +45,7 @@ constexpr auto qt_endl = endl;
PLSParser::PLSParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent) PLSParser::PLSParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
: ParserBase(collection_backend, parent) {} : ParserBase(collection_backend, parent) {}
SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const { SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup) const {
Q_UNUSED(playlist_path); Q_UNUSED(playlist_path);
@ -62,7 +62,7 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
int n = re_match.captured(0).toInt(); int n = re_match.captured(0).toInt();
if (key.startsWith(QLatin1String("file"))) { if (key.startsWith(QLatin1String("file"))) {
Song song = LoadSong(value, 0, 0, dir, collection_search); Song song = LoadSong(value, 0, 0, dir, collection_lookup);
// Use the title and length we've already loaded if any // Use the title and length we've already loaded if any
if (!songs[n].title().isEmpty()) song.set_title(songs[n].title()); if (!songs[n].title().isEmpty()) song.set_title(songs[n].title());

View File

@ -51,7 +51,7 @@ class PLSParser : public ParserBase {
bool TryMagic(const QByteArray &data) const override; bool TryMagic(const QByteArray &data) const override;
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_search = true) const override; SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override; void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
}; };

View File

@ -44,7 +44,7 @@ bool WplParser::TryMagic(const QByteArray &data) const {
return data.contains("<?wpl") || data.contains("<smil>"); return data.contains("<?wpl") || data.contains("<smil>");
} }
SongList WplParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const { SongList WplParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup) const {
Q_UNUSED(playlist_path); Q_UNUSED(playlist_path);
@ -56,13 +56,13 @@ SongList WplParser::Load(QIODevice *device, const QString &playlist_path, const
} }
while (!reader.atEnd() && Utilities::ParseUntilElement(&reader, QStringLiteral("seq"))) { while (!reader.atEnd() && Utilities::ParseUntilElement(&reader, QStringLiteral("seq"))) {
ParseSeq(dir, &reader, &ret, collection_search); ParseSeq(dir, &reader, &ret, collection_lookup);
} }
return ret; return ret;
} }
void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs, const bool collection_search) const { void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs, const bool collection_lookup) const {
while (!reader->atEnd()) { while (!reader->atEnd()) {
QXmlStreamReader::TokenType type = reader->readNext(); QXmlStreamReader::TokenType type = reader->readNext();
@ -72,7 +72,7 @@ void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *so
if (name == QLatin1String("media")) { if (name == QLatin1String("media")) {
QString src = reader->attributes().value(QLatin1String("src")).toString(); QString src = reader->attributes().value(QLatin1String("src")).toString();
if (!src.isEmpty()) { if (!src.isEmpty()) {
Song song = LoadSong(src, 0, 0, dir, collection_search); Song song = LoadSong(src, 0, 0, dir, collection_lookup);
if (song.is_valid()) { if (song.is_valid()) {
songs->append(song); songs->append(song);
} }

View File

@ -54,11 +54,11 @@ class WplParser : public XMLParser {
bool TryMagic(const QByteArray &data) const override; bool TryMagic(const QByteArray &data) const override;
SongList Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search = true) const override; SongList Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup = true) const override;
void Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override; void Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
private: private:
void ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs, const bool collection_search = true) const; void ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs, const bool collection_lookup) const;
static void WriteMeta(const QString &name, const QString &content, QXmlStreamWriter *writer); static void WriteMeta(const QString &name, const QString &content, QXmlStreamWriter *writer);
}; };

View File

@ -42,28 +42,29 @@ class CollectionBackendInterface;
XSPFParser::XSPFParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent) XSPFParser::XSPFParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
: XMLParser(collection_backend, parent) {} : XMLParser(collection_backend, parent) {}
SongList XSPFParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search) const { SongList XSPFParser::Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_lookup) const {
Q_UNUSED(playlist_path); Q_UNUSED(playlist_path);
SongList ret; SongList songs;
QXmlStreamReader reader(device); QXmlStreamReader reader(device);
if (!Utilities::ParseUntilElement(&reader, QStringLiteral("playlist")) || !Utilities::ParseUntilElement(&reader, QStringLiteral("trackList"))) { if (!Utilities::ParseUntilElement(&reader, QStringLiteral("playlist")) || !Utilities::ParseUntilElement(&reader, QStringLiteral("trackList"))) {
return ret; return songs;
} }
while (!reader.atEnd() && Utilities::ParseUntilElement(&reader, QStringLiteral("track"))) { while (!reader.atEnd() && Utilities::ParseUntilElement(&reader, QStringLiteral("track"))) {
Song song = ParseTrack(&reader, dir, collection_search); const Song song = ParseTrack(&reader, dir, collection_lookup);
if (song.is_valid()) { if (song.is_valid()) {
ret << song; songs << song;
} }
} }
return ret;
return songs;
} }
Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const { Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_lookup) const {
QString title, artist, album, location, art; QString title, artist, album, location, art;
qint64 nanosec = -1; qint64 nanosec = -1;
@ -121,7 +122,7 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const boo
} }
return_song: return_song:
Song song = LoadSong(location, 0, track_num, dir, collection_search); Song song = LoadSong(location, 0, track_num, dir, collection_lookup);
// Override metadata with what was in the playlist // Override metadata with what was in the playlist
if (song.source() != Song::Source::Collection) { if (song.source() != Song::Source::Collection) {

View File

@ -51,11 +51,11 @@ class XSPFParser : public XMLParser {
bool TryMagic(const QByteArray &data) const override; bool TryMagic(const QByteArray &data) const override;
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_search = true) const override; SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override; void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
private: private:
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const; Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_lookup) const;
}; };
#endif #endif