The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

73 lines
1.5 KiB

  1. #!/bin/bash
  2. set -f # No globbing
  3. set -C # No clobbering
  4. printurls=
  5. if [[ "$1" == '--urls' ]]
  6. then
  7. printurls=1
  8. shift
  9. fi
  10. dodownload=1
  11. if [[ "$1" == '--nodl' ]]
  12. then
  13. dodownload=
  14. shift
  15. fi
  16. function printurl {
  17. [[ "${printurls}" ]] && echo "$1"
  18. }
  19. if [[ $# -ne 1 || ( ! "$1" =~ ^https://gofile\.io/d/[0-9a-zA-Z]+$ && ! "$1" =~ ^https://gofile\.io/\?c=[0-9a-zA-Z]+$ ) ]]
  20. then
  21. echo 'Usage: gofile.io-dl URL' >&2
  22. exit 1
  23. fi
  24. url="$1"
  25. printurl "$url"
  26. if [[ "${url}" == *'?c='* ]]
  27. then
  28. code="${url##*=}"
  29. else
  30. code="${url##*/}"
  31. fi
  32. printurl "https://apiv2.gofile.io/getUpload?c=${code}"
  33. curl -s "https://apiv2.gofile.io/getUpload?c=${code}" | python3 -c 'import json,sys; obj = json.loads(sys.stdin.read().strip())'$'\n''for f in obj["data"]["files"].values():'$'\n'' print(f["size"], f["name"], f["link"])' | \
  34. while read -r size name link
  35. do
  36. if [[ "${name}" == *'/'* || "${link}" == *' '* || ! "${link}" =~ ^https://srv-file[0-9]+\.gofile\.io/download/ ]]
  37. then
  38. echo 'Cannot download file:' >&2
  39. echo "name: ${name}" >&2
  40. echo "link: ${link}" >&2
  41. echo "size: ${size}" >&2
  42. exit 1
  43. fi
  44. printurl "${link}"
  45. if [[ -z "${dodownload}" ]]
  46. then
  47. continue
  48. fi
  49. if [[ -e "./${name}" ]]
  50. then
  51. echo "./${name} already exists" >&2
  52. exit 1
  53. fi
  54. echo "Downloading ${link} to ./${name}..." >&2
  55. curl "${link}" >"./${name}"
  56. declare -i actualSize=$(stat -c %s "./${name}")
  57. if [[ ${actualSize} -ne ${size} ]]
  58. then
  59. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  60. exit 1
  61. fi
  62. done