Some code that I use when adding stuff to this repository.
youtube-dl <url> --write-thumbnail --skip-download
(let ((default-directory (expand-file-name "static/thumb/")))
(dolist-with-progress-reporter (file (directory-files
(f-join (projectile-project-root)
"content" "covers")
:full "\\.org$"))
"Downloading thumbnails from YouTube..."
;; `k/with-file' abstracts away the boilerplate around opening a file in Emacs
(k/with-file file nil
(when-let (youtube-id (cadar (org-collect-keywords '("youtube"))))
(unless (f-exists? (concat youtube-id ".jpg"))
(shell-command-to-string
(format "youtube-dl '%s' --write-thumbnail --skip-download -o '%s'"
youtube-id youtube-id)))))))
cd ./static/thumb/ || exit 1
# parallel magick '{}' -resize 640 '{.}'.jpg ::: *.jpg *.webp
parallel magick '{}' -resize 640 '{.}'.jpg ::: *.webp
rm *.webp
(defun kisaragi-hiu.com/download-thumbnail (id)
(let ((youtube-id id)
(default-directory (expand-file-name "static/thumb/")))
(unless (f-exists? (concat youtube-id ".jpg"))
(shell-command-to-string
(format "yt-dlp '%1$s' --write-thumbnail --skip-download -o '%1$s'"
youtube-id))
(shell-command-to-string
(format "magick '%s' -resize 640 '%s.jpg'"
(-first #'f-exists? (list (concat youtube-id ".jpg")
(concat youtube-id ".webp")))
youtube-id)))))
(when (and call (> call 0))
(kisaragi-hiu.com/download-thumbnail (read-string "YouTube ID: ")))
- Create entry in
content/illust/yyyy-mm-dd.org
- Copy file to
static/illust/yyyy-mm-dd.jpg
- If it’s a png, copy it to
static/illust/yyyy-mm-dd.png
then runmake jpg
- If it’s a png, copy it to
- Run
make thumb
instatic/illust
<<ytdlthumb(call=0)>>
(require 's)
(let* ((now (current-time))
(date (format-time-string "%F" now))
(date-abbr (format-time-string "%Y%m%d" now))
(title (read-string "Title: "))
(origauthor (read-string "Original author: "))
(origlink (read-string "Link to original: "))
(voice (read-string "Voicebank: "))
(yt (read-string "YouTube ID: "))
(nc (read-string "niconico ID: "))
(lang (completing-read "Language code: " '("ja" "zh_TW" "en"))))
(with-temp-file (format "content/covers/%s-%s.org" date-abbr title)
(insert
(s-lex-format "#+title: ${title}
#+created: ${date}
#+origauthor: ${origauthor}
#+original: ${origlink}
#+voice: ${voice}
#+youtube: ${yt}
#+niconico: ${nc}
#+language: ${lang}
")))
(kisaragi-hiu.com/download-thumbnail yt))