aboutsummaryrefslogtreecommitdiff
path: root/bard-elisp/bard-media.el
blob: 22d54c924e987c928c9079ef2e2992a9e1a1ea4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(require 'cl-lib)
(require 'seq)
(require 'emms)
(require 'image-dired)
(require 'dired-x)

(defun bard/play-youtube-video ()
  "Prompt for a YouTube URL and play it in mpv."
  (interactive)
  (let ((url (read-string "Enter YouTube URL: ")))
    (if (and url (string-match-p "https?://\\(www\\.\\)?youtube\\.com\\|youtu\\.be" url))
        (async-shell-command (format "mpv '%s'" url))
      (message "The URL is not a valid YouTube link: %s" url))))

(defun bard/save-emms-watch-later ()
  "Save the current EMMS playlist to `bard/watch-later-file` using `bard/emms-playlist-format`."
  (interactive)
  (when (and bard/watch-later-file bard/emms-playlist-format)
    (emms-playlist-save bard/emms-playlist-format bard/watch-later-file)
    (message "Playlist saved to %s" bard/watch-later-file)))

;; (defun bard/image-browser (directory)
;;   "Open nsxiv in thumbnail mode on DIRECTORY.
;; Asks the user whether to enable recursive mode."
;;   (interactive "DSelect directory: ")
;;   (let ((recursive (if (y-or-n-p "Recursive searching? ") "-r" "")))
;;     (start-process "nsxiv"  "nsxiv" "-t" "-o" recursive (expand-file-name directory))))

;; (defun bard/image-browser (directory)
;;   "Open nsxiv in thumbnail mode on DIRECTORY.
;; Asks the user whether to enable recursive mode."
;;   (interactive "DSelect directory: ")
;;   (let ((recursive (if (y-or-n-p "Recursive searching? ") "-r" "")))
;;     (start-process "nsxiv" "*nsxiv*" "nsxiv" "-t" "-o" recursive (expand-file-name directory))
;;     (pop-to-buffer "*nsxiv*")))

;; (defun bard/image-browser (directory)
;;   "Open nsxiv in thumbnail mode on DIRECTORY.
;; Asks the user whether to enable recursive mode."
;;   (interactive "DSelect directory: ")
;;   (let ((recursive (if (y-or-n-p "Recursive searching? ") "-r" ""))
;;         (stdout (if (y-or-n-p "Output marked files to buffer? ") "-o" "")))
;;     (start-process "nsxiv" "*nsxiv*" "nsxiv" "-t" stdout recursive (expand-file-name directory))
;;     (if (string= stdout "-o")
;;         (progn (with-current-buffer "*nsxiv*"
;;                  (read-only-mode nil)
;;                  (erase-buffer))
;;                (pop-to-buffer "*nsxiv*")
;;                )
;;       nil)))

(defun bard/image-browser (directory)
  "Open nsxiv in thumbnail mode on DIRECTORY.
Asks the user whether to enable recursive mode."
  (interactive "DSelect directory: ")
  (let ((recursive (if (y-or-n-p "Recursive searching? ") "-r" ""))
        (stdout (if (y-or-n-p "Output marked files to buffer? ") "-o" "")))
    (let ((process (start-process "nsxiv" "*nsxiv*" "nsxiv" "-t" stdout recursive (expand-file-name directory))))
      (when (string= stdout "-o")
        (set-process-sentinel
         process
         (lambda (proc event)
           (when (string= event "finished\n")
             (with-current-buffer "*nsxiv*"
               (read-only-mode nil)
               (erase-buffer)))))
        (pop-to-buffer "*nsxiv*")))))

(provide 'bard-media.el)