dosya_yukle2 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #!/usr/bin/env bash
  2. #
  3. # uguush - upload to uguu.se, teknik.io and 0x0.st
  4. # milisarge-milislinux
  5. ## CONFIGURATION
  6. # colors
  7. n="$(tput sgr0)"
  8. r="$(tput setaf 1)"
  9. g="$(tput setaf 2)"
  10. # screenshot utility
  11. fshot='maim --hidecursor'
  12. #fshot='scrot'
  13. sshot='maim -s --hidecursor'
  14. #sshot='scrot -s'
  15. wshot="maim -i $(xprop -root _NET_ACTIVE_WINDOW | grep -o '0x.*') --hidecursor"
  16. #wshot='scrot -s'
  17. # default delay
  18. secs='0'
  19. # image host
  20. usehost='uguu'
  21. hosts='uguu teknik 0x0 mixtape ptpb maxfile lewd'
  22. shorteners='waaai 0x0 ptpb'
  23. ## EXIT IF NO ARGUMENTS ARE FOUND
  24. if [ $# -lt 1 ]; then
  25. echo '`uguush` requires an argument. Run `uguush -h` for help.'
  26. exit 1
  27. fi
  28. ## FUNCTIONS
  29. depends() {
  30. if ! type xclip &> /dev/null; then
  31. echo >&2 "xclip... [${r}YOK${n}]"
  32. exit 1
  33. fi
  34. }
  35. usage() {
  36. cat <<-HELP
  37. uguush - upload to various file hosts
  38. Usage:
  39. $(basename "${0}") [options]
  40. Options:
  41. -d Delay the screenshot by the specified number of seconds.
  42. -f Take a fullscreen screenshot.
  43. -h Show this help message.
  44. -o Select a host to use. Can be uguu, teknik, 0x0, ptpb, maxfile, mixtape or lewd.
  45. -p <path> Custom path to save the image to. Saves the image as "%Y-%m-%d %H-%M-%S.png".
  46. -s Take a selection screenshot.
  47. -u <file> Upload a file.
  48. -x Do not notify dbus, update the log, or modify the clipboard.
  49. -w Take a screenshot of the current window.
  50. -S Select a shortener to use. Can be waaai, ptpb, or 0x0.
  51. -l <url> Upload the provided url.
  52. HELP
  53. }
  54. delay() {
  55. for (( i=secs; i > 0; --i )) ; do
  56. echo "${i}..."
  57. sleep 1
  58. done
  59. }
  60. screenshot() {
  61. if [ "${ful}" ]; then
  62. FILE="$(mktemp --suffix=.png)"
  63. ${fshot} "${FILE}"
  64. elif [ "${sel}" ]; then
  65. FILE="$(mktemp --suffix=.png)"
  66. ${sshot} "${FILE}" &> /dev/null
  67. if ! [ -s "${FILE}" ]; then
  68. $(rm "${FILE}" 2> /dev/null)
  69. exit
  70. fi
  71. elif [ "${win}" ]; then
  72. FILE="$(mktemp --suffix=.png)"
  73. ${wshot} "${FILE}"
  74. elif [ "${lnk}" ]; then
  75. if [ -f "/usr/share/mime/globs" ]; then
  76. urlext="$(curl -sf --head "${url}" | grep 'Content-Type: ' | head -1 | grep -Po '(?<=\ )[^\;]*')"
  77. urlext="$(echo "${urlext}" | sed -e "s/\\r//")"
  78. urlext="$(cat /usr/share/mime/globs | grep "${urlext}" | sort -r | head -1 | grep -Po '(?<=\.)[^\n]*')"
  79. else
  80. urlext="$(basename ${url})"
  81. urlext=${urlext#*.}
  82. fi
  83. FILE="$(mktemp --suffix=.${urlext})"
  84. $(curl -sf "${url}" > "${FILE}")
  85. fi
  86. }
  87. upload() {
  88. for (( i = 1; i <= 3; i++ )); do
  89. printf %s "Seçenek #${i}... "
  90. case "${usehost}" in
  91. teknik) upurl='https://api.teknik.io/v1/Upload' ;;
  92. 0x0) upurl='https://0x0.st/' ;;
  93. uguu) upurl='https://uguu.se/api.php?d=upload-tool' ;;
  94. ptpb) upurl='https://ptpb.pw/' ;;
  95. maxfile) upurl='https://maxfile.ro/static/upload.php' ;;
  96. mixtape) upurl='https://mixtape.moe/upload.php' ;;
  97. lewd) upurl='https://lewd.se/api.php?d=upload-tool' ;;
  98. esac
  99. case "${useshortener}" in
  100. waaai) shorturl='https://api.waa.ai/shorten' ;;
  101. 0x0) shorturl='http://0x0.st/' ;;
  102. ptpb) shorturl='https://ptpb.pw/u'
  103. esac
  104. if [ "${upurl}" = 'unsupported' ]; then
  105. echo "[${r}FAILED${n}]"
  106. echo "${usehost} doesn't support $([ "${https}" ] && echo HTTPS || echo HTTP)."
  107. exit 1
  108. else
  109. if [ "${usehost}" = 'uguu' ]; then
  110. result="$(curl -sf -F file="@${FILE}" "${upurl}")"
  111. elif [ "${usehost}" = '0x0' ]; then
  112. result="$(curl -sf -F file="@${FILE}" "${upurl}")"
  113. elif [ "${usehost}" = 'teknik' ]; then
  114. result="$(curl -sf -F file="@${FILE}" "${upurl}")"
  115. result="${result##*url\":\"}"
  116. result="${result%%\"*}"
  117. elif [ "${usehost}" = 'mixtape' ]; then
  118. result="$(curl -sf -F files[]="@${FILE}" "${upurl}")"
  119. result="$(echo "${result}" | grep -Eo '"url":"[A-Za-z0-9]+.*",' | sed 's/"url":"//;s/",//')"
  120. result="$(echo "${result//\\\//\/}")"
  121. elif [ "${usehost}" = 'ptpb' ]; then
  122. result="$(curl -sf -F c="@${FILE}" "${upurl}")"
  123. result="${result##*url: }"
  124. result="${result%%$'\n'*}"
  125. elif [ "${usehost}" = 'maxfile' ]; then
  126. result="$(curl -sf -F files[]="@${FILE}" "${upurl}")"
  127. result="$(echo "${result}" | grep -Eo '"url":"[A-Za-z0-9]+.*",' | sed 's/"url":"//;s/",//')"
  128. result="$(echo "https://d.maxfile.ro/${result}")"
  129. elif [ "${usehost}" = 'lewd' ]; then
  130. result="$(curl -sf -F file="@${FILE}" "${upurl}")"
  131. fi
  132. if [ "${useshortener}" = 'waaai' ]; then
  133. tempresult="$(curl -sf -F url="${result}" "${shorturl}")"
  134. code="${tempresult##*short_code\":\"}"
  135. code="${code%%\"*}"
  136. result="https://waa.ai/${code}"
  137. extension="${tempresult##*extension\":}"
  138. extension="${extension%%\}*}"
  139. if [ "${extension}" != "false" ]; then
  140. extension=${extension##\"}
  141. extension=${extension%%\"}
  142. result="${result}.${extension}"
  143. fi
  144. elif [ "${useshortener}" = '0x0' ]; then
  145. result="$(curl -sf -F shorten="${result}" "${shorturl}")"
  146. elif [ "${useshortener}" = 'ptpb' ]; then
  147. result="$(curl -sf -F c="${result}" "${shorturl}")"
  148. fi
  149. fi
  150. if [ "${?}" = 0 ]; then
  151. if [ ! "${nocomm}" ]; then
  152. printf %s "${result}" | xclip -selection primary
  153. printf %s "${result}" | xclip -selection clipboard
  154. echo "$(date +"%D %R") | "${FILE}" | "${result}"" >> ~/.uguush.log
  155. notify-send 'uguu~' "${result}"
  156. fi
  157. echo "[${g}TM${n}]"
  158. echo "Dosyanız yüklendi: ${result}"
  159. # if we took a screenshot, remove the temporary file
  160. if [ -z "${upl}" ]; then
  161. rm "${FILE}"
  162. fi
  163. exit
  164. else
  165. echo "[${r}IPTAL${n}]"
  166. fi
  167. done
  168. }
  169. path() {
  170. if [ "${altpath}" = "true" ]; then
  171. DATE=$(date "+%Y-%m-%d %H-%M-%S")
  172. cp ${FILE} "$path/$DATE.png"
  173. fi
  174. }
  175. ## PARSE OPTIONS
  176. while getopts :d:fho:p:su:wxS:l: opt ;do
  177. case "${opt}" in
  178. d)
  179. # set delay value
  180. secs="${OPTARG}" ;;
  181. f)
  182. # fullscreen
  183. ful='true' ;;
  184. h)
  185. # print help
  186. usage
  187. exit 0 ;;
  188. o)
  189. # set host
  190. [[ "${hosts}" =~ ${OPTARG} ]] && usehost="${OPTARG}" || exit 1 ;;
  191. s)
  192. # take shot with selection
  193. sel='true' ;;
  194. u)
  195. # change $FILE to the specified file with -u
  196. upl='true'
  197. FILE="${OPTARG}" ;;
  198. w)
  199. # take shot of current window
  200. win='true' ;;
  201. x)
  202. # do not notify dbus, update log, or modify clipboard
  203. nocomm='true' ;;
  204. S)
  205. # set shortener
  206. [[ "${shorteners}" =~ ${OPTARG} ]] && useshortener="${OPTARG}" || exit 1 ;;
  207. l)
  208. # set url to upload
  209. lnk='true'
  210. url="${OPTARG}" ;;
  211. p)
  212. # set path to save file
  213. altpath='true'
  214. path="${OPTARG}" ;;
  215. *)
  216. # print help and EXIT_FAILURE
  217. usage
  218. exit 1 ;;
  219. esac
  220. done
  221. ## EXECUTE FUNCTIONS
  222. depends
  223. delay
  224. screenshot
  225. path
  226. upload
  227. # If the program doesn't exit at the for-loop, the upload failed.
  228. echo 'File was not uploaded, did you specify a valid filename?'