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.
 
 
 

77 lines
1.6 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. folderUrl="https://api.gofile.io/getFolder?folderId=${code}"
  33. printurl "${folderUrl}"
  34. curl -s "${folderUrl}" | python3 -c 'import json,sys; obj = json.loads(sys.stdin.read().strip())'$'\n''for f in obj["data"]["contents"].values():'$'\n'' print(f["size"], f["md5"], f["name"], f["link"])' | \
  35. while read -r size md5 name link
  36. do
  37. if [[ "${name}" == *'/'* || "${link}" == *' '* || ! "${link}" =~ ^https://((srv-)?file[0-9]+|srv-store[0-9]+)\.gofile\.io/download/ ]]
  38. then
  39. echo 'Cannot download file:' >&2
  40. echo "name: ${name}" >&2
  41. echo "link: ${link}" >&2
  42. echo "size: ${size}" >&2
  43. echo "md5: ${md5}" >&2
  44. exit 1
  45. fi
  46. printurl "${link}"
  47. if [[ -z "${dodownload}" ]]
  48. then
  49. continue
  50. fi
  51. if [[ -e "./${name}" ]]
  52. then
  53. echo "./${name} already exists" >&2
  54. exit 1
  55. fi
  56. echo "Downloading ${link} to ./${name}..." >&2
  57. curl "${link}" >"./${name}"
  58. declare -i actualSize=$(stat -c %s "./${name}")
  59. if [[ ${actualSize} -ne ${size} ]]
  60. then
  61. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  62. exit 1
  63. fi
  64. md5sum -c <<<"${md5} ./${name}"
  65. done