;; Download youtube videos or play lists.
;; - joneworlds@mailbox.org

;; Perhaps you will find this idea useful.  I made this emacs program
;; so that if I find some videos in youtube I like, I can save my own
;; copy.  When I run this, it asks for the URL of the video OR the
;; playlist I'm looking at.  And then it asks for the name the file(s)
;; should have.  And then this program goes and runs the yt-dlp
;; program to go get the video file (or files, if it's a playlist).

(defun jw-youtube-video (url name only-audio)
  (interactive "syoutube url: \nsname for file(s): \nP")
  (when (> (length url) 0)
    (let ((filename
           (if (> (length name) 0)
               (format " -o \"c:\\Users\\a7ywk\\Downloads\\%s%%(playlist_index)s.mp4\"" name)
             ""))
          (dl-type
           (format "-f %s"
                   (if only-audio 139 18))))
      (async-shell-command
       (format
        "yt-dlp %s %s \"%s\"" filename dl-type url)))))