Simply some song checks and make url always unique by using stream url

instead
This commit is contained in:
Jonas Kvinge 2019-07-31 22:26:51 +02:00
parent 588a0b3c41
commit 99569081c9
6 changed files with 29 additions and 36 deletions

View File

@ -189,18 +189,7 @@ void ContextView::UpdateNoSong() {
void ContextView::SongChanged(const Song &song) {
if (song_playing_.is_valid() && song.id() == song_playing_.id() && song.source() == song_playing_.source() &&
(
song.url() == song_playing_.url()
||
(
song.albumartist() == song_playing_.albumartist() &&
song.artist() == song_playing_.artist() &&
song.album() == song_playing_.album() &&
song.title() == song_playing_.title()
)
)
) {
if (song_playing_.is_valid() && song == song_playing_) {
UpdateSong(song);
}
else {
@ -606,9 +595,7 @@ void ContextView::ScaleCover() {
void ContextView::AlbumCoverLoaded(const Song &song, const QUrl &cover_url, const QImage &image) {
if (song.id() != song_playing_.id() || song.url() != song_playing_.url()) return;
if (song.effective_albumartist() != song_playing_.effective_albumartist() || song.effective_album() != song_playing_.effective_album() || song.title() != song_playing_.title()) return;
if (image == image_original_) return;
if (song != song_playing_ || image == image_original_) return;
active_ = true;
downloading_covers_ = false;

View File

@ -306,7 +306,7 @@ void Player::HandleLoadResult(const UrlHandler::LoadResult &result) {
(result.media_url_ != song.url())
)
{
song.set_url(result.media_url_);
song.set_stream_url(result.media_url_);
update = true;
}

View File

@ -207,21 +207,22 @@ struct Song::Private : public QSharedData {
int skipcount_;
int lastplayed_;
bool compilation_detected_; // From the collection scanner
bool compilation_on_; // Set by the user
bool compilation_off_; // Set by the user
bool compilation_detected_; // From the collection scanner
bool compilation_on_; // Set by the user
bool compilation_off_; // Set by the user
// Filenames to album art for this song.
QUrl art_automatic_; // Guessed by CollectionWatcher
QUrl art_manual_; // Set by the user - should take priority
QUrl art_automatic_; // Guessed by CollectionWatcher
QUrl art_manual_; // Set by the user - should take priority
QString cue_path_; // If the song has a CUE, this contains it's path.
QString cue_path_; // If the song has a CUE, this contains it's path.
QImage image_;
bool init_from_file_; // Whether this song was loaded from a file using taglib.
bool suspicious_tags_; // Whether our encoding guesser thinks these tags might be incorrectly encoded.
QUrl stream_url_; // Temporary stream url set by url handler.
QImage image_; // Album Cover image set by album cover loader.
bool init_from_file_; // Whether this song was loaded from a file using taglib.
bool suspicious_tags_; // Whether our encoding guesser thinks these tags might be incorrectly encoded.
QString error_;
QString error_; // Song load error set by song loader.
};
@ -336,12 +337,15 @@ bool Song::has_manually_unset_cover() const { return d->art_manual_.path() == kM
void Song::manually_unset_cover() { d->art_manual_ = QUrl::fromLocalFile(kManuallyUnsetCover); }
bool Song::has_embedded_cover() const { return d->art_automatic_.path() == kEmbeddedCover; }
void Song::set_embedded_cover() { d->art_automatic_ = QUrl::fromLocalFile(kEmbeddedCover); }
const QUrl &Song::stream_url() const { return d->stream_url_; }
const QUrl &Song::effective_stream_url() const { return d->stream_url_.isEmpty() ? d->url_ : d->stream_url_; }
const QImage &Song::image() const { return d->image_; }
const QString &Song::cue_path() const { return d->cue_path_; }
bool Song::has_cue() const { return !d->cue_path_.isEmpty(); }
bool Song::is_collection_song() const { return !is_cdda() && !is_stream() && id() != -1; }
bool Song::is_collection_song() const { return d->source_ == Source_Collection; }
bool Song::is_metadata_good() const { return !d->title_.isEmpty() && !d->album_.isEmpty() && !d->artist_.isEmpty() && !d->url_.isEmpty() && d->end_ > 0; }
bool Song::is_stream() const { return d->source_ == Source_Stream || d->source_ == Source_Tidal || d->source_ == Source_Subsonic || d->source_ == Source_Qobuz; }
bool Song::is_cdda() const { return d->source_ == Source_CDDA; }
@ -444,6 +448,7 @@ void Song::set_art_automatic(const QUrl &v) { d->art_automatic_ = v; }
void Song::set_art_manual(const QUrl &v) { d->art_manual_ = v; }
void Song::set_cue_path(const QString &v) { d->cue_path_ = v; }
void Song::set_stream_url(const QUrl &v) { d->stream_url_ = v; }
void Song::set_image(const QImage &i) { d->image_ = i; }
QString Song::JoinSpec(const QString &table) {
@ -1354,11 +1359,11 @@ bool Song::IsEditable() const {
}
bool Song::operator==(const Song &other) const {
return url() == other.url() && beginning_nanosec() == other.beginning_nanosec();
return source() == other.source() && url() == other.url() && beginning_nanosec() == other.beginning_nanosec();
}
bool Song::operator!=(const Song &other) const {
return id() != other.id() || url() != other.url() || beginning_nanosec() != other.beginning_nanosec();
return source() != other.source() || url() != other.url() || beginning_nanosec() != other.beginning_nanosec();
}
uint qHash(const Song &song) {
@ -1398,7 +1403,7 @@ void Song::ToXesam(QVariantMap *map) const {
using mpris::AddMetadataAsList;
using mpris::AsMPRISDateTimeType;
AddMetadata("xesam:url", url().toString(), map);
AddMetadata("xesam:url", effective_stream_url().toString(), map);
AddMetadata("xesam:title", PrettyTitle(), map);
AddMetadataAsList("xesam:artist", artist(), map);
AddMetadata("xesam:album", album(), map);

View File

@ -261,6 +261,8 @@ class Song {
// Sets a flag saying that this song (it's media file) has an embedded cover.
void set_embedded_cover();
const QUrl &stream_url() const;
const QUrl &effective_stream_url() const;
const QImage &image() const;
const QString &error() const;
@ -334,6 +336,7 @@ class Song {
void set_cue_path(const QString &v);
void set_stream_url(const QUrl &v);
void set_image(const QImage &i);
// Comparison functions

View File

@ -307,7 +307,7 @@ QVariant Playlist::data(const QModelIndex &idx, int role) const {
case Column_Bitdepth: return song.bitdepth();
case Column_Bitrate: return song.bitrate();
case Column_Filename: return song.url();
case Column_Filename: return song.effective_stream_url();
case Column_BaseFilename: return song.basefilename();
case Column_Filesize: return song.filesize();
case Column_Filetype: return song.filetype();
@ -1020,10 +1020,9 @@ void Playlist::UpdateItems(const SongList &songs) {
item->Metadata().source() == Song::Source_Unknown ||
item->Metadata().filetype() == Song::FileType_Unknown ||
// Stream may change and may need to be updated too
item->Metadata().source() == Song::Source_Stream ||
item->Metadata().source() == Song::Source_Tidal ||
item->Metadata().is_stream() ||
// And CD tracks as well (tags are loaded in a second step)
item->Metadata().source() == Song::Source_CDDA
item->Metadata().is_cdda()
)
) {
PlaylistItemPtr new_item;

View File

@ -267,8 +267,7 @@ void PlayingWidget::SongChanged(const Song &song) {
void PlayingWidget::AlbumCoverLoaded(const Song &song, const QUrl &cover_url, const QImage &image) {
if (!playing_ || song.id() != song_playing_.id() || song.url() != song_playing_.url() || song.effective_albumartist() != song_playing_.effective_albumartist() || song.effective_album() != song_playing_.effective_album() || song.title() != song_playing_.title()) return;
if (timeline_fade_->state() == QTimeLine::Running && image == image_original_) return;
if (!playing_ || song != song_playing_ || (timeline_fade_->state() == QTimeLine::Running && image == image_original_)) return;
active_ = true;
downloading_covers_ = false;