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.
 
 
 

54 lignes
1.4 KiB

  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. server="$(curl -s "https://apiv2.gofile.io/getServer?c=${code}" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read().strip())["data"]["server"])')"
  17. if [[ "${server}" != srv-file?? ]]
  18. then
  19. echo "Unexpected server value: ${server}" >&2
  20. exit 1
  21. fi
  22. read -d '' -r size md5 name link < <(curl -s "https://${server}.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["md5"], f["name"], f["link"])')
  23. if [[ "${name}" == *'/'* || "${link}" == *' '* || "${link}" != "https://${server}.gofile.io/download/"* ]]
  24. then
  25. echo 'Cannot download file:' >&2
  26. echo "name: ${name}" >&2
  27. echo "link: ${link}" >&2
  28. echo "size: ${size}" >&2
  29. echo "md5: ${md5}" >&2
  30. exit 1
  31. fi
  32. if [[ -e "./${name}" ]]
  33. then
  34. echo "./${name} already exists" >&2
  35. exit 1
  36. fi
  37. curl "${link}" >"./${name}"
  38. declare -i actualSize=$(stat -c %s "./${name}")
  39. if [[ ${actualSize} -ne ${size} ]]
  40. then
  41. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  42. exit 1
  43. fi
  44. md5sum -c <<<"${md5} ./${name}"