-
-
Save vovs03/15a18e0bbe809362e61390580c358910 to your computer and use it in GitHub Desktop.
Download file from cloud.mail.ru from linux console with bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 2018-06-18 updated: mail.ru changed internals | |
# 2017-09-22 original idea: https://novall.net/itnews/bash-skript-dlya-skachivaniya-fajlov-s-mail-ru-cherez-konsol-linux.html | |
URL="$1" | |
DST_FILE="$2" | |
[ -z "$DST_FILE" ] && { | |
echo "Syntax: `basename $0` <url> <dst_file>" >&2 | |
echo "Example: `basename $0` https://cloud.mail.ru/public/BeAr/3s8QfYgLj /path/to/my/file.rar" >&2 | |
exit 1 | |
} | |
function getStorageUrl() { | |
local srcUrl="$1" | |
wget --quiet -O - "$srcUrl" | grep -A 20 '"weblink_get"' | tr -d "\n \t" | grep -o '"weblink_get":\[[^]]\+\]' | sed 's/.*"url":"\([^"]\+\)".*/\1/' | |
} | |
function getFilePath() { | |
local srcUrl="$1" | |
echo "$srcUrl" | awk -F '/public/' '{print $2}' | |
} | |
function getToken() { | |
wget --quiet -O - "https://cloud.mail.ru/api/v2/tokens/download" | sed 's/.*"token":"\([^"]\+\)".*/\1/' | |
} | |
storageUrl="`getStorageUrl "$URL"`" | |
filePath="`getFilePath "$URL"`" | |
token="`getToken`" | |
wget --no-check-certificate --referer="$URL" "$storageUrl/$filePath?key=$token" -O "$DST_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment