Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MythMusic: handle streams that repeat same metadata in changing strings #791

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions mythplugins/mythmusic/mythmusic/avfdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ ShoutCastMetaMap ShoutCastMetaParser::parseMeta(const QString &mdata)
auto match = rx.match(title);
if (match.hasMatch())
{
LOG(VB_PLAYBACK, LOG_INFO, QString("ShoutCast: Meta : '%1'")
LOG(VB_PLAYBACK, LOG_DEBUG, QString("ShoutCast: Meta : '%1'")
.arg(mdata));
LOG(VB_PLAYBACK, LOG_INFO,
QString("ShoutCast: Parsed as: '%1' by '%2'")
.arg(match.captured(m_metaTitlePos),
match.captured(m_metaArtistPos)));
LOG(VB_PLAYBACK, LOG_DEBUG,
QString("ShoutCast: Parsed as: '%1' by '%2' on '%3'")
.arg(m_metaTitlePos ? match.captured(m_metaTitlePos) : "",
m_metaArtistPos ? match.captured(m_metaArtistPos) : "",
m_metaAlbumPos ? match.captured(m_metaAlbumPos) : ""));

if (m_metaTitlePos > 0)
result["title"] = match.captured(m_metaTitlePos);
Expand Down Expand Up @@ -553,27 +554,32 @@ void avfDecoder::checkMetatdata(void)

if (av_opt_get(m_inputContext->getContext(), "icy_metadata_packet", AV_OPT_SEARCH_CHILDREN, &pdata) >= 0)
{
QString s = QString::fromUtf8((const char*) pdata);
QString shout = QString::fromUtf8((const char*) pdata);

if (m_lastMetadata != s)
if (m_lastMetadata != shout)
{
m_lastMetadata = s;

LOG(VB_PLAYBACK, LOG_INFO, QString("avfDecoder: shoutcast metadata changed - %1").arg(m_lastMetadata));

m_lastMetadata = shout;
ShoutCastMetaParser parser;
parser.setMetaFormat(gPlayer->getDecoderHandler()->getMetadata().MetadataFormat());
ShoutCastMetaMap meta_map = parser.parseMeta(shout);

ShoutCastMetaMap meta_map = parser.parseMeta(m_lastMetadata);
QString parsed = meta_map["title"] + "\\" + meta_map["artist"] + "\\" + meta_map["album"];
if (m_lastMetadataParsed != parsed)
{
m_lastMetadataParsed = parsed;

MusicMetadata mdata = gPlayer->getDecoderHandler()->getMetadata();
mdata.setTitle(meta_map["title"]);
mdata.setArtist(meta_map["artist"]);
mdata.setAlbum(meta_map["album"]);
mdata.setLength(-1ms);
LOG(VB_PLAYBACK, LOG_INFO, QString("avfDecoder: shoutcast metadata changed - %1").arg(shout));
twitham1 marked this conversation as resolved.
Show resolved Hide resolved
LOG(VB_PLAYBACK, LOG_INFO, QString("avfDecoder: new metadata (%1)").arg(parsed));

DecoderHandlerEvent ev(DecoderHandlerEvent::kMeta, mdata);
dispatch(ev);
MusicMetadata mdata = gPlayer->getDecoderHandler()->getMetadata();
mdata.setTitle(meta_map["title"]);
mdata.setArtist(meta_map["artist"]);
mdata.setAlbum(meta_map["album"]);
mdata.setLength(-1ms);

DecoderHandlerEvent ev(DecoderHandlerEvent::kMeta, mdata);
dispatch(ev);
}
}

av_free(pdata);
Expand Down
1 change: 1 addition & 0 deletions mythplugins/mythmusic/mythmusic/avfdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class avfDecoder : public QObject, public Decoder

QTimer *m_mdataTimer {nullptr};
QString m_lastMetadata;
QString m_lastMetadataParsed;

int m_errCode {0};
};
Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythmusic/mythmusic/musicplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ void MusicPlayer::customEvent(QEvent *event)
// update the current tracks time in the last played list
if (m_playMode == PLAYMODE_RADIO)
{
if (!m_playedList.isEmpty())
if (!m_playedList.isEmpty() && m_currentTime > 0s)
{
m_playedList.last()->setLength(m_currentTime);
// this will update any track lengths displayed on screen
Expand Down