]> Sergey Matveev's repositories - feeder.git/blob - cmd/download-encs.zsh
Sortable date in filenames
[feeder.git] / cmd / download-encs.zsh
1 #!/usr/bin/env zsh
2 set -e
3 fpath=($0:h:a/functions.zsh $fpath)
4 dst=$2:a
5 cd $1
6 [[ -n "$dst" ]] || { dst=encs ; dst=$dst:a }
7 mkdir -p $dst
8 autoload url-to-filename
9 zmodload -F zsh/datetime b:strftime
10 setopt EXTENDED_GLOB
11 for new (new/*(N)) {
12     while read line ; do
13         [[ "$line" != "" ]] || break
14         cols=(${(s: :)line})
15         [[ $cols[1] = "X-Enclosure:" ]] || continue
16         url=$cols[2]
17         [[ -n "$url" ]]
18         fn=$(strftime %Y%m%d-%H%M%S)-$(url-to-filename $url)
19         wget --output-document=$dst/$fn $url 2>&2 2>enc.log
20         print $dst/$fn
21     done < $new
22 }