aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-emms.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-emms.el')
-rw-r--r--emacs/.emacs.d/lisp/my/my-emms.el149
1 files changed, 125 insertions, 24 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-emms.el b/emacs/.emacs.d/lisp/my/my-emms.el
index 799c5f3..91065a2 100644
--- a/emacs/.emacs.d/lisp/my/my-emms.el
+++ b/emacs/.emacs.d/lisp/my/my-emms.el
@@ -157,7 +157,11 @@ either 'audio or 'video
(let ((emms-track-initialize-functions nil))
(my-emms-add-url-lists from
(alist-get type my-extension-types)))
- (with-current-buffer to (emms-sort))))
+ (with-current-buffer to
+ (goto-char (point-min))
+ (let ((inhibit-read-only t))
+ (flush-lines "/Music/Archived/"))
+ (emms-sort))))
(defun my-emms-players-preference (track players)
"If audio, use first player, otherwise second."
@@ -257,8 +261,7 @@ filter extensions from filter-exts."
(not (equal s ""))
(or (not filter-exts)
(member
- (when (string-match "^.*\\.\\(.*\\)$" s)
- (match-string 1 s))
+ (downcase (or (file-name-extension s) ""))
filter-exts))))
(split-string
(buffer-substring-no-properties from to) "
@@ -464,26 +467,88 @@ under /zzz-seren/."
(min end-ln maybe-group-end))))
(cons group-start group-end))))
+(defvar-local my-emms-playlist-group-start-overlay nil)
+(defvar-local my-emms-playlist-group-end-overlay nil)
+
+(defun my-emms-playlist-mark-bounds (group-end)
+ "Mark bounds of the current track group.
+
+An up arrow at the first played in the current group, and a down
+arrow at the end of the track group."
+ (when my-emms-playlist-group-start-overlay
+ (delete-overlay my-emms-playlist-group-start-overlay))
+ (when my-emms-playlist-group-start-overlay
+ (delete-overlay my-emms-playlist-group-end-overlay))
+ (setq my-emms-playlist-group-start-overlay (make-overlay (point) (point)))
+ (overlay-put
+ my-emms-playlist-group-start-overlay
+ 'before-string (propertize
+ "x" 'display
+ `(left-fringe up-arrow emms-playlist-selected-face)))
+ (save-excursion
+ (goto-line (1- group-end))
+ (setq my-emms-playlist-group-end-overlay (make-overlay (point) (point)))
+ (overlay-put
+ my-emms-playlist-group-end-overlay
+ 'before-string (propertize
+ "x" 'display
+ `(left-fringe down-arrow emms-playlist-selected-face)))))
+
+(defun my-emms-mode-line-playlist-current ()
+ "Format the currently playing song.
+
+Override `emms-mode-line-playlist-current' to incorporate wide chars."
+ (let ((track-desc (my-emms-get-display-name-1
+ (emms-track-description
+ (emms-playlist-current-selected-track)))))
+ (format emms-mode-line-format
+ (if (< (string-width track-desc) emms-mode-line-length-limit)
+ track-desc
+ (concat
+ (seq-subseq
+ track-desc 0
+ (- (length track-desc)
+ (- (string-width track-desc) emms-mode-line-length-limit)))
+ "...")))))
+
+
+;; (defun my-emms-playing-time-mode-line ()
+;; "Add playing time to the mode line.
+
+;; Override `emms-playing-time-mode-line': prepend instead of append."
+;; (or global-mode-string (setq global-mode-string '("")))
+;; (unless (member 'emms-playing-time-string
+;; global-mode-string)
+;; (setq global-mode-string
+;; (append '(emms-playing-time-string) global-mode-string))))
+
+
(defun my-emms-playlist-random-group ()
(interactive)
(with-current-emms-playlist
- (remove-overlays)
- (goto-line (1+ (random (count-lines (point-min) (point-max)))))
- (pcase-let ((`(,group-start . ,group-end) (my-emms-playlist-group-bounds)))
- (goto-line group-start)
- (overlay-put
- (make-overlay (point) (point))
- 'before-string (propertize
- "x" 'display
- `(left-fringe down-arrow emms-playlist-selected-face)))
- (save-excursion
- (goto-line (1- group-end))
- (overlay-put
- (make-overlay (point) (point))
- 'before-string (propertize
- "x" 'display
- `(left-fringe up-arrow emms-playlist-selected-face))))
- (emms-playlist-mode-play-current-track))))
+ (let ((random-line (1+ (random (count-lines (point-min) (point-max))))))
+ (goto-line random-line)
+ (pcase-let ((`(,group-start . ,group-end) (my-emms-playlist-group-bounds)))
+ (message "my-emms-playlist-random-group: (%d, %d)" random-line group-start)
+ (goto-line group-start)
+ (my-emms-playlist-mark-bounds group-end)
+ (emms-playlist-mode-play-current-track)))))
+
+;;; TODO: mark bounds if and only if the currently played is out of
+;;; the existing overlay.
+(defun my-emms-playlist-maybe-mark-bounds ()
+ "Used as an `emms-player-started-hook'.
+
+If the last command is `emms-playlist-mode-play-smart' i.e. the
+user manually chose the track to play, and if
+`emms-player-next-function' is
+`my-emms-next-track-or-random-group', then mark boundaries since
+it would not have been marked otherwise."
+ (when (and (eq last-command 'emms-playlist-mode-play-smart)
+ (eq emms-player-next-function 'my-emms-next-track-or-random-group))
+ (with-current-emms-playlist
+ (pcase-let ((`(_ . ,group-end) (my-emms-playlist-group-bounds)))
+ (my-emms-playlist-mark-bounds group-end)))))
(defun my-emms-next-track-or-random-group ()
(interactive)
@@ -563,12 +628,22 @@ character."
(defvar my-emms-score-delta 1)
(defun my-emms-score-up-playing ()
- "Increase score by `my-emms-score-delta', then reset it to 1."
+ "Increase score by `my-emms-score-delta', then reset the score delta to 1."
(emms-score-change-score
my-emms-score-delta
(my-emms-get-display-name-1 (emms-score-current-selected-track-filename)))
(setq my-emms-score-delta 1))
+(defun my-emms-score-show-playing ()
+ "Show score for current playing track in minibuf.
+
+Override `emms-score-show-playing' - using last three components in the name..."
+ (interactive)
+ (message "track/tolerance score: %d/%d"
+ (emms-score-get-score (my-emms-get-display-name-1
+ (emms-score-current-selected-track-filename)))
+ emms-score-min-score))
+
(defun my-emms-score-up-chosen-bonus ()
"Bonus score up if the track is started intentionally.
@@ -580,15 +655,41 @@ If the last command is `emms-playlist-mode-play-smart', then set
(setq last-command nil))
)
-(defun my-emms-wrapped ()
+(defun my-emms-wrapped (&optional n)
"Print top 10 scored tracks."
- (interactive)
+ (interactive "p")
(let (keys)
(maphash (lambda (k _) (push k keys)) emms-score-hash)
(sort keys (lambda (k1 k2)
(> (cl-second (gethash k1 emms-score-hash))
(cl-second (gethash k2 emms-score-hash)))))
- (message "Top 10: %s" (string-join (take 10 keys) "\n"))))
+ (message "Top %s: %s" (or n 10) (string-join (take (or n 10) keys) "\n"))))
+
+(defun my-emms-maybe-get-duration-for-current-track ()
+ "Get duration for the current track.
+
+Can be used as a `emms-player-started-hook'"
+ (unless (emms-track-get (emms-playlist-current-selected-track)
+ 'info-playing-time)
+ (my-emms-info-ffprobe (emms-playlist-current-selected-track))))
+
+(defun my-emms-info-ffprobe (track)
+ "Use ffprobe for urls to get duration.
+
+Call
+
+ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1
+
+on the url"
+ (when (eq (emms-track-type track) 'url)
+ (with-temp-buffer
+ (call-process "ffprobe" nil t nil "-v" "error" "-show_entries"
+ "format=duration" "-of" "default=noprint_wrappers=1:nokey=1"
+ (emms-track-name track))
+ (let ((duration (string-trim (buffer-string))))
+ (when (string-match-p "[0-9.]+" duration)
+ (emms-track-set track 'info-playing-time
+ (floor (string-to-number duration))))))))
(provide 'my-emms)
;;; my-emms.el ends here