]> njoseph.me Git - nimcoon.git/blame - nimcoon.el
Bump version and update changelog
[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
JN
9(defun nimcoon-play-url (url &rest args)
10 "Play given URL in NimCoon."
51c1ed38
JN
11 (start-process "nimcoon" nil "nimcoon" url))
12
13;; Play all YouTube URLs in NimCoon
14(setq browse-url-browser-function
15 (quote
16 (("youtu\\.?be" . nimcoon-play-url)
17 ("." . browse-url-default-browser))))
18
26229fac
JN
19(defun run-nimcoon(args query)
20 "Search by QUERY and play in NimCoon."
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."
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*"
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
47;; Assumes only one process exists. Must capture the pid of the running NimCoon process and only kill it.
48(defun nimcoon-kill-background-processes()
49 "Kill NimCoon process running in the background. Useful for stopping background music."
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
65 ;;; <leader> N --- NimCoon
66 (:prefix-map ("N" . "NimCoon")
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