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