The little things give you away... A collection of various small helper stuff
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

gofile.io-dl 1.1 KiB

il y a 3 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. set -f # No globbing
  3. set -C # No clobbering
  4. if [[ $# -ne 1 || ( ! "$1" =~ ^https://gofile\.io/d/[0-9a-zA-Z]+$ && ! "$1" =~ ^https://gofile\.io/\?c=[0-9a-zA-Z]+$ ) ]]
  5. then
  6. echo 'Usage: gofile.io-dl URL' >&2
  7. exit 1
  8. fi
  9. url="$1"
  10. if [[ "${url}" == *'?c='* ]]
  11. then
  12. code="${url##*=}"
  13. else
  14. code="${url##*/}"
  15. fi
  16. 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"])' | \
  17. while read -r size name link
  18. do
  19. if [[ "${name}" == *'/'* || "${link}" == *' '* || ! "${link}" =~ ^https://srv-file[0-9]+\.gofile\.io/download/ ]]
  20. then
  21. echo 'Cannot download file:' >&2
  22. echo "name: ${name}" >&2
  23. echo "link: ${link}" >&2
  24. echo "size: ${size}" >&2
  25. exit 1
  26. fi
  27. if [[ -e "./${name}" ]]
  28. then
  29. echo "./${name} already exists" >&2
  30. exit 1
  31. fi
  32. echo "Downloading ${link} to ./${name}..." >&2
  33. curl "${link}" >"./${name}"
  34. declare -i actualSize=$(stat -c %s "./${name}")
  35. if [[ ${actualSize} -ne ${size} ]]
  36. then
  37. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  38. exit 1
  39. fi
  40. done