Skip to content

Instantly share code, notes, and snippets.

@kerastinell
Forked from cronfy/dl-cloud-mail-ru.sh
Last active May 5, 2024 13:20
Show Gist options
  • Save kerastinell/badbd1da6a76a6c77a15661bf0f1e288 to your computer and use it in GitHub Desktop.
Save kerastinell/badbd1da6a76a6c77a15661bf0f1e288 to your computer and use it in GitHub Desktop.
Download file from cloud.mail.ru from linux console with bash script
#!/usr/bin/env bash
# IMPORTANT: mail.ru sometimes changes internals, not too much, but script must be changed.
#
# If this script does not work:
# - see forks, may be there is a fix already,
# - if not, please post patch in comments or create a working fork of this gist.
# Thank you!
# ВАЖНО. mail.ru время от времени меняет внутрянку, не очень сильно, но требуется адаптация скрипта.
# Если скрипт не работает, просьба разместить патч в комментариях или сделать работающий форк.
# 2021-05-26 updated: don't make an API call
# 2021-05-26 updated: mail.ru doesn't require token now
# 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
}
htmlPage=$(wget --quiet -O - "$URL")
cloudSettings=$(echo "$htmlPage" | sed -n "/window.cloudSettings/,/};<\/script>/p")
unset htmlPage
[[ "$cloudSettings" == *"\"not_exists\""* ]] && {
echo "Error: file does not exist" >&2
exit 1
}
function getStorageUrl() {
echo "$cloudSettings" | sed -n "/weblink_get/,/]/p" | fgrep -m 1 "url" | cut -d "\"" -f 4
}
function getFilePath() {
local srcUrl="$1"
echo "$srcUrl" | awk -F '/public/' '{print $2}'
}
storageUrl=$(getStorageUrl "$URL")
filePath=$(getFilePath "$URL")
wget --continue --no-check-certificate --referer="$URL" "$storageUrl/$filePath" -O "$DST_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment