-
Notifications
You must be signed in to change notification settings - Fork 0
/
tumblr_download
executable file
·49 lines (40 loc) · 974 Bytes
/
tumblr_download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
cd ~/play/tumblr
true && for (( j = 0; j < 100; j = j + 50 )) ; do
while curl "http://bobbyatto.tumblr.com/api/read?start=$j&num=50" > t && \
fgrep -q 'Our servers are over capacity' t
do
echo "Tumblr overload; try later" >&2
sleep 1h
done
num=$(xmllint --xpath 'count(//tumblr/posts/post/photo-url)' t)
for ((i=1;i<=num;i++)) ; do
xmllint --xpath "(//tumblr/posts/post/photo-url)[$i]/text()" t
printf '\n'
done
done > all_urls
{
while read line ; do
declare -A size
declare -A url
x=${line##*/}
x=${x#tumblr_}
y="a" ; z=0
[[ $x = *75sq.??? ]] && continue
if [[ $x = *1_???.??? ]] ; then
z="${x##*1_}" ; z="${z%.???}"
y="${x%?1_???.???}"
else
z=10000
y=$x
fi
false && printf "%s %s %s %s\n" "$x" "$y" "$z" "$line"
[[ -z ${size[$y]} ]] && size[$y]=0
if (( ${size[$y]} < z )) ; then
size[$y]=$z
url[$y]=$line
fi
done < all_urls
printf "%s\n" "${url[@]}"
} > urls
wget -i urls -nc --wait=1