summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yeetube.el45
1 files changed, 25 insertions, 20 deletions
diff --git a/yeetube.el b/yeetube.el
index 5596590..9cbdfec 100644
--- a/yeetube.el
+++ b/yeetube.el
@@ -274,37 +274,42 @@ It's recommended you keep it as the default value."
(goto-char (point-min))
(toggle-enable-multibyte-characters)
(if is-youtube?
- (yeetube--get-content-youtube)
- (yeetube--get-content-invidious))
- (yeetube-create-buffer query yeetube--video-titles yeetube--video-ids))))
+ (yeetube-get-content-youtube)
+ (yeetube-get-content-invidious))
+ (yeetube-create-buffer query yeetube-content))))
-(defun yeetube--get-content-youtube ()
+(defun yeetube-get-content-youtube ()
"Get content from youtube."
- (setq yeetube--video-ids nil)
- (setq yeetube--video-titles nil)
- (while (and (< (length yeetube--video-ids) yeetube-results-limit)
+ (setq yeetube-content nil)
+ ;; we define these temp lists to keep tract of video-ids and
+ ;; video-titles, ensuring we push only unique ones to
+ ;; yeetube-content
+ (let ((video-ids nil)
+ (video-titles nil))
+ (while (and (< (length video-ids) yeetube-results-limit)
(search-forward "videoId" nil t))
- (let* ((start (point))
- (end (search-forward ","))
+ (let* ((videoid-start (point))
+ (videoid-end (search-forward ","))
(videoid (buffer-substring
- (+ start 3)
- (- end 2))))
- (unless (or (member videoid yeetube--video-ids)
+ (+ videoid-start 3)
+ (- videoid-end 2))))
+ (unless (or (member videoid video-ids)
(not (and (>= (length videoid) 9)
(<= (length videoid) 13)
(string-match-p "^[a-zA-Z0-9_-]*$" videoid))))
- (push videoid yeetube--video-ids)
+ (push videoid video-ids)
(search-forward "text")
- (let* ((start (point))
- (end (search-forward ",\""))
+ (let* ((title-start (point))
+ (title-end (search-forward ",\""))
(title (buffer-substring
- (+ start 3)
- (- end 5))))
+ (+ title-start 3)
+ (- title-end 5))))
(if (string-match-p "vssLoggingContext" title)
- (pop yeetube--video-ids)
- (push title yeetube--video-titles)))))))
+ (pop video-ids)
+ (push title video-titles)
+ (push (cons videoid title) yeetube-content))))))))
-(defun yeetube--get-content-invidious ()
+(defun yeetube-get-content-invidious ()
"Get content from an invidious instance."
(setq yeetube--video-ids nil)
(setq yeetube--video-titles nil)