diff options
author | Yuchen Pei <id@ypei.org> | 2025-01-20 09:50:11 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2025-01-20 09:50:11 +1100 |
commit | b167fc6a8a97eef6555160be1584a55f7031382c (patch) | |
tree | 6fb05d8a793c6ecae8cd4289ebd34a1196bd470e /emacs/.emacs.d/lisp/my/my-ytdl.el | |
parent | 5c461f2cc4e8e76d47b98b18e883fe588fa4f11f (diff) |
[emacs] Rename mastorg to fediorg
Now that the package handles fedi posts in general, it no longer makes
sense to use mastodon-specific naming.
Also updated ytdl infobox formatting chapters and removal of extra
queries in urls
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-ytdl.el')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-ytdl.el | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-ytdl.el b/emacs/.emacs.d/lisp/my/my-ytdl.el index bf917ce..b3b1cf7 100644 --- a/emacs/.emacs.d/lisp/my/my-ytdl.el +++ b/emacs/.emacs.d/lisp/my/my-ytdl.el @@ -90,13 +90,32 @@ (defun my-ytdl-video-url-p (url) (let ((urlobj (url-generic-parse-url url))) - (or (and (string-match-p "^\\(www\\.\\)?youtube.com" (url-host urlobj)) + (or (and (string-match-p + "^\\(www\\.\\)?\\(youtube\\.com\\|yewtu\\.be\\)" + (url-host urlobj)) (string-match-p "^/watch\\?v=.*" (url-filename urlobj))) (equal "youtu.be" (url-host urlobj))))) (require 'hmm) (defvar my-ytdl-player 'hmm-external-mpv "Function to play ytdl urls.") +(defun my-ytdl-video-format-seconds (secs) + (setq secs (floor secs)) + (if (>= secs 3600) + (format "%d:%02d:%02d" + (/ secs 3600) (/ (% secs 3600) 60) (% secs 60)) + (format "%d:%02d" + (/ secs 60) (% secs 60)))) + +(defun my-ytdl-video-format-chapters (chapters) + (mapconcat + (lambda (chapter) + (let-alist chapter + (format "%s: %s-%s" .title (my-ytdl-video-format-seconds .start_time) + (my-ytdl-video-format-seconds .end_time)))) + chapters + "; ")) + (defun my-ytdl-video-render-info (info url) (setf (alist-get 'webpage_url info) (concat (alist-get 'webpage_url info) @@ -104,7 +123,9 @@ (funcall my-ytdl-player url))) " " (buttonize "context" (lambda (_) - (funcall my-url-context-function url))))) + (funcall my-url-context-function url)))) + (alist-get 'chapters info) + (my-ytdl-video-format-chapters (alist-get 'chapters info))) (infobox-render (infobox-translate info (infobox-default-specs info)) `(my-ytdl-video-infobox ,url) @@ -112,6 +133,8 @@ (defun my-ytdl-video-infobox (url) (interactive "sytdl video url: ") + ;; Remove any extra queries from the URL + (setq url (replace-regexp-in-string "&.*" "" url)) (my-ytdl-video-render-info (my-ytdl-video-info url) url)) ;;; fixme: autoload |