diff options
author | Thanos Apollo <[email protected]> | 2023-07-01 01:40:40 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2023-07-01 01:40:40 +0300 |
commit | b5fbc8e553468d2637fc4478f6a8b1a08620ed37 (patch) | |
tree | a8e572bab4f551ae718628d011a3015461b25fa9 | |
parent | 4c7585a1c57c0bd002fbe9d6d0c971dca1379b20 (diff) |
Add basic search functionality
custom yt-search-query, youtube is the default, but in hopefully in
the future it won't be youtube specific.
yt-search only searches for a single url for now, just for testing
purposes.
-rw-r--r-- | yeetube.el | 44 |
1 files changed, 37 insertions, 7 deletions
@@ -24,10 +24,15 @@ ;;; Code: - +(require 'url) (require 'org-element) +(defcustom yt-search-query "https://www.youtube.com/results?search_query=" + "Search URL." + :type 'string + :group 'youtube) + (defcustom yt-download-audio-format nil "Select download video as audio FORMAT. If nil yt-download-videos output will be the default format. @@ -49,13 +54,38 @@ Example Usage: (message "Opening %s with mpv" url)))) -;; TODO: play a video link using a video player from an org-mode read only buffer - - - - -;; TODO: Search Youtube videos play them using a video player +;; TODO Break this function into smaller ones, repeat search for unique videoIds +(defun yt-search (arg) + "Search for ARG in YouTube." + (interactive "sYoutube Search: ") + (let ((videoIds '()) + (videoTitles '())) + (with-current-buffer (url-retrieve-synchronously (concat yt-search-query arg)) + (goto-char (point-min)) + (search-forward "videoId") + (let* ((start (point)) + (end (search-forward ",")) + (videoid (buffer-substring (+ start 3) (- end 2)))) + (if (not (member videoid videoIds)) + (push videoid videoIds))) + (search-forward "text") + (let* ((start (point)) + (end (search-forward ",")) + (title (buffer-substring (+ start 3) (- end 4)))) + (if (not (member title videoTitles)) + (push title videoTitles))) + (with-current-buffer (switch-to-buffer + (get-buffer-create "*Youtube Search*")) + (setq buffer-read-only nil) + (erase-buffer) + (org-mode) + (dolist (videoId videoIds) + (dolist (videoTitle videoTitles) + (insert (format "- [[https://www.youtube.com/watch?v=%s][%s]] \n" + videoId + videoTitle)))) + (setq buffer-read-only t))))) ;; TODO: let user decide custom name and path |