summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-07-18 16:27:13 +0300
committerThanos Apollo <[email protected]>2023-07-18 16:27:13 +0300
commite2e4de0213c5b67d5d6a4a52be62c72a8a02dd14 (patch)
treee47a5a416730917a488251e1cd80f8d28f2afaa6
parent835c235783999e3d6c74aa9141e4777bb52b6536 (diff)
Add testing file for yeetubet-search rewrite
-rw-r--r--yeetube-search2.el45
1 files changed, 45 insertions, 0 deletions
diff --git a/yeetube-search2.el b/yeetube-search2.el
new file mode 100644
index 0000000..e09ff3e
--- /dev/null
+++ b/yeetube-search2.el
@@ -0,0 +1,45 @@
+
+(defvar yeetube--video-ids '())
+(defvar yeetube--video-titles '())
+
+(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)))
+
+
+(defun yeetube--get-content-youtube ()
+ (setq yeetube--video-ids nil)
+ (setq yeetube--video-titles nil)
+ (while (and (< (length yeetube--video-ids) yeetube-results-limit)
+ (search-forward "videoId" nil t))
+ (let* ((start (point))
+ (end (search-forward ","))
+ (videoid (buffer-substring
+ (+ start 3)
+ (- 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 "text")
+ (let* ((start (point))
+ (end (search-forward ",\""))
+ (title (buffer-substring
+ (+ start 3)
+ (- end 5))))
+ (if (string-match-p "vssLoggingContext" title)
+ (pop yeetube--video-ids)
+ (push title yeetube--video-titles)))))))
+
+(setq yeetube-results-limit 15)