From 16b7d09d63f21a462387d4412d6827b5cd1306dc Mon Sep 17 00:00:00 2001 From: Soham Chowdhury Date: Mon, 5 Dec 2016 00:03:04 +0530 Subject: [PATCH] feat(mpd): Add support for date (#222) --- include/adapters/mpd.hpp | 1 + src/adapters/mpd.cpp | 9 +++++++++ src/modules/mpd.cpp | 3 +++ 3 files changed, 13 insertions(+) diff --git a/include/adapters/mpd.hpp b/include/adapters/mpd.hpp index 685bac48..26877ca2 100644 --- a/include/adapters/mpd.hpp +++ b/include/adapters/mpd.hpp @@ -63,6 +63,7 @@ namespace mpd { string get_artist(); string get_album(); string get_title(); + string get_date(); unsigned get_duration(); private: diff --git a/src/adapters/mpd.cpp b/src/adapters/mpd.cpp index a5ad8a32..538e101e 100644 --- a/src/adapters/mpd.cpp +++ b/src/adapters/mpd.cpp @@ -76,6 +76,15 @@ namespace mpd { return string{tag}; } + string mpdsong::get_date() { + assert(m_song); + auto tag = mpd_song_get_tag(m_song.get(), MPD_TAG_DATE, 0); + if (tag == nullptr) { + return ""; + } + return string{tag}; + } + string mpdsong::get_title() { assert(m_song); auto tag = mpd_song_get_tag(m_song.get(), MPD_TAG_TITLE, 0); diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 0b194590..12f7e3cf 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -191,6 +191,7 @@ namespace modules { string artist; string album; string title; + string date; string elapsed_str; string total_str; @@ -207,6 +208,7 @@ namespace modules { artist = song->get_artist(); album = song->get_album(); title = song->get_title(); + date = song->get_date(); } } } catch (const mpd_exception& err) { @@ -219,6 +221,7 @@ namespace modules { m_label_song->replace_token("%artist%", !artist.empty() ? artist : "untitled artist"); m_label_song->replace_token("%album%", !album.empty() ? album : "untitled album"); m_label_song->replace_token("%title%", !title.empty() ? title : "untitled track"); + m_label_song->replace_token("%date%", !date.empty() ? date : "unknown date"); } if (m_label_time) {