Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Formats given mega links into something usable with megadl (megatools) or your web browser
- function help {
- script=$(basename "$0")
- echo "Help:"
- echo ${script}" 'link' # download mega link"
- echo ${script}" -b 'link' # open mega link in browser"
- echo ${script}" -d 'link' # print mega link without downloading"
- echo ${script}" -h # displays the help menu"
- }
- dl=true
- useTools=true
- case "$1" in
- -h|--h|-help|--help )
- help
- exit 0
- ;;
- -d|--d|-D|--D )
- link="$2"
- dl=false
- ;;
- -b|--b|-B|--B )
- link="$2"
- useTools=false
- ;;
- -* )
- echo "Invalid argument: '$1'"
- help
- exit 0
- ;;
- * ) link="$1";;
- esac
- if [[ -z "${link}" ]]; then
- echo "No links entered."
- exit 0
- fi
- link=$(echo "$link" | tr -d '\r\n[:space:]' ) # remove any newline or whitespace characters
- link="${link##*:}" # extract the link from mega: links
- link="${link##*/}" # extract the link from mega.nz links
- link='#!'${link//'%'/'!'} # ensure special characters are present and properly formatted
- link=${link//'!#'/''} # remove any extraneous characters
- link=${link//'!!'/'!'} # remove any extraneous characters
- link="https://mega.nz/${link}"
- if [ "${dl}" = true ]; then
- if [ "${useTools}" = true ]; then
- if [[ -z "$(which megadl)" ]]; then
- echo "'megadl' not found."
- read -p "Would you like to open the link in your default browser (y/n)? " choice
- case "$choice" in
- y|Y|yes|Yes ) xdg-open "${link}";;
- * ) echo "Please install megatools.";;
- esac
- else
- megadl "${link}"
- fi
- else
- xdg-open "${link}"
- fi
- else
- echo "${link}"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement