aboutsummaryrefslogtreecommitdiff
path: root/lisp/emms.el
diff options
context:
space:
mode:
authorPierre Neidhardt <ambrevar@gmail.com>2017-11-26 18:35:44 +0100
committerPierre Neidhardt <ambrevar@gmail.com>2017-11-27 08:21:06 +0100
commit0960515e644015c6d85549fa3bef3d67c0ee7116 (patch)
treed017e4f5677f9cc5ff0b63eafeb9d3ebbd14584c /lisp/emms.el
parentbabc32f7079b1a5925b60fa5c9874c9ccbb5c414 (diff)
lisp/emms-browser.el: Extract year from info-date or fallback on info-year
Diffstat (limited to 'lisp/emms.el')
-rw-r--r--lisp/emms.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/lisp/emms.el b/lisp/emms.el
index b91115e..0f2bd03 100644
--- a/lisp/emms.el
+++ b/lisp/emms.el
@@ -705,6 +705,29 @@ string), a confusing error message would result."
desc
(emms-track-simple-description track))))
+(defun emms-track-get-year (track)
+ "Get year of TRACK for display.
+There is the separation between the 'release date' and the
+'original date'. This difference matters e.g. for
+re-releases (anniversaries and such) where the release date is
+more recent than the original release date. In such cases the
+user probably wants the original release date so this is what we
+show."
+ (or
+ (emms-format-date-to-year (emms-track-get track 'info-date))
+ (emms-format-date-to-year (emms-track-get track 'info-originaldate))
+ (emms-track-get track 'info-year)
+ (emms-track-get track 'info-originalyear)))
+
+(defun emms-format-date-to-year (date)
+ "Try to extract year part from DATE.
+Return nil if the year cannot be extracted."
+ (when date
+ (let ((year (nth 5 (parse-time-string date))))
+ (if year (number-to-string year)
+ (when (string-match "^[ \t]*\\([0-9]\\{4\\}\\)" date)
+ (match-string 1 date))))))
+
;;; The Playlist