]>
Commit | Line | Data |
---|---|---|
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(args query) | |
46 | "Search by QUERY with the given ARGS." | |
47 | (with-output-to-temp-buffer "*NimCoon search results*" | |
48 | (call-process "nimcoon" nil "*NimCoon search results*" t args query) | |
49 | (with-current-buffer "*NimCoon search results*" | |
50 | (org-mode)))) | |
51 | ||
52 | (defun nimcoon-search-video(query) | |
53 | "Search for a video by QUERY." | |
54 | (interactive "sSearch query: ") | |
55 | (nimcoon-search "-n" query)) | |
56 | ||
57 | (defun nimcoon-search-music(query) | |
58 | "Search for a video by QUERY." | |
59 | (interactive "sSearch query: ") | |
60 | (nimcoon-search "-nm" query)) | |
61 | ||
62 | ;;; Keybindings | |
63 | (map! :leader | |
64 | ;;; <leader> N --- NimCoon | |
65 | (:prefix-map ("N" . "NimCoon") | |
66 | (:prefix ("d" . "Download") | |
67 | :desc "Video" "v" #'nimcoon-download-video | |
68 | :desc "Music" "m" #'nimcoon-download-music) | |
69 | (:prefix ("s" . "Search") | |
70 | :desc "Video" "v" #'nimcoon-search-video | |
71 | :desc "Music" "m" #'nimcoon-search-music) | |
72 | :desc "Kill" "k" #'nimcoon-kill-background-processes | |
73 | :desc "Video" "v" #'nimcoon-feeling-lucky-video | |
74 | :desc "Music" "m" #'nimcoon-feeling-lucky-music)) |