]> Sergey Matveev's repositories - feeder.git/blob - cmd/encs
Remove unnecessary filename extensions
[feeder.git] / cmd / encs
1 #!/usr/bin/env zsh
2 set -e
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=encs ; dst=$dst:a }
9 mkdir -p $dst
10 autoload url-to-filename
11 zmodload -F zsh/datetime b:strftime
12 setopt EXTENDED_GLOB
13 for new (new/*(N)) {
14     while read line ; do
15         [[ "$line" != "" ]] || break
16         cols=(${(s: :)line})
17         [[ $cols[1] = "X-Enclosure:" ]] || continue
18         url=$cols[2]
19         [[ -n "$url" ]]
20         fn=$(strftime %Y%m%d-%H%M%S)-$(url-to-filename $url)
21         ${=WGET} --user-agent=$FEEDER_USER_AGENT \
22             --output-document=$dst/$fn $url 2>&2 2>encs.log
23         print $dst/$fn
24     done < $new
25 }