From 9ca00913de53e5cde5dd148299ff117575739d35 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 18 Jan 2024 19:28:35 +0200 Subject: Add yeetube-get-thumbnails --- yeetube.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index 01100cb..28ea9a4 100644 --- a/yeetube.el +++ b/yeetube.el @@ -232,6 +232,20 @@ WHERE indicates where in the buffer the update should happen." (save-buffer) (kill-buffer))) +(cl-defun yeetube-get-thumbnails (content) + "Download thumbnails for CONTENT using `wget'." + (interactive) + (let ((wget-exec (executable-find "wget")) + (default-directory temporary-file-directory)) + (unless wget-exec + (error "Please install `wget', to download thumbnails")) + (cl-loop for item in content + do (let ((title (plist-get item :title)) + (thumbnail (plist-get item :thumbnail))) + (call-process-shell-command + (concat "wget " (shell-quote-argument thumbnail) " -O" (shell-quote-argument title)) + nil 0))))) + ;;;###autoload (defun yeetube-search (query) "Search for QUERY." @@ -246,7 +260,8 @@ WHERE indicates where in the buffer the update should happen." (decode-coding-region (point-min) (point-max) 'utf-8) (goto-char (point-min)) (toggle-enable-multibyte-characters) - (yeetube-get-content)) + (yeetube-get-content) + (yeetube-get-thumbnails yeetube-content)) (with-current-buffer (switch-to-buffer (get-buffer-create (concat "*yeetube*"))) (yeetube-mode))) -- cgit v1.2.3 From b1e0585bac20fdac244ac38ed48c04669bfc94b4 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 18 Jan 2024 19:28:50 +0200 Subject: yeetube-get-item: Rewrite as cl-defun and return item --- yeetube.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yeetube.el b/yeetube.el index 28ea9a4..7c5473c 100644 --- a/yeetube.el +++ b/yeetube.el @@ -276,15 +276,18 @@ WHERE indicates where in the buffer the update should happen." (nth invidious-instance yeetube-invidious-instances) (yeetube-get-url))))) -(defun yeetube-get-item (query) +(cl-defun yeetube-get-item (&key item (item-start "text") item-end (substring-start 3) substring-end) "Get item from youtube results for QUERY. Video result starts with videorenderer. Search back to videorenderer (start of video results), then for item." (search-backward "videorenderer" nil t) - (search-forward query nil t) - (search-forward "text" nil t)) + (search-forward item nil t) + (search-forward item-start nil t) + (let ((item (buffer-substring (+ (point) substring-start) + (- (search-forward item-end) substring-end)))) + item)) (defvar yeetube--title-replacements '(("&" . "&") -- cgit v1.2.3 From 6599aff081957c1d26b9bee543c72d5789b86812 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 18 Jan 2024 19:29:12 +0200 Subject: yeetube-get-content: Rewrite & Simplify --- yeetube.el | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/yeetube.el b/yeetube.el index 7c5473c..ee86a86 100644 --- a/yeetube.el +++ b/yeetube.el @@ -318,28 +318,28 @@ then for item." (let ((videoid (buffer-substring (+ (point) 3) (- (search-forward ",") 2)))) (unless (member videoid (car yeetube-content)) - (yeetube-get-item "title") ;; Video Title - (let ((title (buffer-substring (+ (point) 3) - (- (search-forward ",\"") 5)))) - (unless (member title (car yeetube-content)) - (yeetube-get-item "viewcounttext") ;; View Count - (let ((view-count (buffer-substring (+ (point) 3) - (- (search-forward " ") 0)))) - (yeetube-get-item "lengthtext") ;; Video Duration - (let ((video-duration (buffer-substring (+ (point) 3) - (- (search-forward "},") 3)))) - (yeetube-get-item "longbylinetext") ;; Channel Name - (let ((channel (buffer-substring (+ (point) 3) - (- (search-forward ",") 2)))) - (push (list :title title - :videoid videoid - :view-count (yeetube-view-count-format view-count) - :duration video-duration - :channel channel) - yeetube-content)))))))))) + (let ((title (yeetube-get-item :item "title" :item-end ",\"" :substring-end 5)) + (view-count (yeetube-get-item :item "viewcounttext" :item-end " " :substring-end 0)) + (video-duration (yeetube-get-item :item "lengthtext" :item-end "}," :substring-end 3)) + (channel (yeetube-get-item :item "longbylinetext" :item-end "," :substring-end 2)) + (thumbnail (yeetube-get-item :item "thumbnail" :item-start "url" :item-end ",\"" :substring-end 5))) + (push (list :title title + :videoid videoid + :view-count (yeetube-view-count-format view-count) + :duration video-duration + :channel channel + :thumbnail thumbnail) + yeetube-content)))))) (add-variable-watcher 'yeetube-saved-videos #'yeetube-update-saved-videos-list) +;; View thumbnail using eww +(defun yeetube-view-thumbnail () + "Open URL using eww in a new buffer." + (interactive) + (eww-browse-url (yeetube-get :thumbnail))) + + ;; Yeetube Downlaod: (defvar yeetube-ytdlp (executable-find "yt-dlp") -- cgit v1.2.3 From 0f032f864d5cb9a3bd31e87a086f4a3dcd239bf6 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 18 Jan 2024 19:30:05 +0200 Subject: yeetube-mode-map: Add yeetube-view-thumbnail --- yeetube.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yeetube.el b/yeetube.el index ee86a86..a653174 100644 --- a/yeetube.el +++ b/yeetube.el @@ -444,6 +444,7 @@ FIELDS-FACE-PAIRS is a list of fields and faces." "s" #'yeetube-save-video "P" #'yeetube-play-saved-video "r" #'yeetube-replay + "t" #'yeetube-view-thumbnail "q" #'quit-window) (define-derived-mode yeetube-mode tabulated-list-mode "Yeetube" @@ -463,8 +464,7 @@ FIELDS-FACE-PAIRS is a list of fields and faces." tabulated-list-sort-key (cons "Title" nil)) (display-line-numbers-mode 0) (tabulated-list-init-header) - (tabulated-list-print) - (hl-line-mode)) + (tabulated-list-print)) (provide 'yeetube) ;;; yeetube.el ends here -- cgit v1.2.3 From b91ddbac4f76c42a1e4b37f6bd717a273bfa83b7 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 13:36:34 +0200 Subject: Update docstrings & add comments --- yeetube.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/yeetube.el b/yeetube.el index a653174..bf2fdd0 100644 --- a/yeetube.el +++ b/yeetube.el @@ -232,8 +232,12 @@ WHERE indicates where in the buffer the update should happen." (save-buffer) (kill-buffer))) +;; TODO: Find a way to display thumbnails in tabulated list (cl-defun yeetube-get-thumbnails (content) - "Download thumbnails for CONTENT using `wget'." + "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." (interactive) (let ((wget-exec (executable-find "wget")) (default-directory temporary-file-directory)) @@ -261,7 +265,9 @@ WHERE indicates where in the buffer the update should happen." (goto-char (point-min)) (toggle-enable-multibyte-characters) (yeetube-get-content) - (yeetube-get-thumbnails yeetube-content)) + ;; (yeetube-get-thumbnails yeetube-content) ;; download thumbnails + ;; unfortunately can't use images them with tabulated list + ) (with-current-buffer (switch-to-buffer (get-buffer-create (concat "*yeetube*"))) (yeetube-mode))) -- cgit v1.2.3 From 34fc9dfc121f21272a0fa2f335d6f47d50ed97c9 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 13:36:45 +0200 Subject: Rename yeetube-get-item -> yeetube-scrape-item --- yeetube.el | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/yeetube.el b/yeetube.el index bf2fdd0..7e6138b 100644 --- a/yeetube.el +++ b/yeetube.el @@ -282,12 +282,17 @@ This is used to download thumbnails from `yeetube-content', within (nth invidious-instance yeetube-invidious-instances) (yeetube-get-url))))) -(cl-defun yeetube-get-item (&key item (item-start "text") item-end (substring-start 3) substring-end) - "Get item from youtube results for QUERY. +(cl-defun yeetube-scrape-item (&key item (item-start "text") item-end (substring-start 3) substring-end) + "Scrape ITEM from YouTube.com. Video result starts with videorenderer. Search back to videorenderer (start of video results), -then for item." +then for item. + +ITEM-START is the start of the information for item. +ITEM-END is the end of the item information. +SUBSTRING-START is the start of the string to return, integer. +SUBSTRING-END is the end of the string to return, interger." (search-backward "videorenderer" nil t) (search-forward item nil t) (search-forward item-start nil t) @@ -324,11 +329,11 @@ then for item." (let ((videoid (buffer-substring (+ (point) 3) (- (search-forward ",") 2)))) (unless (member videoid (car yeetube-content)) - (let ((title (yeetube-get-item :item "title" :item-end ",\"" :substring-end 5)) - (view-count (yeetube-get-item :item "viewcounttext" :item-end " " :substring-end 0)) - (video-duration (yeetube-get-item :item "lengthtext" :item-end "}," :substring-end 3)) - (channel (yeetube-get-item :item "longbylinetext" :item-end "," :substring-end 2)) - (thumbnail (yeetube-get-item :item "thumbnail" :item-start "url" :item-end ",\"" :substring-end 5))) + (let ((title (yeetube-scrape-item :item "title" :item-end ",\"" :substring-end 5)) + (view-count (yeetube-scrape-item :item "viewcounttext" :item-end " " :substring-end 0)) + (video-duration (yeetube-scrape-item :item "lengthtext" :item-end "}," :substring-end 3)) + (channel (yeetube-scrape-item :item "longbylinetext" :item-end "," :substring-end 2)) + (thumbnail (yeetube-scrape-item :item "thumbnail" :item-start "url" :item-end ",\"" :substring-end 5))) (push (list :title title :videoid videoid :view-count (yeetube-view-count-format view-count) -- cgit v1.2.3