Initial commit
This commit is contained in:
commit
b765bd42b9
1 changed files with 58 additions and 0 deletions
58
rain.scm
Executable file
58
rain.scm
Executable file
|
|
@ -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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue