v0.05 - Working code parsing, selection, and mpv playback call
This commit is contained in:
parent
9e10d6e7d8
commit
fd970ec833
@ -2,12 +2,13 @@
|
|||||||
(ice-9 rdelim)
|
(ice-9 rdelim)
|
||||||
(ice-9 regex)
|
(ice-9 regex)
|
||||||
(ice-9 textual-ports)
|
(ice-9 textual-ports)
|
||||||
|
(srfi srfi-1)
|
||||||
(os process))
|
(os process))
|
||||||
|
|
||||||
(debug-enable 'backtrace)
|
(debug-enable 'backtrace)
|
||||||
|
|
||||||
(define defaults `((preferred-video-codes . ("234" "311"))
|
(define defaults `((preferred-audio-codes . ("234" "311"))
|
||||||
(preferred-audio-codes . ("232"))))
|
(preferred-video-codes . ("232"))))
|
||||||
|
|
||||||
(define test-url "https://www.youtube.com/embed/1xVkRh7mEe0")
|
(define test-url "https://www.youtube.com/embed/1xVkRh7mEe0")
|
||||||
|
|
||||||
@ -29,13 +30,13 @@
|
|||||||
(cdr (assoc `preferred-video-codes defaults))
|
(cdr (assoc `preferred-video-codes defaults))
|
||||||
(cdr (assoc `preferred-audio-codes defaults)))
|
(cdr (assoc `preferred-audio-codes defaults)))
|
||||||
|
|
||||||
(define (lines-to-values port)
|
(define (fetch-formats port)
|
||||||
|
|
||||||
(define (iterate line out-list)
|
(define (iterate line audio-code-list video-code-list)
|
||||||
(let ((this-line (get-line port)))
|
(let ((this-line (get-line port)))
|
||||||
|
|
||||||
(if (eof-object? this-line)
|
(if (eof-object? this-line)
|
||||||
(values (reverse out-list))
|
(values (reverse (append audio-code-list video-code-list)))
|
||||||
(let ((video-match (match-video-format this-line))
|
(let ((video-match (match-video-format this-line))
|
||||||
(audio-match (match-audio-format this-line)))
|
(audio-match (match-audio-format this-line)))
|
||||||
|
|
||||||
@ -47,19 +48,48 @@
|
|||||||
(video-bitrate (match:substring video-match 4))
|
(video-bitrate (match:substring video-match 4))
|
||||||
(video-moreinfo (match:substring video-match 5)))
|
(video-moreinfo (match:substring video-match 5)))
|
||||||
|
|
||||||
(iterate this-line (acons video-code (string-append
|
(iterate this-line audio-code-list (acons video-code (string-append
|
||||||
video-resolution ","
|
video-resolution ","
|
||||||
video-framerate ","
|
video-framerate ","
|
||||||
video-bitrate) out-list))))
|
video-bitrate) video-code-list))))
|
||||||
(audio-match
|
(audio-match
|
||||||
(let ((audio-code (match:substring audio-match 1))
|
(let ((audio-code (match:substring audio-match 1))
|
||||||
(audio-quality (match:substring audio-match 2)))
|
(audio-quality (match:substring audio-match 2)))
|
||||||
|
|
||||||
(iterate this-line (acons audio-code audio-quality out-list))))
|
(iterate this-line (acons audio-code audio-quality audio-code-list) video-code-list)))
|
||||||
(else
|
(else
|
||||||
(iterate this-line out-list)))))))
|
(iterate this-line audio-code-list video-code-list)))))))
|
||||||
(iterate get-line '()))
|
(iterate get-line '() '()))
|
||||||
|
|
||||||
|
(define (select-formats formats-list)
|
||||||
|
(let* ((preferred-audio-codes (cdr (assoc `preferred-audio-codes defaults)))
|
||||||
|
(preferred-video-codes (cdr (assoc `preferred-video-codes defaults))))
|
||||||
|
|
||||||
|
(format #t "CAAR FORMATS LIST: ~a\n" (caar formats-list))
|
||||||
|
|
||||||
|
(define (preferred-video-formats this-alist return-list)
|
||||||
|
(if (not (null? this-alist))
|
||||||
|
(if (member (caar this-alist) preferred-video-codes)
|
||||||
|
(preferred-video-formats (cdr this-alist) (cons (caar this-alist) return-list))
|
||||||
|
(preferred-video-formats (cdr this-alist) return-list))
|
||||||
|
(reverse return-list)))
|
||||||
|
|
||||||
|
(define (preferred-audio-formats this-alist return-list)
|
||||||
|
(if (not (null? this-alist))
|
||||||
|
(if (member (caar this-alist) preferred-audio-codes)
|
||||||
|
(preferred-audio-formats (cdr this-alist) (cons (caar this-alist) return-list))
|
||||||
|
(preferred-audio-formats (cdr this-alist) return-list))
|
||||||
|
(reverse return-list)))
|
||||||
|
|
||||||
|
(values (cons (preferred-audio-formats formats-list `()) (preferred-video-formats formats-list `())))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; Main
|
;; Main
|
||||||
(display (lines-to-values yt-dlp-port))
|
(let* ((formats (fetch-formats yt-dlp-port))
|
||||||
|
(codes (select-formats formats))
|
||||||
|
(mpv-commandline (string-append "mpv --ytdl-format=" (caar codes) "+" (cadr codes) " " read-url)))
|
||||||
|
|
||||||
|
(system mpv-commandline))
|
||||||
|
|
||||||
(close-port yt-dlp-port)
|
(close-port yt-dlp-port)
|
||||||
|
Loading…
Reference in New Issue
Block a user