diff options
author | Yuchen Pei <id@ypei.org> | 2025-06-29 18:02:16 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2025-06-29 18:02:16 +1000 |
commit | 8d2ef40cd102d34e83a23f2dd663cd04bda45acb (patch) | |
tree | 62530fc0cd5b58a063d8f0417055d5901df4db01 /emacs/.emacs.d | |
parent | 76ecdb1bb0f7f7b670b8885428b91b93ba27e60e (diff) |
[emacs] emms get duration using ffprobe
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r-- | emacs/.emacs.d/init/ycp-emms.el | 3 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-emms.el | 28 |
2 files changed, 30 insertions, 1 deletions
diff --git a/emacs/.emacs.d/init/ycp-emms.el b/emacs/.emacs.d/init/ycp-emms.el index 0385a75..c213157 100644 --- a/emacs/.emacs.d/init/ycp-emms.el +++ b/emacs/.emacs.d/init/ycp-emms.el @@ -34,6 +34,7 @@ (emms-all) (setq emms-playing-time-resume-from-last-played t) (add-to-list 'emms-info-functions 'emms-info-ytdl) + (add-to-list 'emms-info-functions 'my-emms-info-ffprobe) ;; emms-info-native is not very useful (delete 'emms-info-native emms-info-functions) (setq emms-source-file-default-directory (locate-user-emacs-file "emms")) @@ -46,6 +47,7 @@ (setq emms-source-file-directory-tree-function 'emms-source-file-directory-tree-find) (setq emms-info-ytdl-using-torsocks t) + (setq emms-info-auto-update nil) (add-hook 'emms-playlist-mode-hook #'hl-line-mode) (add-hook 'emms-metaplaylist-mode-hook #'hl-line-mode) ) @@ -93,6 +95,7 @@ (add-hook 'emms-player-finished-hook 'my-emms-score-up-playing) (add-hook 'emms-player-started-hook 'my-emms-score-up-chosen-bonus) (add-hook 'emms-player-started-hook 'my-emms-playlist-maybe-mark-bounds) + (add-hook 'emms-player-started-hook 'my-emms-maybe-get-duration-for-current-track) (setq emms-player-next-function 'my-emms-next-track-or-random-group) (setq emms-players-preference-f 'my-emms-players-preference) (my-keybind dired-mode-map "e" #'my-dired-add-to-emms) diff --git a/emacs/.emacs.d/lisp/my/my-emms.el b/emacs/.emacs.d/lisp/my/my-emms.el index 50c1310..c2d2eaa 100644 --- a/emacs/.emacs.d/lisp/my/my-emms.el +++ b/emacs/.emacs.d/lisp/my/my-emms.el @@ -469,6 +469,7 @@ under /zzz-seren/." An up arrow at the first played in the current group, and a down arrow at the end of the track group." + (remove-overlays) (overlay-put (make-overlay (point) (point)) 'before-string (propertize @@ -485,7 +486,6 @@ arrow at the end of the track group." (defun my-emms-playlist-random-group () (interactive) (with-current-emms-playlist - (remove-overlays) (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))) @@ -613,5 +613,31 @@ If the last command is `emms-playlist-mode-play-smart', then set (cl-second (gethash k2 emms-score-hash))))) (message "Top 10: %s" (string-join (take 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 |