-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinsta
executable file
·53 lines (49 loc) · 1.72 KB
/
insta
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
#!/usr/bin/env bash
#########################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : macOS
# Requires : bash, GNU grep, curl, file, open
# Location : ~/bin, /usr/local/bin
# Name : insta
# Version : 1.0.0
# Date : 2019-03-21
# Purpose : Download large version(s) of Instagram photos
# Parameters : <Instagram page URL>
# Exit 0 : No script errors
# 1 : Missing parameter
# 2 : Invalid parameter
# 3 : Unable to fetch Instagram image URL(s)
#########################################################################
[ -z "$1" ] && { echo 'Usage: insta <Instagram page URL>' 2>&1; exit 1; }
PAGE=$(echo "$1" | grep -oE 'https://www\.instagram\.com/p/[^/]+/')
[ -z "$PAGE" ] && { echo 'Argument is not an Instagram page URL.' 2>&1; exit 2; }
SAVE=$(echo "$PAGE" | cut -d/ -f5)
URLS=$(curl -A 'Just another browser' -s "$PAGE?__a=1" | grep -oE '[^{]*1080[^}]*' | grep -oE 'https[^"]*' | grep -Fv 's150x150' | uniq)
N=$(echo "$URLS" | wc -l | xargs)
if (( N == 1 )); then
ARG="-o $SAVE.jpg"
elif (( N > 1 )); then
URLS=$(echo "$URLS" | xargs)
ARG=
for (( i = 1; i <= N; i++ )); do
ARG="$ARG -o ${SAVE}_$i.jpg"
done
else
echo "Couldn't fetch Instagram image URLs." 1>&2
exit 3
fi
curl -A 'Just another browser' -s $ARG $URLS
if (( N == 1 )); then
if [ -f "$SAVE.jpg" -a -r "$SAVE.jpg" ]; then
echo "Instagram image saved as: $SAVE.jpg"
FTYPE=$(file -b "$SAVE.jpg" | awk '{print $1}')
[ "$FTYPE" = "JPEG" ] && open "$SAVE.jpg"
fi
else
echo "Instagram images saved as:"
for (( i = 1; i <= N; i++ )); do
echo -e "\t${SAVE}_$i.jpg"
done
fi
exit 0