diff options
-rw-r--r-- | yeetube-buffer.el | 31 | ||||
-rw-r--r-- | yeetube.el | 18 |
2 files changed, 30 insertions, 19 deletions
diff --git a/yeetube-buffer.el b/yeetube-buffer.el index 0042fcc..565d192 100644 --- a/yeetube-buffer.el +++ b/yeetube-buffer.el @@ -180,6 +180,16 @@ Emojis cause formatting issues, this should be off by default." (yeetube-buffer--format-video-duration "Duration") (yeetube-buffer--format-channel "Channel")))) +(defun yeetube-buffer-insert-content (content) + "Insert formatted CONTENT." + (insert + (concat (yeetube-buffer--format-title (yeetube-buffer-fix-title (car content))) + (yeetube-buffer--format-view-count (yeetube-buffer-view-count-add-commas + (yeetube-buffer-fix-view-count (nth 2 content)))) + (yeetube-buffer--format-video-duration (nth 3 content)) + (yeetube-buffer--format-channel (nth 4 content)) + "\n"))) + ;;;###autoload (defun yeetube-buffer-create (query content buffer-mode) "Create *yeetube* buffer with BUFFER-MODE for search QUERY, displaying CONTENT." @@ -189,24 +199,11 @@ Emojis cause formatting issues, this should be off by default." (setf buffer-read-only nil) (erase-buffer) (yeetube-buffer--format-header query) - (dolist (info (reverse content)) - (let ((title (yeetube-buffer-fix-title (car info))) - (view-count (nth 2 info)) - (video-duration (nth 3 info)) - (channel-name (nth 4 info))) - (insert - (yeetube-buffer--format-title title) - (yeetube-buffer--format-view-count - (yeetube-buffer-view-count-add-commas - (yeetube-buffer-fix-view-count view-count))) - (yeetube-buffer--format-video-duration - (if (string-match-p "^[0-9:]+$" video-duration) - video-duration - "nil")) - (yeetube-buffer--format-channel channel-name) - "\n"))) + (cl-loop for result in (reverse content) + do (yeetube-buffer-insert-content result)) (delete-char -1) - (goto-char (point-min)))) + (goto-char (point-min)) + (setf buffer-read-only t))) (provide 'yeetube-buffer) ;;; yeetube-buffer.el ends here @@ -72,6 +72,15 @@ Example Usage: :type 'string :group 'yeetube) +(defvar yeetube-invidious-instances + '("vid.puffyan.us" + "invidious.flokinet.to" + "yt.artemislena.eu" + "invidious.privacydev.net" + "onion.tube" + "yewtu.be") + "List of invidious instaces.") + (defvar yeetube-content nil "Scraped content.") @@ -165,9 +174,13 @@ WHERE indicates where in the buffer the update should happen." (yeetube-buffer-create query yeetube-content 'yeetube-mode))) (defun yeetube-browse-url () - "Open URL in browser." + "Open URL for video at point, using an invidious instance." (interactive) - (browse-url (yeetube-get-url))) + (let ((invidious-instance (+ 1 (random (length yeetube-invidious-instances))))) + (browse-url + (replace-regexp-in-string "youtube.com" + (nth invidious-instance yeetube-invidious-instances) + (yeetube-get-url))))) (defun yeetube-get-item (query) "Get item from youtube results for QUERY. @@ -281,6 +294,7 @@ prompt blank to keep the default name." ;; Yeetube Mode (defvar yeetube-mode-map (make-sparse-keymap)) (define-key yeetube-mode-map (kbd "RET") #'yeetube-play) +(define-key yeetube-mode-map (kbd "b") #'yeetube-browse-url) (define-key yeetube-mode-map (kbd "d") #'yeetube-download-video) (define-key yeetube-mode-map (kbd "D") #'yeetube-download-change-directory) (define-key yeetube-mode-map (kbd "a") #'yeetube-download-change-audio-format) |