daily pastebin goal
46%
SHARE
TWEET

mega-dl

a guest Feb 17th, 2018 249 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #!/bin/bash
  2. # Formats given mega links into something usable with megadl (megatools) or your web browser
  3.  
  4. function help {
  5.     script=$(basename "$0")
  6.     echo "Help:"
  7.     echo ${script}" 'link'     # download mega link"
  8.     echo ${script}" -b 'link'  # open mega link in browser"
  9.     echo ${script}" -d 'link'  # print mega link without downloading"
  10.     echo ${script}" -h         # displays the help menu"
  11. }
  12.  
  13. dl=true
  14. useTools=true
  15. case "$1" in
  16.     -h|--h|-help|--help )
  17.         help
  18.         exit 0
  19.         ;;
  20.     -d|--d|-D|--D )
  21.         link="$2"
  22.         dl=false
  23.         ;;
  24.     -b|--b|-B|--B )
  25.         link="$2"
  26.         useTools=false
  27.         ;;
  28.     -* )
  29.         echo "Invalid argument: '$1'"
  30.         help
  31.         exit 0
  32.         ;;
  33.     * ) link="$1";;
  34. esac
  35.  
  36. if [[ -z "${link}" ]]; then
  37.     echo "No links entered."
  38.     exit 0
  39. fi
  40.  
  41. link=$(echo "$link" | tr -d '\r\n[:space:]' ) # remove any newline or whitespace characters
  42. link="${link##*:}"        # extract the link from mega:   links
  43. link="${link##*/}"        # extract the link from mega.nz links
  44. link='#!'${link//'%'/'!'} # ensure special characters are present and properly formatted
  45. link=${link//'!#'/''}     # remove any extraneous characters
  46. link=${link//'!!'/'!'}    # remove any extraneous characters
  47.  
  48. link="https://mega.nz/${link}"
  49.  
  50. if [ "${dl}" = true ]; then
  51.     if [ "${useTools}" = true ]; then
  52.         if [[ -z "$(which megadl)" ]]; then
  53.             echo "'megadl' not found."
  54.             read -p "Would you like to open the link in your default browser (y/n)? " choice
  55.             case "$choice" in
  56.                 y|Y|yes|Yes ) xdg-open "${link}";;
  57.                 * ) echo "Please install megatools.";;
  58.             esac
  59.         else
  60.             megadl "${link}"
  61.         fi
  62.     else
  63.         xdg-open "${link}"
  64.     fi
  65. else
  66.     echo "${link}"
  67. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top