]> njoseph.me Git - nimcoon.git/blob - nimcoon.el
youtube: Use a different Invidious instance
[nimcoon.git] / nimcoon.el
1 ;;; nimcoon.el -*- lexical-binding: t; -*-
2 ;;;
3 ;;; Commentary
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
9 (defun nimcoon-play-url (url &rest args)
10 "Play given URL in NimCoon."
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
19 (defun run-nimcoon(args query)
20 "Search by QUERY and play in NimCoon."
21 (call-process "nimcoon" nil 0 nil args query))
22
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
30 ;;; Interactive functions
31 (defun nimcoon-feeling-lucky-music(query)
32 (interactive "sSearch query: ")
33 (run-nimcoon "-ml" query))
34
35 (defun nimcoon-feeling-lucky-video(query)
36 (interactive "sSearch query: ")
37 (run-nimcoon "-l" query))
38
39 (defun nimcoon-download-video(query)
40 (interactive "sSearch query: ")
41 (run-nimcoon "-dl" query))
42
43 (defun nimcoon-download-music(query)
44 (interactive "sSearch query: ")
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
53 (defun nimcoon-search-video(query)
54 "Search for a video by QUERY."
55 (interactive "sSearch query: ")
56 (nimcoon-search "-n" query))
57
58 (defun nimcoon-search-music(query)
59 "Search for a video by QUERY."
60 (interactive "sSearch query: ")
61 (nimcoon-search "-nm" query))
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)
70 (:prefix ("s" . "Search")
71 :desc "Video" "v" #'nimcoon-search-video
72 :desc "Music" "m" #'nimcoon-search-music)
73 :desc "Kill" "k" #'nimcoon-kill-background-processes
74 :desc "Video" "v" #'nimcoon-feeling-lucky-video
75 :desc "Music" "m" #'nimcoon-feeling-lucky-music))
76
77 ;;; nimcoon.el ends here