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.5 KiB

il y a 3 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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[0-9]+$ ]]
  18. then
  19. echo "Unexpected server value: ${server}" >&2
  20. exit 1
  21. fi
  22. 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. while read -r size md5 name link
  24. do
  25. if [[ "${name}" == *'/'* || "${link}" == *' '* || "${link}" != "https://${server}.gofile.io/download/"* ]]
  26. then
  27. echo 'Cannot download file:' >&2
  28. echo "name: ${name}" >&2
  29. echo "link: ${link}" >&2
  30. echo "size: ${size}" >&2
  31. echo "md5: ${md5}" >&2
  32. exit 1
  33. fi
  34. if [[ -e "./${name}" ]]
  35. then
  36. echo "./${name} already exists" >&2
  37. exit 1
  38. fi
  39. echo "Downloading ${link} to ./${name}..." >&2
  40. curl "${link}" >"./${name}"
  41. declare -i actualSize=$(stat -c %s "./${name}")
  42. if [[ ${actualSize} -ne ${size} ]]
  43. then
  44. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  45. exit 1
  46. fi
  47. md5sum -c <<<"${md5} ./${name}"
  48. done