youtube-dl.lisp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. (in-package :stumpwm)
  2. (defun youtube-dl-output (dir)
  3. (concat dir "/" "%(title)s.%(ext)s"))
  4. (defvar *music-directory* "/srv/music")
  5. (defvar *youtube-dl-output-music*
  6. (youtube-dl-output *music-directory*))
  7. (defun youtube-dl-command (url &key (ad-hoc nil) (music nil))
  8. (message (format nil "Download ~s." url))
  9. (term-shell-command (format nil "sh -c 'TMOUT=20; ~a; notify-send \"youtube-dl finished\"; read -p \"Press Enter to close.\"'"
  10. (join `("youtube-dl"
  11. "--restrict-filenames"
  12. ,@(if music
  13. (list (format nil "--output=~s" *youtube-dl-output-music*))
  14. nil)
  15. ,@(if ad-hoc
  16. (list (format nil "--exec ~s" ad-hoc))
  17. nil)
  18. ,(format nil "~s" (if (string-contains "list=" url)
  19. (car (split-string url "&"))
  20. url)))))
  21. :title (if music "youtube-dl-music" "youtube-dl")
  22. :font '("-fa" "Monospace" "-fs" "8")))
  23. (defcommand youtube-dl () ()
  24. (youtube-dl-command (get-x-selection)))
  25. (defcommand youtube-dl-music (&optional url) ()
  26. (youtube-dl-command (or url (get-x-selection)) :music t))
  27. (defcommand youtube-dl-play () ()
  28. (youtube-dl-command (get-x-selection)
  29. :ad-hoc "mpv --no-stop-screensaver --title=youtube-dl-music --no-resume-playback {}"))
  30. (defcommand youtube-dl-music-play () ()
  31. (youtube-dl-command (get-x-selection)
  32. :music t
  33. :ad-hoc "mpv --no-stop-screensaver --title=youtube-dl-music --no-resume-playback {}"))
  34. (defcommand youtube-dl-music-play-url (url) ((:string "URL: "))
  35. (youtube-dl-command url
  36. :music t
  37. :ad-hoc "mpv --no-stop-screensaver --title=youtube-dl-music --no-resume-playback {}"))