summary refs log tree commit diff stats
path: root/lisp/+bongo.el
blob: da680241dca677240e31c337777d3c4db4833f3c (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
;;; +bongo.el --- customizations in bongo -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:

(defgroup +bongo nil
  "Extra customization for `bongo'."
  :group 'bongo)

(defun +bongo-notify ()
  (notifications-notify
   :title "Now Playing"
   :body (let ((bongo-field-separator "
"))
           (substring-no-properties (bongo-formatted-infoset)))
   :urgency 'low
   :transient t))

(defun +bongo-stop-all ()
  "Ensure only one bongo playlist is playing at a time.
This is intended to be :before advice to `bongo-play'."
  (mapc (lambda (b)
          (with-current-buffer b
            (when-let* ((modep (derived-mode-p
                                'bongo-playlist-mode))
                        (bongo-playlist-buffer b)
                        (playingp (bongo-playing-p)))
              (bongo-stop))))
        (buffer-list)))


;;; Bongo Radio

(defcustom +bongo-radio-stations nil
  "Stations to play using `+bongo-radio'.")

(defcustom +bongo-radio-buffer-name "*Bongo Radio*"
  "Name of the buffer that holds all bongo radio stations."
  :type 'string)

(defun +bongo-radio ()
  (interactive)
  (switch-to-buffer (or (get-buffer +bongo-radio-buffer-name)
                        (+bongo-radio-init))))

(defun +bongo-radio-init ()
  (interactive)
  (let ((bongo-playlist-buffer (get-buffer-create +bongo-radio-buffer-name))
        (bongo-confirm-flush-playlist nil))
    (with-bongo-playlist-buffer
      (bongo-playlist-mode)
      (bongo-flush-playlist :delete-all)
      (cl-loop for (name . url) in +bongo-radio-stations
               do (bongo-insert-uri url name)))
    (prog1 (switch-to-buffer bongo-playlist-buffer)
      (goto-char (point-min)))))

(provide '+bongo)
;;; +bongo.el ends here