Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v 0.1.2 (colorify) #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ Hint: you need root permissions (`sudo` may do well).
# Usage:

```
Usage: instadl [-h] [Instagram Share URL]
Usage: instadl [-h] [Instagram Share URL] [-u UserName]
Example: instadl https://instagram.com/p/9aagaUKT7-/
Example: instadl -u UserName

Try ‘instadl -h’ for help.
```
Expand All @@ -23,6 +24,9 @@ Try ‘instadl -h’ for help.
- hamedsepehry[at]yahoo[dot]com

# CHANGELOG
- version 0.1.2
- added get all media by username.
- used better outputs (colorify).

- version 0.1.1
- added proper exit statuses.
Expand Down
75 changes: 69 additions & 6 deletions instadl
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,91 @@
version="0.1.1"
network_timeout=15
instalink=$1
username=$2
instapattern="https?://(www\.)?instagram\.com/.*"

if tput setaf 1 &> /dev/null; then
MAGENTA="\033[1;31m"
ORANGE="\033[1;33m"
GREEN="\033[1;32m"
BLUE="\033[1;34m"
PURPLE="\033[1;35m"
WHITE="\033[1;37m"
BOLD=""
RESET="\033[m"
fi

function show_err {
echo -e ${MAGENTA}${@}${RESET}
}

function show_ok {
echo -e ${GREEN}${@}${RESET}
}

function show_war {
echo -e ${ORANGE}${@}${RESET}
}

function show_msg {
echo -e ${WHITE}${@}${RESET}
}

function show_help {
echo "Instagram Downloader $version, instagram share url downloader."
show_msg "Instagram Downloader $version, instagram share url downloader."
}

function show_error {
echo "instadl: $1" >&2
show_err "instadl: $1" >&2
}

function show_usage {
echo "Usage: instadl [-h] [Instagram Share URL]"
echo "Example: instadl https://instagram.com/p/9aagaUKT7-/"
echo ""
echo "Try ‘instadl -h’ for help."
show_msg "Usage: instadl [-h] [Instagram Share URL]"
show_msg "Example: instadl https://instagram.com/p/9aagaUKT7-/"
show_msg "Example: instadl -u username"
show_msg ""
show_msg "Try ‘instadl -h’ for help."
}

function download_all {
show_msg "Fetch User data for $username"
show_msg "Save data in ${username} directoty"
if [[ -d "${username}" ]]
then
show_war "${username} exists, crawling."
else
mkdir "${username}"
fi
cd ${username}
mapfile -t links < <(wget -T $network_timeout --quiet -O - "https://www.instagram.com/${username}/media" | sed -e 's/standard/\n/g' | sed -e 's/_resolution": {"url": "//g'| grep -v status | sed -e 's/".*//g' -e 's/\\//g')
maxid=$(wget -T $network_timeout --quiet -O - "https://www.instagram.com/${username}/media" | sed -e 's/standard/\n/g' | grep -e "\"image\", \"id\"" | sed -e 's/.*\"image\", \"id\"\: \"//g' -e 's/\".*//g' | tail -n 1)
for i in "${links[@]}"
do
wget -T $network_timeout -nc "${i%%\?*}" > /dev/null 2>&1
show_ok "✔ ${RESET}$i"
done
until [[ "$maxid" == "" ]]
do
mapfile -t links < <(wget -T $network_timeout --quiet -O - "https://www.instagram.com/${username}/media/?max_id=${maxid}" | sed -e 's/standard/\n/g' | sed -e 's/_resolution": {"url": "//g'| grep -v status | sed -e 's/".*//g' -e 's/\\//g')
maxid=$(wget -T $network_timeout --quiet -O - "https://www.instagram.com/${username}/media/?max_id=${maxid}" | sed -e 's/standard/\n/g' | grep -e "\"image\", \"id\"" | sed -e 's/.*\"image\", \"id\"\: \"//g' -e 's/\".*//g' | tail -n 1)
for i in "${links[@]}"
do
wget -T $network_timeout -nc "${i%%\?*}" > /dev/null 2>&1
show_ok "✔ ${RESET}$i"
done
sleep 1
done
cd ..
}

if [ "$instalink" == "" ] | [ "$instalink" == "-h" ] #if there was no link
then
show_help
show_usage
exit 1
elif [[ "$instalink" == "-u" ]]
then
download_all
elif [[ ! $instalink =~ $instapattern ]] #if the link was wrong
then
show_error "invalid instagram share url."
Expand Down