executable_youtube-dl-json 896 B

123456789101112131415161718192021222324252627282930
  1. #!/run/current-system/profile/bin/guile \
  2. --no-auto-compile -e main -s
  3. !#
  4. (use-modules (srfi srfi-1)
  5. (ice-9 popen)
  6. (ice-9 rdelim))
  7. (define (system->string . args)
  8. (let* ((port (apply open-pipe* OPEN_READ args))
  9. (output (read-string port)))
  10. (close-pipe port)
  11. output))
  12. (define (main args)
  13. (define youtube-channel
  14. (string-join (take (string-split (second args) #\/) 5) "/"))
  15. (define youtube-channel-json
  16. (string-append (string-downcase (last (string-split youtube-channel #\/)))
  17. ".json"))
  18. (display youtube-channel)
  19. (newline)
  20. (and=> (getenv "HOME")
  21. (lambda (home)
  22. (with-output-to-file (string-append home "/Videos/youtube-dl-json/" youtube-channel-json)
  23. (lambda ()
  24. (display (system->string "youtube-dl" "--dump-single-json" "--ignore-errors" youtube-channel)))))))