From 7c401b0fe0ef866f9f42515065aeeb6106764d58 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 5 Jul 2023 09:44:35 +0300 Subject: update yeetube-search to support invidious Use yeetube-check-if-youtube to seperate searching process. Adjust yeetube-query-url since both invidious and youtube can use URL/search?q= Everything else remains the same since they are almost identical. --- yeetube.el | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'yeetube.el') diff --git a/yeetube.el b/yeetube.el index 7ec1fa7..cc2c298 100644 --- a/yeetube.el +++ b/yeetube.el @@ -139,23 +139,45 @@ PREFIX [[URL/watch?v=VIDEOID][VIDEOTITLE ]]" (interactive "sYeetube Search: ") (let ((videoIds '()) (videoTitles '())) - (with-current-buffer (url-retrieve-synchronously (concat yeetube-query-url query) t t) + (with-current-buffer + (url-retrieve-synchronously (concat yeetube-query-url "/search?q=" query) t t) (goto-char (point-min)) (toggle-enable-multibyte-characters) (while (< (length videoIds) yeetube-results-limit) - (search-forward "videoId") + (if (yeetube-check-if-youtube yeetube-query-url) + (search-forward "videoId") + (search-forward "watch?v")) (let* ((start (point)) - (end (search-forward ",")) - (videoid (buffer-substring (+ start 3) (- end 2)))) + (end (if (yeetube-check-if-youtube yeetube-query-url) + (search-forward ",") + (search-forward ">"))) + (videoid (buffer-substring (if (yeetube-check-if-youtube yeetube-query-url) + (+ start 3) + (+ start 1)) + ;; Yeah they are the same in both cases, + ;; /but/ if we start adding more sites + ;; it will be easier to use something like pcase afterwards + (if (yeetube-check-if-youtube yeetube-query-url) + (- end 2) + (- end 2))))) (unless (or (member videoid videoIds) (not (and (>= (length videoid) 9) (<= (length videoid) 13) (string-match-p "^[a-zA-Z0-9_-]*$" videoid)))) (push videoid videoIds) - (search-forward "text") + (if (yeetube-check-if-youtube yeetube-query-url) + (search-forward "text") + (search-forward "\"auto\">")) (let* ((start (point)) - (end (search-forward ",\"")) - (title (buffer-substring (+ start 3) (- end 5)))) + (end (if (yeetube-check-if-youtube yeetube-query-url) + (search-forward ",\"") + (search-forward ">"))) + (title (buffer-substring (if (yeetube-check-if-youtube yeetube-query-url) + (+ start 3) + (+ start 0)) + (if (yeetube-check-if-youtube yeetube-query-url) + (- end 5) + (- end 4))))) (if (string-match-p "vssLoggingContext" title) (pop videoIds) (push title videoTitles))))))) -- cgit v1.2.3