From 361494adc5d72ecb966daf69ed57e555f18467f7 Mon Sep 17 00:00:00 2001 From: M00T Date: Sat, 2 Aug 2025 03:47:10 -0400 Subject: [PATCH] Fourth draft --- mpv-yt-helper.scm | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/mpv-yt-helper.scm b/mpv-yt-helper.scm index 8182734..351a309 100644 --- a/mpv-yt-helper.scm +++ b/mpv-yt-helper.scm @@ -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)