aboutsummaryrefslogtreecommitdiffhomepage
path: root/downloader.lisp
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-10-24 16:59:27 -0500
committerColin Okay <colin@cicadas.surf>2022-10-24 16:59:27 -0500
commitc4c0a40788948667e10f850cbd2c47dd25f61367 (patch)
tree702e92b43c387bd70a441f4aafa1113787dadde6 /downloader.lisp
parent826e5c9f7420688495d1be2821324e1afccb51b4 (diff)
Modify: trackinfo
Diffstat (limited to 'downloader.lisp')
-rw-r--r--downloader.lisp53
1 files changed, 32 insertions, 21 deletions
diff --git a/downloader.lisp b/downloader.lisp
index d7f0144..246bf29 100644
--- a/downloader.lisp
+++ b/downloader.lisp
@@ -20,11 +20,17 @@
(funcall ok track)
(funcall err url)))))
-(defun info-file-with-name (dir name)
+(defun trackinfo-file (dir name)
(merge-pathnames
(format nil "~a.info.json" name)
dir))
+(defun trackmedia-file (dir)
+ (find-if
+ (lambda (path)
+ (not (string-equal "json" (pathname-type path))))
+ (uiop:directory-files dir)))
+
(defun trackinfo (path)
"Returns a trackinfo object - a list whose first member is a path to
a file and whose CDR is a PLIST of attributes to pass
@@ -34,30 +40,35 @@
(codec :|acodec|)
(artist :|artist|)
(dur :|duration|)
- (file :|_filename|)
(thumbs :|thumbnails|)
(source :|webpage_url|))
(jonathan:parse (alexandria:read-file-into-string path))
(with-plist ((url :|url|)) (first thumbs)
- (values file
- (list
- :source source
- :title title
- :album album
- :codec codec
- :artist artist
- :duration dur
- :thumb-url url)))))
+ (list
+ :source source
+ :title title
+ :album album
+ :codec codec
+ :artist artist
+ :duration dur
+ :thumb-url url))))
(defun download-media (url)
(with-temp-dir (tmpdir)
- (let* ((tmpname
- (default-name "media"))
- (trackinfo-file
- (info-file-with-name tmpdir tmpname)))
- (uiop:run-program
- (format nil "youtube-dl --write-info-json -x -o \"~a/~a.%(ext)s\" ~a"
- tmpdir tmpname url))
- (when (uiop:file-exists-p trackinfo-file)
- (multiple-value-bind (file plist) (trackinfo trackinfo-file)
- (new-track file plist))))))
+ (handler-case
+ (let* ((tmpname
+ (default-name "media"))
+ (trackinfo-file
+ (trackinfo-file tmpdir tmpname)))
+ (uiop:run-program
+ (format nil "youtube-dl --write-info-json -x -o \"~a/~a.%(ext)s\" ~a"
+ tmpdir tmpname url))
+ (when (uiop:file-exists-p trackinfo-file)
+ (let ((info
+ (trackinfo trackinfo-file)))
+ (new-track
+ (trackmedia-file tmpdir)
+ info))))
+ (error (e)
+ (format t "ERROR: ~a~%" e)
+ nil))))