-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoto.pl
69 lines (51 loc) · 1.75 KB
/
foto.pl
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
search=$1
#---------------checks if ONE argument is supplied
if [ $# != 1 ]
then
echo supply ONE argument
exit 1 # Avsluttet scriptet
fi
#---------------checks to see if there are a website with that name
url="http://commons.wikimedia.org/wiki/Category"
wget -q --spider $url:$search
#---------------exits the scripts if it's not
if [ $? != 0 ]
then
echo fant ikke kategorien
exit 1 #avslutter dersom ingen funn.
fi
#---------------grabs the frontpage
wget -q $url:$search
#---------------calculates and presents the number of fotos
hits=`cat Category:$search | grep "div class=.thumb.*src=.http://upload.wikimedia.org" | wc -l`
echo "There are $hits hits for this search."
#---------------asks if the user want to proceed whith downloading the fotos
echo -n "Do you want to continue? (y/n)"
read answer;
#----------------kills script and delets the content downloaded so far of the user dont want to proceed
if [ $answer != "y" ]
then
echo "Exiting script..."
rm Category:$search*
exit 0
fi
#-------------tests if the searchs' folder have already been created
if [ `ls | grep ^$search ` ]
then
echo "The search have already been performed"
echo "Exiting..."
rm Category:$search*
exit 0
fi
#-------------strips the downloaded frontpage for the foto-urls and downloads the fotos to a directory named like the argument.
urls=`cat Category:$search | grep "div
class=.thumb.*src=.http://upload.wikimedia.org" | sed s/.*src=.http:..upload.wikimedia.org// | sed s/.jpg.*div.$// | sed s/thumb.//`
for line in $urls
do
wget -nd -P$search -A.jpg http://upload.wikimedia.org$line.jpg
done
#--------------removes the temporary frontpage and exits the script
rm Category:$search
echo "The script have downloaded the fotos"
echo "Exiting..."