The little things give you away... A collection of various small helper stuff
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

86 řádky
1.8 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 && $# -ne 2 ) || ( ! "$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 [PASSWORD]' >&2
  24. exit 1
  25. fi
  26. url="$1"
  27. password="$2"
  28. printurl "$url"
  29. if [[ "${url}" == *'?c='* ]]
  30. then
  31. code="${url##*=}"
  32. else
  33. code="${url##*/}"
  34. fi
  35. folderUrl="https://api.gofile.io/getFolder?folderId=${code}"
  36. printurl "${folderUrl}"
  37. if [[ "${password}" ]]
  38. then
  39. password="$(echo -n "${password}" | sha256sum | sed 's,\s.*$,,')"
  40. folderUrl="${folderUrl}&password=${password}&cache=true"
  41. printurl "${folderUrl}"
  42. fi
  43. 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"])' | \
  44. while read -r size md5 name link
  45. do
  46. if [[ "${name}" == *'/'* || "${link}" == *' '* || ! "${link}" =~ ^https://((srv-)?file[0-9]+|srv-store[0-9]+)\.gofile\.io/download/ ]]
  47. then
  48. echo 'Cannot download file:' >&2
  49. echo "name: ${name}" >&2
  50. echo "link: ${link}" >&2
  51. echo "size: ${size}" >&2
  52. echo "md5: ${md5}" >&2
  53. exit 1
  54. fi
  55. printurl "${link}"
  56. if [[ -z "${dodownload}" ]]
  57. then
  58. continue
  59. fi
  60. if [[ -e "./${name}" ]]
  61. then
  62. echo "./${name} already exists" >&2
  63. exit 1
  64. fi
  65. echo "Downloading ${link} to ./${name}..." >&2
  66. curl "${link}" >"./${name}"
  67. declare -i actualSize=$(stat -c %s "./${name}")
  68. if [[ ${actualSize} -ne ${size} ]]
  69. then
  70. echo "Size mismatch: expected ${size}, got ${actualSize}" >&2
  71. exit 1
  72. fi
  73. md5sum -c <<<"${md5} ./${name}"
  74. done