1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Merge git://github.com/szemek/clementine

This commit is contained in:
Arnaud Bienner 2012-11-22 00:37:51 +01:00
commit cf22a91c6a
3 changed files with 29 additions and 5 deletions

View File

@ -1114,6 +1114,12 @@ bool Song::IsMetadataEqual(const Song& other) const {
d->cue_path_ == other.d->cue_path_;
}
bool Song::IsDuplicate(const Song& other) const {
return url() == other.url() ||
(title().toLower() == other.title().toLower() &&
artist().toLower() == other.artist().toLower());
}
bool Song::IsEditable() const {
return d->valid_ && !d->url_.isEmpty() && !is_stream() &&
d->filetype_ != Type_Unknown && !has_cue();

View File

@ -262,6 +262,7 @@ class Song {
// Comparison functions
bool IsMetadataEqual(const Song& other) const;
bool IsOnSameAlbum(const Song& other) const;
bool IsDuplicate(const Song& other) const;
bool operator==(const Song& other) const;

View File

@ -1921,17 +1921,34 @@ void Playlist::RemoveDeletedSongs() {
void Playlist::RemoveDuplicateSongs() {
QList<int> rows_to_remove;
QSet<QUrl> filenames;
QHash<Song, int> unique_songs;
for (int row = 0; row < items_.count(); ++row) {
PlaylistItemPtr item = items_[row];
Song song = item->Metadata();
if (filenames.contains(song.url())) {
rows_to_remove.append(row);
} else {
filenames.insert(song.url());
bool found_duplicate = false;
QHashIterator<Song, int> iterator(unique_songs);
while (iterator.hasNext() && !found_duplicate) {
iterator.next();
Song uniq_song = iterator.key();
if (song.IsDuplicate(uniq_song)) {
if (song.bitrate() > uniq_song.bitrate()) {
rows_to_remove.append(unique_songs[uniq_song]);
unique_songs.remove(uniq_song);
unique_songs.insert(song, row);
}
else {
rows_to_remove.append(row);
}
found_duplicate = true;
}
}
if (!found_duplicate)
unique_songs.insert(song, row);
}
removeRows(rows_to_remove);