mpv.lisp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (in-package :stumpwm)
  2. (defvar *mpv-program* "mpv"
  3. "The name by which to invoke MPV.")
  4. (defparameter *mpv-headphones*
  5. nil
  6. "If non-nil use heaphones in MPV.")
  7. (defvar *mpv-default-arguments*
  8. '("--keep-open=no"))
  9. (defparameter *mpv-arguments*
  10. *mpv-default-arguments*)
  11. (defcommand toggle-mpv-arguments () ()
  12. (if *mpv-headphones*
  13. (progn
  14. (setf *mpv-arguments* *mpv-default-arguments*)
  15. (setf *mpv-headphones* nil))
  16. (progn
  17. (setf *mpv-arguments*
  18. `(,@*mpv-default-arguments*
  19. ,(concat "--audio-device=" *headphones*)))
  20. (setf *mpv-headphones* t))))
  21. (defcommand mpv () ()
  22. "Start or focus mpv."
  23. (let ((clipboard (get-x-selection)))
  24. (cond ((string-contains "youtube.com" clipboard)
  25. (run-shell-command (join `(,*mpv-program* ,@*mpv-arguments* ,clipboard))))
  26. (t (run-or-raise (join `(,*mpv-program* ,@*mpv-arguments*))
  27. '(:class "mpv"))))))
  28. (defcommand xclip-mpv () ()
  29. "Play video from clipboard with mpv."
  30. (let ((clipboard (get-x-selection)))
  31. (run-shell-command
  32. (join `(,*mpv-program* ,@*mpv-arguments* ,clipboard)))
  33. (message (concat "Play " clipboard))))
  34. (defcommand mpv-watch () ()
  35. "Play video from file with mpv."
  36. (run-shell-command
  37. (join `(,*mpv-program* ,@*mpv-arguments* ,(concat "$(cat " (getenv "HOME") "/watch)")))))
  38. (defcommand music-mpv () ()
  39. "Play music in MPV."
  40. (let ((window (current-window)))
  41. (if (and window (string= (window-title window) "mpv-music"))
  42. (other-in-frame-or-fother)
  43. (run-or-raise
  44. (join (list "mpv" "--keep-open=no" "--msg-level=all=no"
  45. "--no-resume-playback" "--shuffle" "--title=mpv-music"
  46. (concat "--input-unix-socket=" (getenv "HOME") "/.mpv/socket")
  47. "/srv/music/*"))
  48. '(:title "mpv-music")))))
  49. (defcommand mpv-next () ()
  50. (run-shell-command "mpvctl next"))
  51. (defcommand mpv-previous () ()
  52. (run-shell-command "mpvctl previous"))
  53. (defcommand mpv-music () ()
  54. (run-shell-command "mpv https://www.youtube.com/playlist?list=PLmjgicsUWIkvEKkLN01vm85neXAik3yU2"))
  55. (defvar *brown-noise-file*
  56. "/srv/video/Smoothed_Brown_Noise.m4a")
  57. (defcommand brown-noise () ()
  58. (run-shell-command
  59. (format nil "alacritty -e mpv --no-resume-playback ~a"
  60. *brown-noise-file*)))