Skip to content

Commit

Permalink
Properly handle disc changes
Browse files Browse the repository at this point in the history
Always query metadata when disc change was detected.
Also reset last queried metadata before querying data
or in case of an error.
  • Loading branch information
hambre committed Jan 3, 2024
1 parent 6abb8ac commit e49e65f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mythplugins/mythmusic/mythmusic/cddecoder.cpp
Expand Up @@ -661,7 +661,7 @@ MusicMetadata *CdDecoder::getMetadata()
#endif // CDTEXT
{
#ifdef HAVE_MUSICBRAINZ
if (isDiscChanged && !getMusicBrainz().hasMetadata(m_setTrackNum))
if (isDiscChanged)
{
// lazy load whole CD metadata
getMusicBrainz().queryForDevice(m_deviceName);
Expand Down
17 changes: 16 additions & 1 deletion mythplugins/mythmusic/mythmusic/musicbrainz.cpp
Expand Up @@ -307,6 +307,7 @@ bool MusicBrainz::queryForDevice(const QString &deviceName)
const auto discId = queryDiscId(deviceName.toStdString());
if (discId.empty())
{
reset();
return false;
}
if (discId == m_discId)
Expand All @@ -315,6 +316,10 @@ bool MusicBrainz::queryForDevice(const QString &deviceName)
LOG(VB_MEDIA, LOG_DEBUG, QString("musicbrainz: Metadata for disc %1 already present").arg(QString::fromStdString(m_discId)));
return true;
}

// new disc id, reset existing data
reset();

const auto releaseId = queryRelease(discId);
if (releaseId.empty())
{
Expand Down Expand Up @@ -348,7 +353,17 @@ MusicMetadata *MusicBrainz::getMetadata(int track) const
return nullptr;
}
auto *metadata = new MusicMetadata(it.value());
metadata->getAlbumArtImages()->addImage(&m_albumArt);
if (!m_albumArt.m_filename.isEmpty())
{
metadata->getAlbumArtImages()->addImage(&m_albumArt);
}
return metadata;
}

void MusicBrainz::reset()
{
LOG(VB_MEDIA, LOG_DEBUG, "musicbrainz: Reset metadata");
m_tracks.clear();
m_albumArt = AlbumArtImage();
}

4 changes: 4 additions & 0 deletions mythplugins/mythmusic/mythmusic/musicbrainz.h
Expand Up @@ -37,6 +37,10 @@ class MusicBrainz
*/
MusicMetadata *getMetadata(int track) const;

/**
* Reset last queried metadata
*/
void reset();
private:

#ifdef HAVE_MUSICBRAINZ
Expand Down

0 comments on commit e49e65f

Please sign in to comment.