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.
 
 
 

79 lignes
1.6 KiB

  1. #!/bin/bash
  2. set -f # No globbing
  3. set -C # No clobbering
  4. set -e
  5. set -o pipefail
  6. printurls=
  7. if [[ "$1" == '--urls' ]]
  8. then
  9. printurls=1
  10. shift
  11. fi
  12. dodownload=1
  13. if [[ "$1" == '--nodl' ]]
  14. then
  15. dodownload=
  16. shift
  17. fi
  18. function printurl {
  19. if [[ "${printurls}" ]]; then echo "$1"; fi
  20. }
  21. if [[ $# -ne 1 || ( ! "$1" =~ ^https://gofile\.io/d/[0-9a-zA-Z]+$ && ! "$1" =~ ^https://gofile\.io/\?c=[0-9a-zA-Z]+$ ) ]]
  22. then
  23. echo 'Usage: gofile.io-dl [--urls] [--nodl] URL' >&2
  24. exit 1
  25. fi
  26. url="$1"
  27. printurl "$url"
  28. if [[ "${url}" == *'?c='* ]]
  29. then
  30. code="${url##*=}"
  31. else
  32. code="${url##*/}"
  33. fi
  34. folderUrl="https://api.gofile.io/getFolder?folderId=${code}"
  35. printurl "${folderUrl}"
  36. curl -s --fail "${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"])' | \
  37. while read -r size md5 name link
  38. do
  39. if [[ "${name}" == *'/'* || "${link}" == *' '* || ! "${link}" =~ ^https://((srv-)?file[0-9]+|srv-store[0-9]+)\.gofile\.io/download/ ]]
  40. then
  41. echo 'Cannot download file:' >&2
  42. echo "name: ${name}" >&2
  43. echo "link: ${link}" >&2
  44. echo "size: ${size}" >&2
  45. echo "md5: ${md5}" >&2
  46. exit 1
  47. fi
  48. printurl "${link}"
  49. if [[ -z "${dodownload}" ]]
  50. then
  51. continue
  52. fi
  53. if [[ -e "./${name}" ]]
  54. then
  55. echo "./${name} already exists" >&2
  56. exit 1
  57. fi
  58. echo "Downloading ${link} to ./${name}..." >&2
  59. curl "${link}" >"./${name}"
  60. declare -i actualSize=$(stat -c %s "./${name}")
  61. if [[ ${actualSize} -ne ${size} ]]
  62. then
  63. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  64. exit 1
  65. fi
  66. md5sum -c <<<"${md5} ./${name}"
  67. done