Xah Talk Show 2024-07-07 Ep560, Emacs Lisp Coding, Get Youtube Video Thumbnail

xts 2024-07-07 2g85
xts 2024-07-07 Qb5W
xts 2024-07-07 Qb5W
xts 2024-07-07 NcXD
xts 2024-07-07 NcXD
(defun grab-youtube-thumbnail ()
  "grab Youtube Thumbnail and save it in current dir.
Created: 2024-07-07
Version: 2024-07-07"
  (interactive)
  (let (xp1 xp2 xboundary xurl xid xThumbnailUrl xcmd)
    (setq xboundary (bounds-of-thing-at-point 'url))
    (setq xp1 (car xboundary))
    (setq xp2 (cdr xboundary))
    (setq xurl (buffer-substring-no-properties xp1 xp2))
    ;; https://www.youtube.com/watch?v=ID
    ;; https://www.youtube.com/embed/Z0DLy7zW_Ak
    (setq xid (xah-html--get-youtube-id xurl))
    ;; the thumbnail is this https://img.youtube.com/vi/ID/maxresdefault.jpg
    (setq xThumbnailUrl
          (concat "https://img.youtube.com/vi/"
                  xid
                  "/maxresdefault.jpg"))
    (setq xcmd (format "curl -O %s" xThumbnailUrl))
    (shell-command xcmd)
    (message "image thumbnail saved in maxresdefault.jpg")
    ;; (url-copy-file )
    ))