From 82a6798c83230f20e2007f03ef0f704eaef8ad62 Mon Sep 17 00:00:00 2001 From: Craig Drummond Date: Tue, 17 Nov 2020 12:06:04 +0000 Subject: [PATCH] - Better handling of CUE tracks when MPD is set to list as directory. - Disable CUE parsing in cantata by default, as MPD handles this better now. Issues #1650 and #1652 --- ChangeLog | 2 ++ db/librarydb.cpp | 11 +++++++++++ gui/settings.cpp | 2 +- mpd-interface/song.cpp | 11 +++++++++++ mpd-interface/song.h | 1 + 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2b2ab8958..fec251b70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ ccoors. 3. Fix Community Radio Browser search. 4. Remove dirble from radio section, as its no longer active. +5. Better handling of CUE tracks when MPD is set to list as directory. +6. Disable CUE parsing in cantata by default, as MPD handles this better now. 2.4.2 ----- diff --git a/db/librarydb.cpp b/db/librarydb.cpp index 83130ec33..73f1af4de 100644 --- a/db/librarydb.cpp +++ b/db/librarydb.cpp @@ -1226,9 +1226,20 @@ void LibraryDb::insertSongs(QList *songs) return; } + QSet mpdCueTrackDirs; for (const Song &s: *songs) { + if (s.isMpdCueTrack()) { + mpdCueTrackDirs.insert(Utils::getDir(s.filePath())); + } insertSong(s); } + + if (!mpdCueTrackDirs.isEmpty()) { + DBUG << "Remove non-MPD cue tracks"; + for (const QString &d: mpdCueTrackDirs) { + QSqlQuery(*db).exec("delete from songs where file like '" + d + "%%' and not file like '" + d + "%%/%%'"); + } + } delete songs; } diff --git a/gui/settings.cpp b/gui/settings.cpp index 74e81ef0f..eb85d3dfa 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -324,7 +324,7 @@ QSet Settings::singleTracksFolders() MPDParseUtils::CueSupport Settings::cueSupport() { - return MPDParseUtils::toCueSupport(cfg.get("cueSupport", MPDParseUtils::toStr(MPDParseUtils::Cue_Parse))); + return MPDParseUtils::toCueSupport(cfg.get("cueSupport", MPDParseUtils::toStr(MPDParseUtils::Cue_Ignore))); } QStringList Settings::lyricProviders() diff --git a/mpd-interface/song.cpp b/mpd-interface/song.cpp index 6d2bc9775..8e84ffe63 100644 --- a/mpd-interface/song.cpp +++ b/mpd-interface/song.cpp @@ -42,6 +42,7 @@ #include //static const quint8 constOnlineDiscId=0xEE; +static const QString constMpdQueue=QLatin1String(".cue/track"); // .cue.track0123 const QString Song::constCddaProtocol=QLatin1String("/[cantata-cdda]/"); const QString Song::constMopidyLocal=QLatin1String("local:track:"); @@ -816,6 +817,11 @@ QString Song::filePath(const QString &base) const return file; } QString fileName=decodePath(file, isCdda()); + int mpdCueIdx = fileName.indexOf(constMpdQueue); + if (mpdCueIdx == fileName.length()-(constMpdQueue.length()+4)) + { + fileName=fileName.mid(0, mpdCueIdx+4); + } if (!base.isEmpty() && !fileName.isEmpty() && !isNonMPD()) { bool haveAbsPath=fileName.startsWith("/") || fileName.contains(":/"); if (!haveAbsPath) { @@ -825,6 +831,11 @@ QString Song::filePath(const QString &base) const return fileName; } +bool Song::isMpdCueTrack() const +{ + return file.indexOf(constMpdQueue)==file.length()-(constMpdQueue.length()+4); +} + QString Song::describe() const { #if !defined CANTATA_NO_UI_FUNCTIONS diff --git a/mpd-interface/song.h b/mpd-interface/song.h index ab96abbfa..ce0f5f8d7 100644 --- a/mpd-interface/song.h +++ b/mpd-interface/song.h @@ -225,6 +225,7 @@ struct Song QString albumKey() const; bool isCueFile() const { return Playlist==type && file.endsWith(QLatin1String(".cue"), Qt::CaseInsensitive); } bool isFromCue() const { return CueFile::isCue(file); } + bool isMpdCueTrack() const; QString basicArtist(bool orComposer=false) const; QString basicTitle() const; QString filePath(const QString &base=QString()) const;