summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-07-05 09:44:35 +0300
committerThanos Apollo <[email protected]>2023-07-05 18:13:59 +0300
commit7c401b0fe0ef866f9f42515065aeeb6106764d58 (patch)
tree37cafac8476722d68484ef00775ea16dd93e044c
parentb77f86a6da150a1617ea1ee4e7990fdf1440cbf3 (diff)
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.
-rw-r--r--yeetube.el36
1 files changed, 29 insertions, 7 deletions
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)))))))