Created
July 3, 2023 12:32
-
-
Save lost-rob0t/a8793d3fb83fddcf97e897f5e03d196a to your computer and use it in GitHub Desktop.
Emacs yt-dlp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; yt-dlp-music-.el --- Download music -*- lexical-binding: t; -*- | |
;; | |
;; Copyright (C) 2023 | |
;; | |
;; Author: <[email protected]> | |
;; Maintainer: <[email protected]> | |
;; Created: July 02, 2023 | |
;; Modified: July 02, 2023 | |
;; Version: 0.0.1 | |
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp | |
;; Homepage: https://github.com/lost-rob0t/yt-dlp | |
;; Package-Requires: ((emacs "24.3")) | |
;; | |
;; This file is not part of GNU Emacs. | |
;; | |
;;; Commentary: | |
;; | |
;; | |
;; | |
;;; Code: | |
(require 'async) | |
(require 's) | |
(require 'f) | |
(defcustom nsaspy/music-dir (f-expand "~/usb/Music/") | |
"path to music dir.") | |
(defcustom nsaspy/genres '("psytrance" "retrowave" "misc") | |
"Default list of music genre to use") | |
(defcustom nsaspy/music-format "mp3" | |
"Format of the music") | |
(defcustom nsaspy/music-embed-thumnail t | |
"Weather to embed the thumnail.") | |
(defun nsaspy/music-append-link (link genre) | |
"Append a LINK to the Genre links file so we dont lose it." | |
(with-temp-buffer | |
(insert (format "%s\n" link)) | |
(append-to-file (point-min) (point-max) (f-join nsaspy/music-dir (format "%s.links" genre))))) | |
(defun nsaspy/dl-song () | |
"Download a song." | |
(interactive) | |
(let* ( | |
(link (read-string "Url: " (current-kill 0))) | |
(genre (downcase (completing-read "genre: " nsaspy/genres nil nil))) | |
(output-dir (f-join nsaspy/music-dir genre)) | |
(output-string (concat output-dir "/%(title)s.%(ext)s")) | |
(format-string (shell-quote-argument output-string)) | |
(cmd (read-string "cmd: " (format "yt-dlp -x --audio-format %s --embed-thumbnail --output %s %s" | |
nsaspy/music-format format-string link)))) | |
(nsaspy/music-append-link link genre) | |
(if (not (f-dir? output-dir)) | |
(f-mkdir-full-path output-dir)) | |
(async-shell-command cmd "*yt-dlp*" "*yt-dlp*"))) | |
(provide 'yt-dlp) | |
;;; yt-dlp.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment