-
Notifications
You must be signed in to change notification settings - Fork 0
/
instagrab.sh
executable file
·61 lines (56 loc) · 1.25 KB
/
instagrab.sh
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
#!/bin/bash
lastid=""
function geturls()
{
urls=( $(echo ${json} | jq -r ".items[].carousel_media[]?.images.standard_resolution.url, .items[].carousel_media[]?.videos.standard_resolution.url, .items[].images.standard_resolution.url, .items[].videos.standard_resolution.url") )
}
function getjson()
{
json=$(wget --quiet -O - "http://instagram.com/${1}/media?max_id=${2}")
}
function downloadmedia()
{
for url in "${urls[@]}"
do
if [[ "${url}" != "null" ]]
then
echo ${user} ${url}
wget --quiet -c ${url} &
fi
done
}
function downloadall()
{
getjson ${1} ${lastid}
geturls
downloadmedia
ifmore=$(echo ${json} | jq -r ".more_available")
if [[ -f debug ]]; then echo "${ifmore}"; fi
if [[ -f skip ]]; then ifmore="false"; fi
if [[ "${ifmore}" == "true" ]]
then
lastid=$(echo ${json} | jq -r ".items[19].id" | sed -e 's/\"//g')
if [[ -f debug ]]; then echo "${lastid}"; fi
if [[ "${lastid}" != "null" ]]
then
downloadall ${1}
fi
fi
}
while read user
do
lastid=""
if [[ -d "${user}" ]]
then
echo "${user} exists, crawling."
else
mkdir "${user}"
fi
if cd "${user}"
then
downloadall ${user}
cd ..
else
echo "Could not enter directory"
fi
done < users.txt