From b765bd42b97aecee252612c8843d68a94cc7d601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C3=A6l=C5=8Drum=20spect=C4=81tr=C4=ABx?= Date: Fri, 21 Nov 2025 21:25:44 +0100 Subject: [PATCH] Initial commit --- rain.scm | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 rain.scm diff --git a/rain.scm b/rain.scm new file mode 100755 index 0000000..28fb8cf --- /dev/null +++ b/rain.scm @@ -0,0 +1,58 @@ +#!/bin/sh +#| -*- scheme -*- +exec csi -ss "$0" "$@" +|# + +(import (chicken io) + (chicken format) + (chicken port) + (chicken process-context) + (html-parser) + (http-client) + (matchable)) + +(define (find-comic-image index) + (call-with-current-continuation + (lambda (k) + (with-input-from-request (format #f "https://rain.thecomicseries.com/comics/~a" index) #f + (lambda () ((make-html-parser + #:start (lambda (t a s v) + (when (equal? (alist-ref 'id a) '("comicimage")) + (k (car (alist-ref 'src a)))))) #:dummy-seed)))))) + +(define (download-comic-image index) + (format (current-error-port) "* downloading comic image ~a~%" index) + (call-with-output-file (format #f "rain-~a.png" index) + (lambda (out) + (call-with-input-request (find-comic-image index) + #f + (lambda (in) + (copy-port in out)))))) + +(define (download-all indices) + (for-each download-comic-image indices)) + +(define (usage) + (format (current-error-port) "usage: ~a [OPTION ...] [INDEX ...]~%" (program-name)) + (format (current-error-port) "options:~%") + (format (current-error-port) " -h|-help display this help message~%") + (format (current-error-port) " -v|-version display version information~%")) + +(define parse-command-line + (match-lambda + (((or "-h" "-help") . _) + (usage)) + (((or "-v" "-version") . _) + (format (current-error-port) "rain.scm 1.0.0~%" (program-name))) + (() + (usage)) + (indices + (for-each (lambda (x) + (when (char=? #\- (string-ref x 0)) + (usage) + (exit 1))) + indices) + (download-all indices)))) + +(define (main args) + (parse-command-line args))