]> njoseph.me Git - nimcoon.git/blob - nimcoon.el
Allow searching from Emacs
[nimcoon.git] / nimcoon.el
1 ;;; nimcoon.el -*- lexical-binding: t; -*-
2 ;;;
3 ;;; Usage in Doom Emacs
4 ;;; Place or symlink the file into ~/.doom.d/
5 ;;; (load! "nimcoon")
6
7 ;;; Non-interactive functions to respond to URL clicks
8 (defun nimcoon-play-url (url &rest args)
9 "Play given URL in NimCoon."
10 (start-process "nimcoon" nil "nimcoon" url))
11
12 ;; Play all YouTube URLs in NimCoon
13 (setq browse-url-browser-function
14 (quote
15 (("youtu\\.?be" . nimcoon-play-url)
16 ("." . browse-url-default-browser))))
17
18 (defun run-nimcoon(args query)
19 "Search by QUERY and play in NimCoon."
20 (call-process "nimcoon" nil 0 nil args query))
21
22 ;;; Interactive functions
23 (defun nimcoon-feeling-lucky-music(query)
24 (interactive "sSearch query: ")
25 (run-nimcoon "-ml" query))
26
27 (defun nimcoon-feeling-lucky-video(query)
28 (interactive "sSearch query: ")
29 (run-nimcoon "-l" query))
30
31 (defun nimcoon-download-video(query)
32 (interactive "sSearch query: ")
33 (run-nimcoon "-dl" query))
34
35 (defun nimcoon-download-music(query)
36 (interactive "sSearch query: ")
37 (run-nimcoon "-dlm" query))
38
39 ;; Assumes only one process exists. Must capture the pid of the running NimCoon process and only kill it.
40 (defun nimcoon-kill-background-processes()
41 "Kill NimCoon process running in the background. Useful for stopping background music."
42 (interactive)
43 (shell-command "kill `pgrep nimcoon` `pgrep mpv` `pgrep vlc`"))
44
45 (defun nimcoon-search-video(query)
46 "Search for a video by QUERY."
47 (interactive "sSearch query: ")
48 (with-output-to-temp-buffer "*NimCoon search results*"
49 (call-process "nimcoon" nil "*NimCoon search results*" t "--non-interactive" query)
50 (with-current-buffer "*NimCoon search results*"
51 (org-mode))))
52
53 (defun nimcoon-search-music(query)
54 "Search for a video by QUERY."
55 (interactive "sSearch query: ")
56 (with-output-to-temp-buffer "*NimCoon search results*"
57 (call-process "nimcoon" nil "*NimCoon search results*" t "--music" "--non-interactive" query)
58 (with-current-buffer "*NimCoon search results*"
59 (org-mode))))
60
61 ;;; Keybindings
62 (map! :leader
63 ;;; <leader> N --- NimCoon
64 (:prefix-map ("N" . "NimCoon")
65 (:prefix ("d" . "Download")
66 :desc "Video" "v" #'nimcoon-download-video
67 :desc "Music" "m" #'nimcoon-download-music)
68 (:prefix ("s" . "Search")
69 :desc "Video" "v" #'nimcoon-search-video
70 :desc "Music" "m" #'nimcoon-search-music)
71 :desc "Kill" "k" #'nimcoon-kill-process
72 :desc "Video" "v" #'nimcoon-feeling-lucky-video
73 :desc "Music" "m" #'nimcoon-feeling-lucky-music))