aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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))))