summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2023-11-30 17:13:15 +0200
committerMavridis Philippe <mavridisf@gmail.com>2024-09-08 01:41:03 +0300
commitada12bc56af54c67952662835c4404bffab087fc (patch)
treec7a0d2a5caf3e33325b2935d52b113906558d3a7
parentdcb2aad5aeb4b9c46966cd4828f40d99bf7fe8fe (diff)
downloadkaffeine-ada12bc56af54c67952662835c4404bffab087fc.tar.gz
kaffeine-ada12bc56af54c67952662835c4404bffab087fc.zip
mpv: add metadata handling
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp2
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp58
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_part.h2
3 files changed, 59 insertions, 3 deletions
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp b/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp
index aa9e50c..6224dbf 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_event.cpp
@@ -41,7 +41,7 @@ MpvEventThread::MpvEventThread(MpvPart *part) {
void MpvEventThread::initPropertyObservers() {
mpv_observe_property(m_part->m_mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
mpv_observe_property(m_part->m_mpv, 0, "duration", MPV_FORMAT_DOUBLE);
- mpv_observe_property(m_part->m_mpv, 0, "media-title", MPV_FORMAT_STRING);
+ mpv_observe_property(m_part->m_mpv, 0, "metadata", MPV_FORMAT_NONE);
// "The advantage over using this instead of calculating it out of other
// properties is that it properly falls back to estimating the playback
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp b/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
index 65148b5..346acba 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
@@ -246,6 +246,7 @@ void MpvPart::updatePlaytime(TQTime time) {
void MpvPart::customEvent(TQCustomEvent *event) {
if (event->type() == MPVPART_EVENT_PROPERTY_CHANGE) {
MpvPropertyChangeEvent *pe = (MpvPropertyChangeEvent *)event;
+
if (pe->property() == "time-pos" && pe->format() == MPV_FORMAT_DOUBLE) {
m_time = pe->toTime();
updatePlaytime(m_time);
@@ -264,6 +265,10 @@ void MpvPart::customEvent(TQCustomEvent *event) {
emit signalNewMeta(m_mrl);
}
}
+
+ else if (pe->property() == "metadata") {
+ updateMetadata();
+ }
}
else if (event->type() == MPVPART_EVENT_EOF) {
@@ -769,9 +774,59 @@ void MpvPart::hideContextMenu() {
}
}
+void MpvPart::updateMetadata() {
+ if (!m_mpv) return;
+
+ kdDebug() << "update metadata" << endl;
+
+ // Errors reading metadata are not fatal, as this is not something that
+ // the user explicitly requests
+ mpv_node result;
+ if (mpv_get_property(m_mpv, "metadata", MPV_FORMAT_NODE, &result) < 0) {
+ kdWarning() << "mpv: error reading metadata" << endl;
+ return;
+ }
+
+ if (result.format != MPV_FORMAT_NODE_MAP) {
+ kdWarning() << "mpv: wrong metadata format" << endl;
+ return;
+ }
+
+ mpv_node_list *map = result.u.list;
+
+ for (int i = 0; i < map->num; ++i) {
+ TQString key(map->keys[i]);
+ TQString value = TQString::fromUtf8(map->values[i].u.string);
+ if (key == "title" || key == "icy-name") {
+ m_mrl.setTitle(value);
+ }
+ else if (key == "artist") {
+ m_mrl.setArtist(value);
+ }
+ else if (key == "album") {
+ m_mrl.setAlbum(value);
+ }
+ else if (key == "track" || key == "icy-title") {
+ m_mrl.setTrack(value);
+ }
+ else if (key == "date") {
+ m_mrl.setYear(value);
+ }
+ else if (key == "genre" || key == "icy-genre") {
+ m_mrl.setGenre(value);
+ }
+ else if (key == "comment" || key == "icy-description") {
+ m_mrl.setComment(value);
+ }
+ kdDebug() << "e " << map->keys[i] << ": " << map->values[i].u.string << endl;
+ }
+
+ mpv_free_node_contents(&result);
+}
+
#define THROW_ERROR(msg, details) \
kdError() << "mpv: " << msg << " (" << details << ")" << endl; \
- KMessageBox::detailedError(nullptr, i18n(msg), details); \
+ KMessageBox::detailedError(nullptr, i18n(msg), details);
#define THROW_ERROR_FREE(msg, details) \
THROW_ERROR(msg, details) \
@@ -852,7 +907,6 @@ data = result.u.list->values[4].u.ba;
}
}
-
// Try to launch ksnapshot
TQString ksError;
TQCString ksDcop;
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_part.h b/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
index 8658778..a4b056a 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
@@ -119,6 +119,8 @@ class MpvPart : public KaffeinePart
void slotTogglePlaytimeMode();
+ void updateMetadata();
+
signals:
void mpvEvents();