Skip to content

Latest commit

 

History

History
96 lines (81 loc) · 3.27 KB

admin.org

File metadata and controls

96 lines (81 loc) · 3.27 KB

kisaragi-hiu.com admin scripts

Some code that I use when adding stuff to this repository.

Thumbnails

Downloading thumbnails using youtube-dl

youtube-dl <url> --write-thumbnail --skip-download

Downloading thumbnails for all cover entries with a youtube field

(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)))))))

Convert all thumbnails into the right size

cd ./static/thumb/ || exit 1

# parallel magick '{}' -resize 640 '{.}'.jpg ::: *.jpg *.webp
parallel magick '{}' -resize 640 '{.}'.jpg ::: *.webp
rm *.webp

Download one thumbnail

(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: ")))

Adding one illustration

  • 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 run make jpg
  • Run make thumb in static/illust

Adding one cover entry

<<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))