X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=upload.sh;h=f24a8d76b721dfcfdbbfe9b7e271047c8f6f851e;hb=refs%2Fheads%2Fmaster;hp=e698573b84d3289e18edd809af53d3a78ab0f3e3;hpb=eaa8b25194f1c98e481cf999d6926fe2c249d29f;p=rawnet diff --git a/upload.sh b/upload.sh index e698573..f24a8d7 100755 --- a/upload.sh +++ b/upload.sh @@ -35,23 +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 - while [ ! -f "$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4" \ - -a ! -f "$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4.upload" ]; do sleep 1; done - read size <"$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4.upload" - while [ -f "$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4.upload" ]; do - stat="$(stat -c %s "$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4" 2>&-)" - printf '
%iMB / %iMB
\n' \ - "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))" + 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>&-)" + HTTP_CHUNK "
" \ + "
$((stat / 1048576))MB / $((size / 1048576))MB
" "$BR" sleep 1 done - printf '
Ready!
\n' - printf '' + HTTP_CHUNK '
Ready!
' "$BR" \ + '' + HTTP_CHUNK '' }