-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-links.sh
executable file
·35 lines (33 loc) · 1.21 KB
/
image-links.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /bin/sh
cd "$(dirname "$0")"
./thoughtful-theridion.bin --non-interactive --eval "
(let*
((buffer (make-array ${2:-(expt 10 7)} :element-type (quote (unsigned-byte 8))))
(fetcher (make-instance 'thoughtful-theridion:http-fetcher))
(n (read-sequence buffer *standard-input*))
(buffer (subseq buffer 0 n)))
(setf (thoughtful-theridion:current-content-bytes fetcher) buffer
(thoughtful-theridion:current-headers fetcher) (quote ((:content-type . \"text/html\")))
(thoughtful-theridion:current-url fetcher) \"$1\"
(thoughtful-theridion:current-status-code fetcher) 200
(thoughtful-theridion::decode-bytes-policy fetcher)
(lambda (&key content)
(thoughtful-theridion::decode-guessed-encoding
:content (map '(vector (unsigned-byte 8)) 'identity content)
:content-type \"text/html\"))
)
(thoughtful-theridion:parse-obtained-content fetcher)
(loop
with ht := (make-hash-table :test 'equal)
for el in
(css-selectors:query
\"img\"
(thoughtful-theridion:parsed-content fetcher))
for src :=
(html5-parser:element-attribute el \"src\")
when (and src (not (gethash src ht)))
do
(progn
(format t \"~a~%\" src)
(setf (gethash src ht) t))
))"