From 5e6558a2d5495d57c898ea4efe2557c48af0b1ab Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Tue, 15 Mar 2022 22:42:07 -0600 Subject: [PATCH] Playlist Parsers: Avoid overriding song metadata if it's already in the library. --- src/playlistparsers/asxparser.cpp | 12 ++++++++---- src/playlistparsers/cueparser.cpp | 31 +++++++++++++++++++++++------- src/playlistparsers/m3uparser.cpp | 21 ++++++++++++-------- src/playlistparsers/plsparser.cpp | 11 +++++++---- src/playlistparsers/xspfparser.cpp | 18 ++++++++++------- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/playlistparsers/asxparser.cpp b/src/playlistparsers/asxparser.cpp index 9e65a2c0e1..c63ca21ef6 100644 --- a/src/playlistparsers/asxparser.cpp +++ b/src/playlistparsers/asxparser.cpp @@ -108,10 +108,14 @@ Song ASXParser::ParseTrack(QXmlStreamReader* reader, const QDir& dir) const { return_song: Song song = LoadSong(ref, 0, dir); - // Override metadata with what was in the playlist - song.set_title(title); - song.set_artist(artist); - song.set_album(album); + // Override metadata with what was in the playlist if the song is not in the + // library. + if (!song.is_library_song()) { + song.set_title(title); + song.set_artist(artist); + song.set_album(album); + } + return song; } diff --git a/src/playlistparsers/cueparser.cpp b/src/playlistparsers/cueparser.cpp index dbca6d851f..f15de74ae2 100644 --- a/src/playlistparsers/cueparser.cpp +++ b/src/playlistparsers/cueparser.cpp @@ -227,23 +227,40 @@ SongList CueParser::Load(QIODevice* device, const QString& playlist_path, // finalize parsing songs for (int i = 0; i < entries.length(); i++) { CueEntry entry = entries.at(i); + Song song; - Song song = LoadSong(entry.file, IndexToMarker(entry.index), dir); + // set song beginning, track number and cue path only in single-file mode + if (files == 1) { + song = LoadSong(entry.file, IndexToMarker(entry.index), dir); + song.set_cue_path(playlist_path); + song.set_track(i + 1); + } else { + song = LoadSong(entry.file, 0, dir); + + if (!song.is_library_song()) { + song.set_title(entry.title); + song.set_artist(entry.PrettyArtist()); + song.set_album(entry.album); + song.set_albumartist(entry.album_artist); + song.set_genre(entry.genre); + song.set_year(entry.date.toInt()); + song.set_composer(entry.PrettyComposer()); + song.set_disc(entry.disc.toInt()); + } + + ret << song; + + continue; + } // cue song has mtime equal to qMax(media_file_mtime, cue_sheet_mtime) if (cue_mtime.isValid()) { song.set_mtime(qMax(cue_mtime.toTime_t(), song.mtime())); } - song.set_cue_path(playlist_path); // overwrite the stuff, we may have read from the file or library, using // the current .cue metadata - // set track number only in single-file mode - if (files == 1) { - song.set_track(i + 1); - } - // the last TRACK for every FILE gets it's 'end' marker from the media // file's // length diff --git a/src/playlistparsers/m3uparser.cpp b/src/playlistparsers/m3uparser.cpp index 20ef07250a..ffd3b549de 100644 --- a/src/playlistparsers/m3uparser.cpp +++ b/src/playlistparsers/m3uparser.cpp @@ -59,15 +59,20 @@ SongList M3UParser::Load(QIODevice* device, const QString& playlist_path, } } else if (!line.isEmpty()) { Song song = LoadSong(line, 0, dir); - if (!current_metadata.title.isEmpty()) { - song.set_title(current_metadata.title); - } - if (!current_metadata.artist.isEmpty()) { - song.set_artist(current_metadata.artist); - } - if (current_metadata.length > 0) { - song.set_length_nanosec(current_metadata.length); + + // Override metadata from playlist if the song is not in the library. + if (!song.is_library_song()) { + if (!current_metadata.title.isEmpty()) { + song.set_title(current_metadata.title); + } + if (!current_metadata.artist.isEmpty()) { + song.set_artist(current_metadata.artist); + } + if (current_metadata.length > 0) { + song.set_length_nanosec(current_metadata.length); + } } + ret << song; current_metadata = Metadata(); diff --git a/src/playlistparsers/plsparser.cpp b/src/playlistparsers/plsparser.cpp index e7a3bdd1f9..38d3fb23c4 100644 --- a/src/playlistparsers/plsparser.cpp +++ b/src/playlistparsers/plsparser.cpp @@ -43,10 +43,13 @@ SongList PLSParser::Load(QIODevice* device, const QString& playlist_path, if (key.startsWith("file")) { Song song = LoadSong(value, 0, dir); - // 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].length_nanosec() != -1) - song.set_length_nanosec(songs[n].length_nanosec()); + // Use the title and length we've already loaded if any and only if the + // song is not in the library. + if (!song.is_library_song()) { + if (!songs[n].title().isEmpty()) song.set_title(songs[n].title()); + if (songs[n].length_nanosec() != -1) + song.set_length_nanosec(songs[n].length_nanosec()); + } songs[n] = song; } else if (key.startsWith("title")) { diff --git a/src/playlistparsers/xspfparser.cpp b/src/playlistparsers/xspfparser.cpp index d30e0962e8..20e6d418b8 100644 --- a/src/playlistparsers/xspfparser.cpp +++ b/src/playlistparsers/xspfparser.cpp @@ -99,13 +99,17 @@ Song XSPFParser::ParseTrack(QXmlStreamReader* reader, const QDir& dir) const { return_song: Song song = LoadSong(location, 0, dir); - // Override metadata with what was in the playlist - song.set_title(title); - song.set_artist(artist); - song.set_album(album); - song.set_art_manual(art); - song.set_length_nanosec(nanosec); - song.set_track(track_num); + // If the song is not in the library, fill metadata with what was in the + // playlist. + if (!song.is_library_song()) { + song.set_title(title); + song.set_artist(artist); + song.set_album(album); + song.set_art_manual(art); + song.set_length_nanosec(nanosec); + song.set_track(track_num); + } + return song; }