diff --git a/src/core/songloader.cpp b/src/core/songloader.cpp index b8b47d057..1e6a822f7 100644 --- a/src/core/songloader.cpp +++ b/src/core/songloader.cpp @@ -183,7 +183,15 @@ void SongLoader::LoadPlaylistAndEmit(ParserBase* parser, const QString& filename void SongLoader::LoadPlaylist(ParserBase* parser, const QString& filename) { QFile file(filename); file.open(QIODevice::ReadOnly); - songs_ = parser->Load(&file, filename, QFileInfo(filename).path()); + + SongList all_songs = parser->Load(&file, filename, QFileInfo(filename).path()); + songs_.clear(); + + foreach(const Song& song, all_songs) { + if(song.is_valid()) { + songs_ << song; + } + } } static bool CompareSongs(const Song& left, const Song& right) { diff --git a/src/library/librarywatcher.cpp b/src/library/librarywatcher.cpp index 15b5fae0b..931b5cd8d 100644 --- a/src/library/librarywatcher.cpp +++ b/src/library/librarywatcher.cpp @@ -399,9 +399,7 @@ void LibraryWatcher::UpdateCueAssociatedSongs(const QString& file, const QString QHash sections_map; foreach(const Song& song, old_sections) { - if(song.is_valid()) { - sections_map[song.beginning()] = song; - } + sections_map[song.beginning()] = song; } QSet used_ids; @@ -438,7 +436,7 @@ void LibraryWatcher::UpdateNonCueAssociatedSong(const QString& file, const Song& // from the library if(cue_deleted) { foreach(const Song& song, backend_->GetSongsByFilename(file)) { - if(!song.IsMetadataEqual(matching_song) && song.is_valid()) { + if(!song.IsMetadataEqual(matching_song)) { t->deleted_songs << song; } } diff --git a/src/playlistparsers/cueparser.cpp b/src/playlistparsers/cueparser.cpp index 54fbb0256..3849f66b3 100644 --- a/src/playlistparsers/cueparser.cpp +++ b/src/playlistparsers/cueparser.cpp @@ -274,6 +274,7 @@ bool CueParser::UpdateSong(const CueEntry& entry, const QString& next_index, Son return false; } + // believe the CUE: Init() forces validity song->Init(entry.title, entry.PrettyArtist(), entry.album, beginning, end); song->set_albumartist(entry.album_artist); @@ -292,6 +293,9 @@ bool CueParser::UpdateLastSong(const CueEntry& entry, Song* song) const { return false; } + // believe the CUE and force validity (like UpdateSong() does) + song->set_valid(true); + song->set_title(entry.title); song->set_artist(entry.PrettyArtist()); song->set_album(entry.album); diff --git a/src/playlistparsers/plsparser.cpp b/src/playlistparsers/plsparser.cpp index 6d80d0441..15c56436e 100644 --- a/src/playlistparsers/plsparser.cpp +++ b/src/playlistparsers/plsparser.cpp @@ -49,6 +49,8 @@ SongList PLSParser::Load(QIODevice *device, const QString& playlist_path, const } else { songs[n].InitFromFile(songs[n].filename(), -1); } + // force validity + songs[n].set_valid(true); } else if (key.startsWith("title")) { songs[n].set_title(value); } else if (key.startsWith("length")) { diff --git a/tests/cueparser_test.cpp b/tests/cueparser_test.cpp index 2b4e1d4ad..874e97b75 100644 --- a/tests/cueparser_test.cpp +++ b/tests/cueparser_test.cpp @@ -33,6 +33,17 @@ class CueParserTest : public ::testing::Test { : parser_(NULL) { } + // We believe CUE - all songs with proper CUE entries should be valid. + bool validate_songs(SongList songs) { + foreach(const Song& song, songs) { + if(!song.is_valid()) { + return false; + } + } + + return true; + } + CueParser parser_; MockFileRefFactory taglib_; }; @@ -55,6 +66,8 @@ TEST_F(CueParserTest, ParsesASong) { ASSERT_EQ(1, first_song.beginning()); ASSERT_EQ(1, first_song.track()); ASSERT_EQ("CUEPATH", first_song.cue_path()); + + validate_songs(song_list); } TEST_F(CueParserTest, ParsesTwoSongs) { @@ -84,6 +97,8 @@ TEST_F(CueParserTest, ParsesTwoSongs) { ASSERT_EQ("Zucchero himself", second_song.albumartist()); ASSERT_EQ(5 * 60 + 3, second_song.beginning()); ASSERT_EQ(2, second_song.track()); + + validate_songs(song_list); } TEST_F(CueParserTest, SkipsBrokenSongs) { @@ -115,6 +130,8 @@ TEST_F(CueParserTest, SkipsBrokenSongs) { ASSERT_EQ("Zucchero himself", second_song.albumartist()); ASSERT_EQ(5 * 60, second_song.beginning()); ASSERT_EQ(2, second_song.track()); + + validate_songs(song_list); } TEST_F(CueParserTest, UsesAllMetadataInformation) { @@ -148,6 +165,8 @@ TEST_F(CueParserTest, UsesAllMetadataInformation) { ASSERT_EQ("Some other guy", second_song.composer()); ASSERT_EQ(2, second_song.beginning()); ASSERT_EQ(2, second_song.track()); + + validate_songs(song_list); } TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) { @@ -210,6 +229,8 @@ TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) { ASSERT_EQ(1, fifth_song.beginning()); ASSERT_EQ(-1, fifth_song.track()); ASSERT_EQ("CUEPATH", fifth_song.cue_path()); + + validate_songs(song_list); } TEST_F(CueParserTest, SkipsBrokenSongsInMultipleFileBasedCues) { @@ -260,6 +281,8 @@ TEST_F(CueParserTest, SkipsBrokenSongsInMultipleFileBasedCues) { ASSERT_EQ("D2", fourth_song.title()); ASSERT_EQ(61, fourth_song.beginning()); ASSERT_EQ(-1, fourth_song.track()); + + validate_songs(song_list); } TEST_F(CueParserTest, SkipsDataFiles) { @@ -288,4 +311,6 @@ TEST_F(CueParserTest, SkipsDataFiles) { ASSERT_EQ("D1", second_song.title()); ASSERT_EQ(61, second_song.beginning()); ASSERT_EQ(-1, second_song.track()); + + validate_songs(song_list); }