summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-07-18 16:45:35 +0300
committerThanos Apollo <[email protected]>2023-07-18 16:45:35 +0300
commita62af4686e3575d4e4171010018e85999b9006b8 (patch)
tree2f33e7e8c0cddbb451bb09611e0b91496c9a7daa
parente2e4de0213c5b67d5d6a4a52be62c72a8a02dd14 (diff)
Add duplicated adjusted for invidious
-rw-r--r--yeetube-search2.el48
1 files changed, 38 insertions, 10 deletions
diff --git a/yeetube-search2.el b/yeetube-search2.el
index e09ff3e..db57561 100644
--- a/yeetube-search2.el
+++ b/yeetube-search2.el
@@ -5,16 +5,19 @@
(defun yt-search2 (query)
"Search for QUERY."
(interactive "sYeetube Search: ")
- (with-current-buffer
- (url-retrieve-synchronously
- (concat yeetube-query-url
- "/search?q="
- (replace-regexp-in-string " " "+" query))
- t t)
- (goto-char (point-min))
- (toggle-enable-multibyte-characters)
- (yeetube--get-content-youtube)
- (yeetube--draw-buffer query yeetube--video-titles yeetube--video-ids)))
+ (let ((is-youtube? (yeetube-check-if-youtube yeetube-query-url)))
+ (with-current-buffer
+ (url-retrieve-synchronously
+ (concat yeetube-query-url
+ "/search?q="
+ (replace-regexp-in-string " " "+" query))
+ t t)
+ (goto-char (point-min))
+ (toggle-enable-multibyte-characters)
+ (if is-youtube?
+ (yeetube--get-content-youtube)
+ (yeetube--get-content-invidious))
+ (yeetube--draw-buffer query yeetube--video-titles yeetube--video-ids))))
(defun yeetube--get-content-youtube ()
@@ -42,4 +45,29 @@
(pop yeetube--video-ids)
(push title yeetube--video-titles)))))))
+(defun yeetube--get-content-invidious ()
+ (setq yeetube--video-ids nil)
+ (setq yeetube--video-titles nil)
+ (while (and (< (length yeetube--video-ids) yeetube-results-limit)
+ (search-forward "watch?v" nil t))
+ (let* ((start (point))
+ (end (search-forward ">"))
+ (videoid (buffer-substring
+ (+ start 1)
+ (- end 2))))
+ (unless (or (member videoid yeetube--video-ids)
+ (not (and (>= (length videoid) 9)
+ (<= (length videoid) 13)
+ (string-match-p "^[a-zA-Z0-9_-]*$" videoid))))
+ (push videoid yeetube--video-ids)
+ (search-forward "\"auto\">")
+ (let* ((start (point))
+ (end (search-forward ">"))
+ (title (buffer-substring
+ (+ start 0)
+ (- end 4))))
+ (if (string-match-p "vssLoggingContext" title)
+ (pop yeetube--video-ids)
+ (push title yeetube--video-titles)))))))
+
(setq yeetube-results-limit 15)