Petteri Hintsanen
2015-10-18 20:25:02 UTC
New function emms-browser-get-track-field-extended uses albumartist,
originalyear and originaldate tags for grouping tracks in the browser.
It can be assigned to emms-browser-get-track-field-function.
---
lisp/emms-browser.el | 56 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 53 insertions(+), 3 deletions(-)
diff --git a/lisp/emms-browser.el b/lisp/emms-browser.el
index 8a86bd2..1fc1182 100644
--- a/lisp/emms-browser.el
+++ b/lisp/emms-browser.el
@@ -1,6 +1,6 @@
;;; emms-browser.el --- a track browser supporting covers and filtering
-;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2006, 2007, 2008, 2009, 2015 Free Software Foundation, Inc.
;; Author: Damien Elmes <***@repose.cx>
;; Keywords: emms, mp3, mpeg, multimedia
@@ -419,6 +419,21 @@ Called once for each directory."
:group 'emms-browser
:type 'hook)
+(defcustom emms-browser-prefer-albumartist nil
+ "*Prefer albumartist tag.
+If non-nil, emms-browser-get-track-field-extended prefers
+albumartist tag over artist tag, if available."
+ :group 'emms-browser
+ :type 'boolean)
+
+(defcustom emms-browser-prefer-originalyear nil
+ "*Prefer originalyear and originaldate tags.
+If non-nil, emms-browser-get-track-field-extended prefers
+originalyear and originaldate tags over year and date tags, if
+available."
+ :group 'emms-browser
+ :type 'boolean)
+
(defvar emms-browser-buffer nil
"The current browser buffer, if any.")
@@ -644,6 +659,41 @@ compilations, etc."
(defun emms-browser-get-track-field-simple (track type)
(emms-track-get track type "misc"))
+(defun emms-browser-get-track-field-extended (track type)
+ "Return TYPE from TRACK.
+This function uses 'info-albumartist, 'info-originalyear,
+'info-originaldate and 'info-date symbols, if available for
+TRACK.
+
+If TYPE is 'info-year, 'info-date and 'info-originaldate are
+preferred over 'info-year and 'info-originalyear symbols.
+
+If emms-browser-prefer-albumartist is t, info-albumartist is
+preferred over info-artist.
+
+If emms-browser-prefer-originalyear is t, info-originalyear is
+preferred over info-year."
+ (cond ((eq type 'info-artist)
+ (or (when emms-browser-prefer-albumartist
+ (emms-track-get track 'info-albumartist))
+ (emms-track-get track 'info-artist "misc")))
+ ((eq type 'info-year)
+ (let ((date (or (when emms-browser-prefer-originalyear
+ (or (emms-track-get track 'info-originaldate)
+ (emms-track-get track 'info-originalyear)))
+ (emms-track-get track 'info-date)
+ (emms-track-get track 'info-year "misc"))))
+ (emms-browser-extract-year-from-date date)))
+ (t (emms-track-get track type "misc"))))
+
+(defun emms-browser-extract-year-from-date (date)
+ "Try to extract year part from DATE.
+Return DATE if the year cannot be extracted."
+ (or (nth 5 (parse-time-string date))
+ (when (string-match "^[ \t]*[0-9]\\{4\\}" date)
+ (substring date (match-beginning 0) (match-end 0)))
+ date))
+
(defun emms-browser-get-track-field-use-directory-name (track type)
(if (eq type 'info-artist)
(emms-browser-get-artist-from-path
@@ -809,8 +859,8 @@ return an empty string."
tracknum)))))
(defun emms-browser-disc-number (track)
- "Return a string representation of a track number.
-The string will end in a space. If no track number is available,
+ "Return a string representation of a disc number.
+The string will end in a space. If no disc number is available,
return an empty string."
(let ((discnum (emms-track-get track 'info-discnumber)))
(if (or (not (stringp discnum)) (string= discnum "0"))
originalyear and originaldate tags for grouping tracks in the browser.
It can be assigned to emms-browser-get-track-field-function.
---
lisp/emms-browser.el | 56 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 53 insertions(+), 3 deletions(-)
diff --git a/lisp/emms-browser.el b/lisp/emms-browser.el
index 8a86bd2..1fc1182 100644
--- a/lisp/emms-browser.el
+++ b/lisp/emms-browser.el
@@ -1,6 +1,6 @@
;;; emms-browser.el --- a track browser supporting covers and filtering
-;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2006, 2007, 2008, 2009, 2015 Free Software Foundation, Inc.
;; Author: Damien Elmes <***@repose.cx>
;; Keywords: emms, mp3, mpeg, multimedia
@@ -419,6 +419,21 @@ Called once for each directory."
:group 'emms-browser
:type 'hook)
+(defcustom emms-browser-prefer-albumartist nil
+ "*Prefer albumartist tag.
+If non-nil, emms-browser-get-track-field-extended prefers
+albumartist tag over artist tag, if available."
+ :group 'emms-browser
+ :type 'boolean)
+
+(defcustom emms-browser-prefer-originalyear nil
+ "*Prefer originalyear and originaldate tags.
+If non-nil, emms-browser-get-track-field-extended prefers
+originalyear and originaldate tags over year and date tags, if
+available."
+ :group 'emms-browser
+ :type 'boolean)
+
(defvar emms-browser-buffer nil
"The current browser buffer, if any.")
@@ -644,6 +659,41 @@ compilations, etc."
(defun emms-browser-get-track-field-simple (track type)
(emms-track-get track type "misc"))
+(defun emms-browser-get-track-field-extended (track type)
+ "Return TYPE from TRACK.
+This function uses 'info-albumartist, 'info-originalyear,
+'info-originaldate and 'info-date symbols, if available for
+TRACK.
+
+If TYPE is 'info-year, 'info-date and 'info-originaldate are
+preferred over 'info-year and 'info-originalyear symbols.
+
+If emms-browser-prefer-albumartist is t, info-albumartist is
+preferred over info-artist.
+
+If emms-browser-prefer-originalyear is t, info-originalyear is
+preferred over info-year."
+ (cond ((eq type 'info-artist)
+ (or (when emms-browser-prefer-albumartist
+ (emms-track-get track 'info-albumartist))
+ (emms-track-get track 'info-artist "misc")))
+ ((eq type 'info-year)
+ (let ((date (or (when emms-browser-prefer-originalyear
+ (or (emms-track-get track 'info-originaldate)
+ (emms-track-get track 'info-originalyear)))
+ (emms-track-get track 'info-date)
+ (emms-track-get track 'info-year "misc"))))
+ (emms-browser-extract-year-from-date date)))
+ (t (emms-track-get track type "misc"))))
+
+(defun emms-browser-extract-year-from-date (date)
+ "Try to extract year part from DATE.
+Return DATE if the year cannot be extracted."
+ (or (nth 5 (parse-time-string date))
+ (when (string-match "^[ \t]*[0-9]\\{4\\}" date)
+ (substring date (match-beginning 0) (match-end 0)))
+ date))
+
(defun emms-browser-get-track-field-use-directory-name (track type)
(if (eq type 'info-artist)
(emms-browser-get-artist-from-path
@@ -809,8 +859,8 @@ return an empty string."
tracknum)))))
(defun emms-browser-disc-number (track)
- "Return a string representation of a track number.
-The string will end in a space. If no track number is available,
+ "Return a string representation of a disc number.
+The string will end in a space. If no disc number is available,
return an empty string."
(let ((discnum (emms-track-get track 'info-discnumber)))
(if (or (not (stringp discnum)) (string= discnum "0"))
--
2.1.4
2.1.4