First draft
This commit is contained in:
		
							parent
							
								
									56fab642c8
								
							
						
					
					
						commit
						fc6fba70e7
					
				
							
								
								
									
										58
									
								
								mpv-yt-helper.scm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								mpv-yt-helper.scm
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
			
		||||
(import (ice-9 popen)
 | 
			
		||||
	(ice-9 rdelim)
 | 
			
		||||
	(ice-9 regex)
 | 
			
		||||
	(ice-9 textual-ports)
 | 
			
		||||
	(os process))
 | 
			
		||||
 | 
			
		||||
;;; (display "Define void port for stderr")
 | 
			
		||||
;;; (newline)
 | 
			
		||||
;;; (define void (%make-void-port "w"))
 | 
			
		||||
;;; 
 | 
			
		||||
;;; (display "Store original error port")
 | 
			
		||||
;;; (newline)
 | 
			
		||||
;;; (define original-error-port (current-error-port))
 | 
			
		||||
;;; 
 | 
			
		||||
;;; (display "Redirect stderr to /dev/null")
 | 
			
		||||
;;; (set-current-error-port void)
 | 
			
		||||
;;; (newline)
 | 
			
		||||
 | 
			
		||||
(define (parse-format-line line)
 | 
			
		||||
  (let* ((video-match (string-match "([0-9]{3,}).*([0-9]{3,}x[0-9]{3,}).*(video only).*" line))
 | 
			
		||||
         (audio-match (string-match "([0-9]{3,}-?).*(audio only).*" line)))
 | 
			
		||||
  
 | 
			
		||||
    (cond
 | 
			
		||||
      (video-match
 | 
			
		||||
        (let ((video-code (match:substring video-match 1))
 | 
			
		||||
  	      (video-resolution (match:substring video-match 2))
 | 
			
		||||
  	      (video-moreinfo (match:substring video-match 3)))
 | 
			
		||||
	    video-code))
 | 
			
		||||
 | 
			
		||||
      (audio-match
 | 
			
		||||
        (let  ((audio-code (match:substring audio-match 1))
 | 
			
		||||
  	       (audio-moreinfo (match:substring audio-match 2)))
 | 
			
		||||
          (if (string=? "234" audio-code)
 | 
			
		||||
	    audio-code))))))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
(define fetch-format-lines 
 | 
			
		||||
  (let* ((url "https://www.youtube.com/watch?v=m5RuTLhUPU4")
 | 
			
		||||
        (yt-dlp-port (open-input-pipe (string-append "yt-dlp --no-warnings --list-formats " url))))
 | 
			
		||||
        
 | 
			
		||||
    (let loop ((this-line (get-line yt-dlp-port)))
 | 
			
		||||
 | 
			
		||||
      (if (not (eof-object? this-line))
 | 
			
		||||
	(begin
 | 
			
		||||
	  (if (parse-format-line this-line)
 | 
			
		||||
	    (format #t "CODE: ~a\n" (parse-format-line this-line)))
 | 
			
		||||
	  (loop (get-line yt-dlp-port)))
 | 
			
		||||
	(format #t "EOF\n")))
 | 
			
		||||
 | 
			
		||||
    (close-pipe yt-dlp-port)))
 | 
			
		||||
 | 
			
		||||
(define defaults
 | 
			
		||||
  `((preferred-video-codes . ("234" "311"))
 | 
			
		||||
    (preferred-audio-codes . ("232"))))
 | 
			
		||||
 | 
			
		||||
;; Not working, pseudoscheme
 | 
			
		||||
(define (call-mpv video-code audio-code)
 | 
			
		||||
  (system (string-append "mpv --ytdl-format=" audio-code "+" video-code url)))
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user