when loading playlist, take only it's valid songs (+ force validity of CUE and PLS related songs)

This commit is contained in:
Paweł Bara 2011-02-03 17:47:32 +00:00
parent 74a878be41
commit 7bdac8fba6
5 changed files with 42 additions and 5 deletions

View File

@ -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) {

View File

@ -399,9 +399,7 @@ void LibraryWatcher::UpdateCueAssociatedSongs(const QString& file, const QString
QHash<int, Song> sections_map;
foreach(const Song& song, old_sections) {
if(song.is_valid()) {
sections_map[song.beginning()] = song;
}
sections_map[song.beginning()] = song;
}
QSet<int> 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;
}
}

View File

@ -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);

View File

@ -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")) {

View File

@ -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);
}