]> Sergey Matveev's repositories - feeder.git/blob - cmd/warcs
Trivial style fixes
[feeder.git] / cmd / warcs
1 #!/usr/bin/env zsh
2 setopt ERR_EXIT EXTENDED_GLOB
3 cmds=$0:h:a
4 . $cmds/env.rc
5 fpath=($cmds/functions.zsh $fpath)
6 dst=$2:a
7 cd $1
8 [[ -n $dst ]] || { dst=warcs ; dst=$dst:a }
9 mkdir -p $dst
10 autoload url-to-filename
11 zmodload -F zsh/datetime b:strftime
12 wget_opts=(
13     --user-agent="$FEEDER_USER_AGENT"
14     --page-requisites
15     --compression=auto
16     --no-warc-keep-log
17     --no-warc-digests
18     --no-warc-compression
19 )
20 for new (new/*(N)) {
21     while read line ; do
22         [[ -n $line ]] || break
23         cols=(${(s: :)line})
24         [[ $cols[1] = "X-URL:" ]] || continue
25         url=$cols[2]
26         [[ -n "$url" ]]
27         [[ -n "$tmp" ]] || {
28             # Lazy temporary file creation
29             tmp=`mktemp`
30             trap "rm -f $tmp" HUP PIPE INT QUIT TERM EXIT
31             wget_opts=(--output-document=$tmp $wget_opts)
32         }
33         fn=$(strftime %Y%m%d-%H%M%S)-$(url-to-filename $url)
34         ${=WGET} $wget_opts --output-file=warcs.log --warc-file=$dst/$fn $url
35         $FEEDER_WARC_COMPRESS $dst/$fn.warc
36         print $dst/$fn.warc*
37     done < $new
38 }