Fourth draft
This commit is contained in:
parent
165fe82177
commit
361494adc5
@ -17,10 +17,10 @@
|
||||
test-url))
|
||||
|
||||
(define (match-audio-format line)
|
||||
(string-match "([0-9]{3,}-?).*(audio only).*" line))
|
||||
(string-match "([0-9]{3,}-?).*audio only.*\\[en\\] Default\\, (high|low).*" line))
|
||||
|
||||
(define (match-video-format line)
|
||||
(string-match "([0-9]{3,}).*([0-9]{3,}x[0-9]{3,}).*(video only).*" line))
|
||||
(string-match "([0-9]{3,}).* ([0-9]{3,}x[0-9]{3,}).*([0-9]{2,}) \\|.* ([0-9]{1,}k).*(video only).*" line))
|
||||
|
||||
(define yt-dlp-port (open-input-pipe (string-append "yt-dlp --no-warnings --list-formats " read-url)))
|
||||
|
||||
@ -31,15 +31,35 @@
|
||||
|
||||
(define (lines-to-values port)
|
||||
|
||||
(let* ((this-line (get-line port)))
|
||||
(define (iterate line out-list)
|
||||
(let ((this-line (get-line port)))
|
||||
|
||||
(if (eof-object? this-line)
|
||||
(values (reverse out-list))
|
||||
(let ((video-match (match-video-format this-line))
|
||||
(audio-match (match-audio-format this-line)))
|
||||
|
||||
(cond
|
||||
(video-match
|
||||
(let ((video-code (match:substring video-match 1))
|
||||
(video-resolution (match:substring video-match 2))
|
||||
(video-framerate (match:substring video-match 3))
|
||||
(video-bitrate (match:substring video-match 4))
|
||||
(video-moreinfo (match:substring video-match 5)))
|
||||
|
||||
(iterate this-line (acons video-code (string-append
|
||||
video-resolution ","
|
||||
video-framerate ","
|
||||
video-bitrate) out-list))))
|
||||
(audio-match
|
||||
(let ((audio-code (match:substring audio-match 1))
|
||||
(audio-quality (match:substring audio-match 2)))
|
||||
|
||||
(iterate this-line (acons audio-code audio-quality out-list))))
|
||||
(else
|
||||
(iterate this-line out-list)))))))
|
||||
(iterate get-line '()))
|
||||
|
||||
(if (not (eof-object? this-line))
|
||||
(let ((video-match (match-video-format this-line))
|
||||
(audio-match (match-audio-format this-line)))
|
||||
(begin
|
||||
(and audio-match (format #t "~a\n" audio-match))
|
||||
(and video-match (format #t "~a\n" video-match))
|
||||
(lines-to-values yt-dlp-port))))))
|
||||
;; Main
|
||||
(lines-to-values yt-dlp-port)
|
||||
(display (lines-to-values yt-dlp-port))
|
||||
(close-port yt-dlp-port)
|
||||
|
Loading…
Reference in New Issue
Block a user