From 998c8e2a00cdb3ae64735b8564336c37a6a9518a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:08:18 +0200 Subject: yeetube-results-limit: fix typo --- yeetube.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index a79bcef..7f0dc8b 100644 --- a/yeetube.el +++ b/yeetube.el @@ -51,7 +51,7 @@ (defcustom yeetube-results-limit 20 "Define a limit for search results." - :type 'natnump + :type 'number :group 'yeetube) (defcustom yeetube-player #'yeetube-mpv-play -- cgit v1.2.3 From 8d5d7ea41d36330f16388a224f02847e990ce88d Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:20:20 +0200 Subject: remove yeetube-buffer.el Redoing with tabulated-list makes yeetube-buffer obsolete --- yeetube-buffer.el | 192 ------------------------------------------------------ yeetube.el | 2 +- 2 files changed, 1 insertion(+), 193 deletions(-) delete mode 100644 yeetube-buffer.el diff --git a/yeetube-buffer.el b/yeetube-buffer.el deleted file mode 100644 index 379a8eb..0000000 --- a/yeetube-buffer.el +++ /dev/null @@ -1,192 +0,0 @@ -;;; yeetube-buffer.el --- Yeetube Buffer -*- lexical-binding: t; -*- - -;; Copyright (C) 2023 Thanos Apollo - -;; Author: Thanos Apollo -;; Keywords: extensions youtube videos -;; URL: https://git.thanosapollo.org/yeetube - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; This package is an extension for yeetube, to create a custom -;; *yeetube* buffer. - -;;; Code: - -(require 'cl-lib) - -(defcustom yeetube-buffer-display-emojis nil - "Display video title's emojis. - -Emojis cause formatting issues, this should be off by default." - :type 'boolean - :group 'yeetube) - -(defgroup yeetube-buffer-faces nil - "Faces used by yeetube." - :group 'yeetube - :tag "Yeetube Faces" - :prefix 'yeetube-face) - -(defface yeetube-buffer-face-header-query - '((t :inherit font-lock-function-name-face)) - "Face used for the video published date." - :group 'yeetube-buffer-faces) - -(defface yeetube-buffer-face-duration - '((t :inherit font-lock-string-face)) - "Face used for the video duration." - :group 'yeetube-buffer-faces) - -(defface yeetube-buffer-face-view-count - '((t :inherit font-lock-keyword-face)) - "Face used for the video view count." - :group 'yeetube-buffer-faces) - -(defface yeetube-buffer-face-title - '((t :inherit font-lock-variable-use-face)) - "Face used for video title." - :group 'yeetube-buffer-faces) - -(defface yeetube-buffer-face-channel - '((t :inherit font-lock-function-call-face)) - "Face used for video channel name." - :group 'yeetube-buffer-faces) - -(defun yeetube-buffer-strip-emojis (str) - "Remove characters which are part of the `emoji' script from STR." - (cl-remove-if (lambda (c) - (equal (aref char-script-table c) 'emoji)) - str)) - -(defun yeetube-buffer-fix-view-count (view-count) - "Fix VIEW-COUNT display issues." - (replace-regexp-in-string "[^0-9]" "" view-count)) - -(defun yeetube-buffer-view-count-add-commas (string) - "Add commas for STRING." - (let ((result "") - (len (length string))) - (dotimes (i len) - (setf result (concat (substring string (- len i 1) (- len i)) result)) - (when (and (> (- len (1+ i)) 0) - (= (% (1+ i) 3) 0)) - (setf result (concat "," result)))) - result)) - -;;; Formatting inspired from ytel -(defun yeetube-buffer--format-header-title (query) - "Format header for QUERY." - (let* ((n (string-width query)) - (extra-chars (- n 53)) - (formatted-string - (if (<= extra-chars 0) - (concat query - (make-string (abs extra-chars) ?\ ) - " ") - (concat (seq-subseq query 0 50) - "... " )))) - (propertize formatted-string 'face 'yeetube-buffer-face-header-query))) - -(defun yeetube-buffer--format-title (title) - "Format a video TITLE to be inserted in the *yeetube* buffer." - (let* ((n (string-width title)) - (extra-chars (- n 60)) - (formatted-string - (if (<= extra-chars 0) - (concat title - (make-string (abs extra-chars) ?\ ) - " ") - (concat (seq-subseq title 0 57) - "... " )))) - (propertize formatted-string 'face 'yeetube-buffer-face-title))) - -(defun yeetube-buffer--format-view-count (view-count) - "Format a video VIEW-COUNT to be inserted in the *yeetube* buffer." - (let* ((n (string-width view-count)) - (extra-chars (- n 13)) - (formatted-string - (if (<= extra-chars 0) - (concat view-count - (make-string (abs extra-chars) ?\ ) - " ") - (concat (seq-subseq view-count 0 10) - "...")))) - (propertize formatted-string 'face 'yeetube-buffer-face-view-count))) - -(defun yeetube-buffer--format-video-duration (video-duration) - "Format a video VIDEO-DURATION to be inserted in the *yeetube* buffer." - (let* ((n (string-width video-duration)) - (extra-chars (- n 13)) - (formatted-string (if (<= extra-chars 0) - (concat video-duration - (make-string (abs extra-chars) ?\ ) - " ") - (concat (seq-subseq video-duration 0 10) - "...")))) - (propertize formatted-string 'face 'yeetube-buffer-face-duration))) - -(defun yeetube-buffer--format-channel (channel) - "Format a video CHANNEL to be inserted in the *yeetube* buffer." - (let* ((n (string-width channel)) - (extra-chars (- n 15)) - (formatted-string - (if (<= extra-chars 0) - (concat channel - (make-string (abs extra-chars) ?\ ) - " ") - (concat (seq-subseq channel 0 11) - "... " )))) - (propertize formatted-string 'face 'yeetube-buffer-face-channel))) - -(defun yeetube-buffer--format-header (query) - "Render header for *yeetube* buffer for QUERY." - (setf header-line-format - (concat - "Search: " (yeetube-buffer--format-header-title query) - (yeetube-buffer--format-view-count "Views") - (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 (cl-getf content :title)) - (yeetube-buffer--format-view-count (yeetube-buffer-view-count-add-commas - (yeetube-buffer-fix-view-count - (cl-getf content :view-count)))) - (yeetube-buffer--format-video-duration (cl-getf content :duration)) - (yeetube-buffer--format-channel (cl-getf content :channel)) - "\n"))) - -;;;###autoload -(defun yeetube-buffer-create (query content buffer-mode) - "Create *yeetube* buffer with BUFFER-MODE for search QUERY, displaying CONTENT." - (with-current-buffer - (switch-to-buffer (get-buffer-create "*yeetube*")) - (funcall buffer-mode) - (setf buffer-read-only nil) - (erase-buffer) - (yeetube-buffer--format-header query) - (cl-loop for result in (reverse content) - do (yeetube-buffer-insert-content result)) - (delete-char -1) - (goto-char (point-min)) - (setf buffer-read-only t))) - -(provide 'yeetube-buffer) -;;; yeetube-buffer.el ends here diff --git a/yeetube.el b/yeetube.el index 7f0dc8b..b05b57e 100644 --- a/yeetube.el +++ b/yeetube.el @@ -40,8 +40,8 @@ (require 'compat) (require 'url) +(require 'tabulated-list) (require 'cl-lib) -(require 'yeetube-buffer) (require 'yeetube-mpv) (defgroup yeetube nil -- cgit v1.2.3 From cd5cd8aabd0db468a0ba60cab15584fa1401a88b Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:23:01 +0200 Subject: yeetube-get: Redo with tabulated-list-get-id --- yeetube.el | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/yeetube.el b/yeetube.el index b05b57e..23e1080 100644 --- a/yeetube.el +++ b/yeetube.el @@ -110,9 +110,7 @@ Keywords: - :channel" (unless (keywordp keyword) (error "Value `%s' is not a keyword" keyword)) - (let ((video-info - (cl-getf (nth (- (line-number-at-pos) 1) (reverse yeetube-content)) keyword))) - video-info)) + (cl-getf (tabulated-list-get-id) keyword)) (defun yeetube-get-url () "Get video url." -- cgit v1.2.3 From 7d6985302422fdc8df0562aee223d1233d8a0946 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:35:12 +0200 Subject: yeetube-search: Change buffer & start yeetube-mode --- yeetube.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yeetube.el b/yeetube.el index 23e1080..485ab50 100644 --- a/yeetube.el +++ b/yeetube.el @@ -215,8 +215,10 @@ 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-buffer-create query yeetube-content 'yeetube-mode))) + (yeetube-get-content)) + (with-current-buffer + (switch-to-buffer (get-buffer-create (concat "*yeetube*"))) + (yeetube-mode))) ;;;###autoload (defun yeetube-browse-url () -- cgit v1.2.3 From 27b94d889ea850e5c81dcbec3d7f7cbb6e8d83d4 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:36:12 +0200 Subject: yeetube-get-content: format view-count before push --- yeetube.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index 485ab50..b41d2c8 100644 --- a/yeetube.el +++ b/yeetube.el @@ -284,7 +284,7 @@ then for item." (- (search-forward ",") 2)))) (push (list :title title :videoid videoid - :view-count view-count + :view-count (format "% 10s" (replace-regexp-in-string "[^0-9]" "" view-count)) :duration video-duration :channel channel) yeetube-content)))))))))) -- cgit v1.2.3 From f7c21d066267c3994f70e335281d1a439a351e6e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:36:51 +0200 Subject: Add yeetube-propertize-vector Will be used to propertize items in tabulated-list --- yeetube.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index b41d2c8..1ec9f1d 100644 --- a/yeetube.el +++ b/yeetube.el @@ -371,8 +371,16 @@ prompt blank to keep the default name." (setf download-counter (1+ download-counter)) (yeetube-download--ytdlp url name yeetube-download-audio-format))))) -;; Yeetube Mode +(defun yeetube-propertize-vector (content &rest fields-face-pairs) + "Create a vector with each item propertized with its corresponding face. + +CONTENT is a list of strings. +FIELDS-FACE-PAIRS is a list of fields and faces." + (apply #'vector + (cl-loop for (field face) on fields-face-pairs by #'cddr + collect (propertize (cl-getf content field) 'face face)))) +;; Yeetube Mode (defvar-keymap yeetube-mode-map :doc "Keymap for yeetube commands" "RET" #'yeetube-play -- cgit v1.2.3 From 72e65b345d9aeb7ee5590acb2e97d5c60297dc11 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:37:23 +0200 Subject: Redo yeetube-mode with tabulated list --- yeetube.el | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/yeetube.el b/yeetube.el index 1ec9f1d..2314c59 100644 --- a/yeetube.el +++ b/yeetube.el @@ -397,13 +397,25 @@ FIELDS-FACE-PAIRS is a list of fields and faces." "r" #'yeetube-replay "q" #'quit-window) -(define-derived-mode yeetube-mode special-mode "Yeetube" +(define-derived-mode yeetube-mode tabulated-list-mode "Yeetube" "Yeetube mode." - :interactive t - (abbrev-mode 0) + :keymap yeetube-mode-map + (setf tabulated-list-format [("Title" 60 t) ("Views" 12 t) ("Duration" 12 t) ("Channel" 12 t)] + tabulated-list-entries + (cl-map 'list + (lambda (content) + (list content + (yeetube-propertize-vector content + :title 'yeetube-buffer-face-title + :view-count 'yeetube-buffer-face-view-count + :duration 'yeetube-buffer-face-duration + :channel 'yeetube-buffer-face-channel))) + yeetube-content) + tabulated-list-sort-key (cons "Title" nil)) (display-line-numbers-mode 0) - :lighter " yeetube-mode" - :keymap yeetube-mode-map) + (tabulated-list-init-header) + (tabulated-list-print) + (hl-line-mode)) (provide 'yeetube) ;;; yeetube.el ends here -- cgit v1.2.3 From 5a173df634c385fb87f6a4e873949ad8efb13c82 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:55:31 +0200 Subject: Remove yeetube---fix-title tabulated-lists solves previous issues --- yeetube.el | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/yeetube.el b/yeetube.el index 2314c59..d0bac18 100644 --- a/yeetube.el +++ b/yeetube.el @@ -248,16 +248,6 @@ then for item." ("\\\\" . "")) "Unicode character replacements.") -;; Usually titles from youtube get messed up, -;; This should fix some of the common issues. -(defun yeetube---fix-title (title) - "Adjust TITLE." - (mapc (lambda (replacement) - (setf title (replace-regexp-in-string (car replacement) (cdr replacement) title))) - yeetube--title-replacements) - (if yeetube-buffer-display-emojis - title - (yeetube-buffer-strip-emojis title))) (defun yeetube-get-content () "Get content from youtube." @@ -269,9 +259,8 @@ then for item." (- (search-forward ",") 2)))) (unless (member videoid (car yeetube-content)) (yeetube-get-item "title") ;; Video Title - (let ((title (yeetube---fix-title - (buffer-substring (+ (point) 3) - (- (search-forward ",\"") 5))))) + (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) -- cgit v1.2.3 From af874221aea1ef6e427a281096edbc7b2caad77e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:56:08 +0200 Subject: Add yeetube-view-count-format --- yeetube.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index d0bac18..604575f 100644 --- a/yeetube.el +++ b/yeetube.el @@ -248,6 +248,17 @@ then for item." ("\\\\" . "")) "Unicode character replacements.") +(defun yeetube-view-count-format (string) + "Add commas for STRING." + (let* ((string (replace-regexp-in-string "[^0-9]" "" string)) + (len (length string)) + (result "")) + (cl-loop for i from 0 to (1- len) + do (setf result (concat (substring string (- len i 1) (- len i)) result)) + if (and (> (- len (1+ i)) 0) + (= (% (1+ i) 3) 0)) + do (setf result (concat "," result))) + result)) (defun yeetube-get-content () "Get content from youtube." @@ -273,7 +284,7 @@ then for item." (- (search-forward ",") 2)))) (push (list :title title :videoid videoid - :view-count (format "% 10s" (replace-regexp-in-string "[^0-9]" "" view-count)) + :view-count (yeetube-view-count-format view-count) :duration video-duration :channel channel) yeetube-content)))))))))) -- cgit v1.2.3 From f348a1a155f133648946c817d45545cacd15a1c5 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:56:37 +0200 Subject: Add yeetube-faces --- yeetube.el | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/yeetube.el b/yeetube.el index 604575f..e2da3f7 100644 --- a/yeetube.el +++ b/yeetube.el @@ -73,6 +73,37 @@ Example Usage: :type 'string :group 'yeetube) +(defgroup yeetube-faces nil + "Faces used by yeetube." + :group 'yeetube + :tag "Yeetube Faces" + :prefix 'yeetube-face) + +(defface yeetube-face-header-query + '((t :inherit font-lock-function-name-face)) + "Face used for the video published date." + :group 'yeetube-faces) + +(defface yeetube-face-duration + '((t :inherit font-lock-string-face)) + "Face used for the video duration." + :group 'yeetube-faces) + +(defface yeetube-face-view-count + '((t :inherit font-lock-keyword-face)) + "Face used for the video view count." + :group 'yeetube-faces) + +(defface yeetube-face-title + '((t :inherit font-lock-variable-use-face)) + "Face used for video title." + :group 'yeetube-faces) + +(defface yeetube-face-channel + '((t :inherit font-lock-function-call-face)) + "Face used for video channel name." + :group 'yeetube-faces) + (defvar yeetube-invidious-instances '("vid.puffyan.us" "invidious.flokinet.to" @@ -406,10 +437,10 @@ FIELDS-FACE-PAIRS is a list of fields and faces." (lambda (content) (list content (yeetube-propertize-vector content - :title 'yeetube-buffer-face-title - :view-count 'yeetube-buffer-face-view-count - :duration 'yeetube-buffer-face-duration - :channel 'yeetube-buffer-face-channel))) + :title 'yeetube-face-title + :view-count 'yeetube-face-view-count + :duration 'yeetube-face-duration + :channel 'yeetube-face-channel))) yeetube-content) tabulated-list-sort-key (cons "Title" nil)) (display-line-numbers-mode 0) -- cgit v1.2.3 From 725af1e9a8abdfd5dd064f4f39d35d16f4335094 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 9 Jan 2024 20:59:29 +0200 Subject: Update yeetube-mode-map --- yeetube.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yeetube.el b/yeetube.el index e2da3f7..01100cb 100644 --- a/yeetube.el +++ b/yeetube.el @@ -418,8 +418,8 @@ FIELDS-FACE-PAIRS is a list of fields and faces." "M-RET" #'yeetube-search "b" #'yeetube-browse-url "d" #'yeetube-download-video - "D" #'yeetube-change-download-directory - "a" #'yeetube-change-download-audio-format + "D" #'yeetube-download-change-directory + "a" #'yeetube-download-change-audio-format "p" #'yeetube-mpv-toggle-pause "v" #'yeetube-mpv-toggle-video "V" #'yeetube-mpv-toggle-no-video-flag -- cgit v1.2.3