X-Git-Url: https://git.plutz.net/?p=rawnet;a=blobdiff_plain;f=upload.sh;h=f24a8d76b721dfcfdbbfe9b7e271047c8f6f851e;hp=0571b186926ee8eb2ab0f1f7e1be4eb232fc6c7b;hb=2adea9f215c202bd7054ffdb0b379f4cf1db3fd1;hpb=16ad0cf056cc655f5ae57d2f91b9db386549cd59 diff --git a/upload.sh b/upload.sh index 0571b18..f24a8d7 100755 --- a/upload.sh +++ b/upload.sh @@ -35,24 +35,76 @@ UPLOAD(){ rm -- "${file}.upload" } +base16(){ + local num="$1" + case $num in + [0-9]) printf %i "$num";; + 10) printf a;; + 11) printf b;; + 12) printf c;; + 13) printf d;; + 14) printf e;; + 15) printf f;; + *) printf '%s%s' "$(base16 $((num / 16)))" "$(base16 $((num % 16)))" + esac +} + +HTTP_CHUNK(){ + local chunk="$*" + printf '%s\r\n%s\r\n' "$(base16 "${#chunk}")" "$chunk" +} + frame_uploadprogress() { - printf ' - - Upload Progress - - - ' "$_BASE" - printf '
%i / %i
\n' 0 0 + printf '%s: %s\r\n' "Content-Type" "text/html" "Transfer-Encoding" "chunked" + printf '\r\n' + + HTTP_CHUNK " + " " + Upload Progress + + + " " + " + HTTP_CHUNK '
0 / 0
' while [ ! -f "${VIDEO_FILE}" -a ! -f "${VIDEO_FILE}.upload" ]; do sleep 1 done read size <"${VIDEO_FILE}.upload" 2>&- while [ -f "${VIDEO_FILE}.upload" ]; do stat="$(stat -c %s "$VIDEO_FILE" 2>&-)" - printf '
%iMB / %iMB
\n' \ - "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))" + HTTP_CHUNK "
" \ + "
$((stat / 1048576))MB / $((size / 1048576))MB
" "$BR" sleep 1 done - printf '
Ready!
\n' - printf '' + HTTP_CHUNK '
Ready!
' "$BR" \ + '' + HTTP_CHUNK '' }