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.
 
 
 

74 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. 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["name"], f["link"])' | \
  35. while read -r size 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. exit 1
  44. fi
  45. printurl "${link}"
  46. if [[ -z "${dodownload}" ]]
  47. then
  48. continue
  49. fi
  50. if [[ -e "./${name}" ]]
  51. then
  52. echo "./${name} already exists" >&2
  53. exit 1
  54. fi
  55. echo "Downloading ${link} to ./${name}..." >&2
  56. curl "${link}" >"./${name}"
  57. declare -i actualSize=$(stat -c %s "./${name}")
  58. if [[ ${actualSize} -ne ${size} ]]
  59. then
  60. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  61. exit 1
  62. fi
  63. done