Created
October 29, 2022 06:56
-
-
Save ksqsf/3f27388935b0c9b301aa777f0f1887c0 to your computer and use it in GitHub Desktop.
下载 Bilibili 音频
This file contains 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
(ql:quickload :dexador) ;; HTTP | |
(ql:quickload :yason) ;; JSON | |
(defun download-bilibili-audio (audio-id) | |
(let* ((headers '(("User-Agent" . "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18") | |
("Referer" . "https://bilibili.com"))) | |
(cover-json (yason:parse (dex:get (format nil "https://www.bilibili.com/audio/music-service-c/web/song/info?sid=~a" audio-id)))) | |
(cover-url (gethash "cover" (gethash "data" cover-json))) | |
(cover-data (dex:get cover-url)) | |
(audio-json (yason:parse (dex:get (format nil "https://www.bilibili.com/audio/music-service-c/web/url?sid=~a" audio-id)))) | |
(audio-url (nth 0 (gethash "cdns" (gethash "data" audio-json)))) | |
(audio-data (dex:get audio-url :headers headers))) | |
(with-open-file (file "/tmp/cover.jpg" | |
:direction :output | |
:element-type '(unsigned-byte 8) | |
:if-does-not-exist :create | |
:if-exists :supersede) | |
(write-sequence cover-data file)) | |
(with-open-file (file "/tmp/file.m4a" | |
:direction :output | |
:element-type '(unsigned-byte 8) | |
:if-does-not-exist :create | |
:if-exists :supersede) | |
(write-sequence audio-data file)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment