From b1da2ccfe0a23b7de7a15f5bcfb310c3601f1a47 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:19:36 +0200 Subject: Update copyright & package desc --- yeetube.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yeetube.el b/yeetube.el index f30ba29..ad32d9f 100644 --- a/yeetube.el +++ b/yeetube.el @@ -1,6 +1,6 @@ -;;; yeetube.el --- Scrape YouTube - Control MPV - Download content with yt-dlp | -*- lexical-binding: t; -*- +;;; yeetube.el --- Scrape YouTube - Play with mpv & Download with yt-dlp | -*- lexical-binding: t; -*- -;; Copyright (C) 2023 Thanos Apollo +;; Copyright (C) 2023-2024 Thanos Apollo ;; Author: Thanos Apollo ;; Keywords: extensions youtube videos -- cgit v1.2.3 From 324af85bf74986ea2f0f057306e74e64e3d512fb Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:19:51 +0200 Subject: yeetube-download-dir: Use expand-file-name Fix issues for non unix systems --- yeetube.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index ad32d9f..90468ad 100644 --- a/yeetube.el +++ b/yeetube.el @@ -74,7 +74,7 @@ (const :tag "WAV" "wav")) :group 'yeetube) -(defcustom yeetube-download-directory "~/Downloads" +(defcustom yeetube-download-directory (expand-file-name "Downloads" "~") "Default directory to downlaod videos." :type 'string :group 'yeetube) -- cgit v1.2.3 From 93f6f218deb06b73a2af1b2c8bdbb7a547a0c53e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:20:32 +0200 Subject: Add defcustom yeetube-thumbnail size Cons for height & width --- yeetube.el | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/yeetube.el b/yeetube.el index 90468ad..4f7f1d3 100644 --- a/yeetube.el +++ b/yeetube.el @@ -116,14 +116,9 @@ Valid options include: :tag "Yeetube Faces" :prefix 'yeetube-face) -(defcustom yeetube-thumbnail-height 80 - "Height of the thumbnail." - :type 'number - :group 'yeetube) - -(defcustom yeetube-thumbnail-width 80 - "Width of the thumbnail." - :type 'number +(defcustom yeetube-thumbnail-size '(90 . 90) + "Thumbnail size (height width)." + :type '(cons integer integer) :group 'yeetube) (defcustom yeetube-display-thumbnails nil -- cgit v1.2.3 From 35e9f3376b046a0addfdd577df28db1fdca1b2af Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:21:11 +0200 Subject: Add yeetube--wget-thumbnail - Adds torsocks support as well --- yeetube.el | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/yeetube.el b/yeetube.el index 4f7f1d3..7f0050b 100644 --- a/yeetube.el +++ b/yeetube.el @@ -290,27 +290,35 @@ WHERE indicates where in the buffer the update should happen." (save-buffer) (kill-buffer))) -;; TODO: Find a way to display thumbnails in tabulated list +(defun yeetube--wget-thumbnail (torsocks url &optional output) + "Get thumbnail using `wget' from URL. + +If TORSOCKS is non-nil, use torsocks to download URL. +URL is the URL to download. +OUTPUT is the output file name." + (let ((wget-exec (executable-find "wget"))) + (unless wget-exec + (error "Please install `wget' to download videos")) + (let ((command (if torsocks + (format "%s %s %s -O %s.jpg" (executable-find "torsocks") wget-exec + (shell-quote-argument url) (shell-quote-argument output)) + (format "%s %s -O %s.jpg" wget-exec (shell-quote-argument url) + (shell-quote-argument output))))) + (call-process-shell-command command nil 0)))) + + (cl-defun yeetube-get-thumbnails (content) "Download thumbnails for CONTENT using `wget'. -This is used to download thumbnails from `yeetube-content', within -`yeetube-search'. We can't as of now use images with tabulated-list." +This is used to download thumbnails from `yeetube-content'." (interactive) (when yeetube-display-thumbnails - (let ((wget-exec (executable-find "wget")) - (default-directory temporary-file-directory)) - (unless wget-exec - (error "Please install `wget', to download thumbnails")) + (let ((default-directory temporary-file-directory)) (cl-loop for item in content do (let ((thumbnail (plist-get item :thumbnail)) (videoid (plist-get item :videoid))) - (call-process-shell-command - (format "%s %s %s %s.jpg" wget-exec - (shell-quote-argument thumbnail) - "-O" - videoid) - nil 0)))))) + (unless (file-exists-p (expand-file-name (concat videoid ".jpg"))) + (yeetube--wget-thumbnail yeetube-enable-tor thumbnail videoid))))))) (defvar yeetube-filter-code-alist '(("Relevance" . "EgIQAQ%253D%253D") -- cgit v1.2.3 From 65bdd404cc25f169bdbda0f757c6e79cbcfd95da Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:21:58 +0200 Subject: Add yeetube-iimage-mode-buffer Allow for custom thumbnail size --- yeetube.el | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index 7f0050b..50cf944 100644 --- a/yeetube.el +++ b/yeetube.el @@ -572,6 +572,29 @@ column." (< (string-to-number (nth 0 split-a)) (string-to-number (nth 0 split-b))) (> units-a units-b)))) +;; Modified from iimage.el for hardcoded width/height +(defun yeetube-iimage-mode-buffer (arg) + "Display images if ARG is non-nil, undisplay them otherwise." + (let ((image-path (cons default-directory iimage-mode-image-search-path)) + file) + (with-silent-modifications + (save-excursion + (dolist (pair iimage-mode-image-regex-alist) + (goto-char (point-min)) + (while (re-search-forward (car pair) nil t) + (when (and (setq file (match-string (cdr pair))) + (setq file (locate-file file image-path))) + (if arg + (add-text-properties + (match-beginning 0) (match-end 0) + `(display + ,(create-image file nil nil + :max-width (car yeetube-thumbnail-size) + :max-height (cdr yeetube-thumbnail-size))) + (remove-list-of-text-properties + (match-beginning 0) (match-end 0) + '(display modification-hooks))))))))))) + (define-derived-mode yeetube-mode tabulated-list-mode "Yeetube" "Yeetube mode." :keymap yeetube-mode-map @@ -599,7 +622,7 @@ column." (display-line-numbers-mode 0) (tabulated-list-init-header) (tabulated-list-print) - (iimage-mode t)) + (yeetube-iimage-mode-buffer t)) (provide 'yeetube) ;;; yeetube.el ends here -- cgit v1.2.3 From f5d75c5e44428c31adefd382edd32443cced972d Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:22:56 +0200 Subject: Update docstrings --- yeetube.el | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/yeetube.el b/yeetube.el index 50cf944..96cd26c 100644 --- a/yeetube.el +++ b/yeetube.el @@ -106,7 +106,7 @@ Valid options include: :group 'yeetube) (defcustom yeetube-enable-tor nil - "Enable routing through tor" + "Enable routing through tor." :type 'boolean :group 'yeetube) @@ -125,7 +125,7 @@ Valid options include: "When t, fetch & display thumbnails. Disabled by default, still an experimental feature that a user should -opt-in. Note that when enabled the thumbnail images will be downloaded +opt-in. Note that when enabled the thumbnail images will be downloaded on `temporary-file-directory'." :type 'boolean :group 'yeetube) @@ -181,7 +181,7 @@ on `temporary-file-directory'." (defvar yeetube-url "https://youtube.com/watch?v=" "URL used to play videos from. -You can change this value to an invidious instance. Although yeetube +You can change this value to an invidious instance. Although yeetube will still query youtube, `yeetube-play' will use the above url to play videos from.") @@ -331,13 +331,14 @@ This is used to download thumbnails from `yeetube-content'." '(("Accept-Language" . "Accept-Language: en-US,en;q=0.9") ("Accept" . "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") ("User-Agent" . "Mozilla/5.0 (Windows NT 10.0; rv:122.0) Gecko/20100101 Firefox/122.0")) - "HTTP Request extra headers") + "HTTP Request extra headers.") (defun yeetube-get-filter-code (filter) - "Get filter code for sorting search results." + "Get FILTER code for sorting search results." (cdr (assoc filter yeetube-filter-code-alist))) (defmacro yeetube-with-tor-socks (&rest body) + "Execute BODY with torsocks." `(let ((url-gateway-method 'socks) (socks-noproxy '("localhost")) (socks-server '("Default server" "127.0.0.1" 9050 5))) @@ -471,7 +472,7 @@ Optional values: NAME for custom file name. AUDIO-FORMAT to extract and keep contents as specified audio-format only." (unless (executable-find "yt-dlp") - (error "Executable for yt-dlp not found. Please install yt-dlp")) + (error "Executable for yt-dlp not found. Please install yt-dlp")) (let* ((tor-command (when yeetube-enable-tor (executable-find "torsocks"))) (name-command (when name (format "-o %s" (shell-quote-argument name)))) (format-command (when audio-format @@ -546,23 +547,32 @@ FIELDS-FACE-PAIRS is a list of fields and faces." "q" #'quit-window) (defun yeetube--sort-views (a b) - "PREDICATE for function 'sort'. -Used by variable 'tabulated-list-format' to sort the \"Views\" -column." + "PREDICATE for function `sort'. + +Used by `tabulated-list-format' to sort the \"Views\" +column. + +A and B are vectors." (< (string-to-number (replace-regexp-in-string "," "" (aref (cadr a) 1))) (string-to-number (replace-regexp-in-string "," "" (aref (cadr b) 1))))) (defun yeetube--sort-duration (a b) - "PREDICATE for function 'sort'. -Used by variable 'tabulated-list-format' to sort the \"Duration\" -column." + "PREDICATE for function `sort'. + +Used by `tabulated-list-format' to sort the \"Duration\" +column. + +A and B are vectors." (< (string-to-number (replace-regexp-in-string ":" "" (aref (cadr a) 2))) (string-to-number (replace-regexp-in-string ":" "" (aref (cadr b) 2))))) (defun yeetube--sort-date (a b) - "PREDICATE for function 'sort'. -Used by variable 'tabulated-list-format' to sort the \"Date\" -column." + "PREDICATE for function `sort'. + +Used by variable `tabulated-list-format' to sort the \"Date\" +column. + +A and B are vectors." (let* ((intervals '("second" "minute" "hour" "day" "week" "month" "year")) (split-a (split-string (replace-regexp-in-string "s" "" (aref (cadr a) 3)))) (split-b (split-string (replace-regexp-in-string "s" "" (aref (cadr b) 3)))) -- cgit v1.2.3 From 3dbe007cb6ec643ac1635161c47ac5aac53c3d68 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:23:24 +0200 Subject: yeetube-display-thumbnails: Enable by default Since now we have proper wget support & custom thumbnail sizes, it's okay to enable it by default. --- yeetube.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index 96cd26c..ef1914a 100644 --- a/yeetube.el +++ b/yeetube.el @@ -121,7 +121,7 @@ Valid options include: :type '(cons integer integer) :group 'yeetube) -(defcustom yeetube-display-thumbnails nil +(defcustom yeetube-display-thumbnails t "When t, fetch & display thumbnails. Disabled by default, still an experimental feature that a user should -- cgit v1.2.3 From c8fc8255b9a3e2d0472ab18b8bce8de2b96d094a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 6 Mar 2024 06:23:59 +0200 Subject: yeetube-search: Use pop-to-buffer-same-window --- yeetube.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/yeetube.el b/yeetube.el index ef1914a..e3c63c9 100644 --- a/yeetube.el +++ b/yeetube.el @@ -363,9 +363,8 @@ This is used to download thumbnails from `yeetube-content'." (toggle-enable-multibyte-characters) (yeetube-get-content)) (yeetube-get-thumbnails yeetube-content)) ;; download thumbnails - (with-current-buffer - (pop-to-buffer-same-window "*yeetube*") - (yeetube-mode))) + (pop-to-buffer-same-window "*yeetube*") + (yeetube-mode)) ;;;###autoload (defun yeetube-browse-url () -- cgit v1.2.3