From 7e92b09827ccefdea68ab594f02c7a614b0113df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 21 Oct 2021 17:40:24 +0200 Subject: [PATCH] change upload names to allow for transcoding --- db_video.sh | 5 ++-- index.cgi | 2 +- page_channel.sh | 30 +++++++++++------------ page_video.sh | 63 ++++++++++++++++++++++++++++++++----------------- upload.sh | 10 ++++---- 5 files changed, 65 insertions(+), 45 deletions(-) diff --git a/db_video.sh b/db_video.sh index 86163a2..e2cc09d 100755 --- a/db_video.sh +++ b/db_video.sh @@ -52,8 +52,8 @@ update_video(){ local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \ DESCR_CACHE FUTUREUSE local arg video thumb cnt - video="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.mp4" - thumb="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}_thumb.jpg" + video="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.upload.mp4" + thumb="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.thumb.jpg" for arg in "$@"; do case $arg in name=*) name="${arg#*=}";; @@ -135,7 +135,6 @@ delete_video() { if LOCK "$vid_db"; then grep -v "^${video} " <"$vid_db" >"${vid_db}.$$" mv -- "${vid_db}.$$" "$vid_db" - rm -- "${_DATA}/${CHANNEL_ID}/${video}.mp4" "${_DATA}/${CHANNEL_ID}/${video}_thumb.jpg" RELEASE "$vid_db" else return 1 diff --git a/index.cgi b/index.cgi index 2dec18f..0d3c668 100755 --- a/index.cgi +++ b/index.cgi @@ -125,7 +125,7 @@ case ${PATH_INFO} in $(w_user_invite) EOF ;; - /video/*/*.mp4|/video/*/*_thumb.jpg) + /video/*/*.mp4|/video/*/*.webm|/video/*/*.jpg) . "${_EXEC}/cgilite/file.sh" FILE "${_DATA}/${PATH_INFO#/video/}" ;; diff --git a/page_channel.sh b/page_channel.sh index a1e0161..89720d2 100755 --- a/page_channel.sh +++ b/page_channel.sh @@ -37,7 +37,7 @@ AUTHOR(){ if [ ! "$USER_ID" ]; then REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOTALLOWED" elif new_channel "$channel"; then - REDIRECT "${_BASE}/channel/${channel}/edit" + REDIRECT "${_BASE}/channel/$channel/edit" else REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOLOCK" fi @@ -46,38 +46,38 @@ AUTHOR(){ if [ ! "$channel" ]; then REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL" elif [ ! "$USER_ID" ]; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN" elif ! AUTHOR; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED" elif update_channel "$channel" "name=$(POST name)" \ "description=$(POST description)" \ "authors=$USER_ID"; then - REDIRECT "${_BASE}/channel/${channel}/" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/" else - REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOLOCK" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOLOCK" fi ;; update_channel_cancel) - REDIRECT "${_BASE}/channel/${channel}/" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/" ;; newvideo) video="$(POST video |checkid)" AUTHOR \ - && mkdir -p -- "${_DATA}/${channel}/" + && mkdir -p -- "${_DATA}/$CHANNEL_ID/" if [ ! "$video" ]; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_INVALID_ID" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_INVALID_ID" elif [ ! "$channel" ]; then REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL" elif [ ! "$USER_ID" ]; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN" elif ! AUTHOR; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED" elif new_video "$video"; then - REDIRECT "${_BASE}/channel/${channel}/${video}/" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/${video}/" else - REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_NOLOCK" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NEWVIDEO_NOLOCK" fi ;; esac @@ -92,7 +92,7 @@ w_video(){ VIDEO_LENGTH="${VIDEO_LENGTH%.*}" [ "${VIDEO_STATUS}" = public ] || AUTHOR || return 0 - thumb="${_BASE}/video/${CHANNEL_ID}/${VIDEO_ID}_thumb.jpg" + thumb="${_BASE}/video/${CHANNEL_ID}/${VIDEO_ID}.thumb.jpg" [ "$NAME" = \\ ] && NAME="(Unnamed Video)" printf '[div .video .thumb [a href="%s/channel/%s/%s/" @@ -144,10 +144,10 @@ w_channel_list(){ if [ "$channel" -a "$video" ]; then . ${_EXEC}/page_video.sh elif [ "$channel" -a "$action" = edit ]; then - AUTHOR || REDIRECT "${_BASE}/${channel}/#ERROR_EDIT_NOTALLOWED" + AUTHOR || REDIRECT "${_BASE}/$CHANNEL_ID/#ERROR_EDIT_NOTALLOWED" yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF [form .channel .edit method=POST - [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name"] + [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name" autocomplete=off] [textarea name="description" placeholder="Description" . $(HTML "$CHANNEL_DESCRIPTION")] [submit "action" "update_channel" . Update] [submit "action" "update_channel_cancel" . Cancel] diff --git a/page_video.sh b/page_video.sh index 28061c2..3d425e3 100755 --- a/page_video.sh +++ b/page_video.sh @@ -8,32 +8,36 @@ read_video "$video" [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in update_video) if [ ! "$USER_ID" ]; then - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOTLOGGEDIN" elif ! AUTHOR; then - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOTALLOWED" elif update_video "$video" "name=$(POST name)" \ "description=$(POST description)" \ "status=$(POST status |grep -m1 -xE 'void|private|hidden|public')" \ "uploader=$USER_ID"; then - REDIRECT "${_BASE}/channel/${channel}/${video}/#UPDATE_SUCCESS" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#UPDATE_SUCCESS" else - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOLOCK" fi ;; update_video_cancel) - REDIRECT "${_BASE}/channel/${channel}/${video}/#CANCELED" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#CANCELED" ;; delete) if [ ! "$USER_ID" ]; then - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOTLOGGEDIN" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOTLOGGEDIN" elif ! AUTHOR; then - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOTALLOWED" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOTALLOWED" elif [ "$(POST delconfirm)" != confirm ]; then - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_NOT_CONFIRMED" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOT_CONFIRMED" elif delete_video "$video"; then - REDIRECT "${_BASE}/channel/${channel}/#DELETE_CONFIRM" + rm -f -- "$_DATA/$CHANNEL_ID/$VIDEO_ID.upload.mp4" \ + "$_DATA/$CHANNEL_ID/$VIDEO_ID.mp4" \ + "$_DATA/$CHANNEL_ID/$VIDEO_ID.webm" \ + "$_DATA/$CHANNEL_ID/$VIDEO_ID.thumb.jpg" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#DELETE_CONFIRM" else - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPDATE_NOLOCK" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOLOCK" fi ;; esac @@ -41,14 +45,14 @@ esac if [ "$REQUEST_METHOD" = POST -a "$channel" -a "$video" ]; then if ! AUTHOR; then head -c "$CONTENT_LENGTH" >/dev/null - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOTALLOWED" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOTALLOWED" elif [ "$VIDEO_STATUS" != void ]; then head -c "$CONTENT_LENGTH" >/dev/null - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOCLOBBER" - elif UPLOAD "$_DATA/$channel/$video.mp4"; then + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOCLOBBER" + elif UPLOAD "$_DATA/$CHANNEL_ID/$VIDEO_ID.upload.mp4"; then update_video "$video" status=private VIDEO_STATUS=private - REDIRECT "${_BASE}/channel/${channel}/${video}/edit" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/edit" fi fi @@ -57,7 +61,7 @@ if [ "$channel" -a "$video" -a "$action" = edit ]; then yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF [form .video .edit method=POST - [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name"] + [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name" autocomplete=off] [fieldset .status $([ $VIDEO_STATUS = void ] && printf "disabled=disabled") [radio "status" "private" #status_private $(checked $VIDEO_STATUS private void)] [label for=status_private tooltip="Video is only visible to channel authors" Private] @@ -82,7 +86,7 @@ elif [ "$channel" -a "$video" -a "$action" = frameuploadprogress ]; then printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' '' frame_uploadprogress -elif [ "$channel" -a "$video" ]; then +elif [ "$channel" -a "$video" -a "$VIDEO_STATUS" = void ]; then [ $VIDEO_STATUS = public -o $VIDEO_STATUS = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; } yield_page "$VIDEO_NAME" "video" <<-EOF @@ -95,11 +99,28 @@ elif [ "$channel" -a "$video" ]; then [input type=file name=upload] [submit "action" "video_upload" Upload] ]') - $( [ $VIDEO_STATUS != void ] && printf ' - [video preload=none controls=controls width=%i height=%i - [source src="%s/video/%s/%s.mp4" type="video/mp4"] - ]' "$VIDEO_RESX" "$VIDEO_RESY" "$_BASE" "$channel" "$video" - ) + $(AUTHOR && printf '[a .button href="edit" edit]') + [h1 .name $(HTML "$VIDEO_NAME")] + [div .description . ${VIDEO_DESCR_CACHE}] + EOF + +elif [ "$channel" -a "$video" -a "$VIDEO_STATUS" != void ]; then + [ $VIDEO_STATUS = public -o $VIDEO_STATUS = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; } + + yield_page "$VIDEO_NAME" "video" <<-EOF + [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]] + [video preload=none controls=controls width="$VIDEO_RESX" height="$VIDEO_RESY" + $([ -f "${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.mp4" ] \ + && printf '[source src="%s/video/%s/%s.mp4" type="video/mp4"]' \ + "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" + [ -f "${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.webm" ] \ + && printf '[source src="%s/video/%s/%s.webm" type="video/webm"]' \ + "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" + [ ! -f "${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.mp4" \ + -a ! -f "${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.webm" ] \ + && printf '[source src="%s/video/%s/%s.upload.mp4" type="video/mp4"]\nThe video has not yet been transcoded and may not be displayed correctly.' \ + "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" + )] $(AUTHOR && printf '[a .button href="edit" edit]') [h1 .name $(HTML "$VIDEO_NAME")] [div .description . ${VIDEO_DESCR_CACHE}] diff --git a/upload.sh b/upload.sh index dd678fe..6370407 100755 --- a/upload.sh +++ b/upload.sh @@ -40,11 +40,11 @@ frame_uploadprogress() { ' "$_BASE" printf '
%i / %i
\n' 0 0 - while [ ! -f "$_DATA/$channel/$video.mp4" -a \ - ! -f "$_DATA/$channel/$video.mp4.upload" ]; do sleep 1; done - read size <"$_DATA/$channel/$video.mp4.upload" - while [ -f "$_DATA/$channel/$video.mp4.upload" ]; do - stat="$(stat -c %s "$_DATA/$channel/$video.mp4" 2>&-)" + while [ ! -f "$_DATA/$channel/$video.upload.mp4" \ + -a ! -f "$_DATA/$channel/$video.upload.mp4.upload" ]; do sleep 1; done + read size <"$_DATA/$channel/$video.upload.mp4.upload" + while [ -f "$_DATA/$channel/$video.upload.mp4.upload" ]; do + stat="$(stat -c %s "$_DATA/$channel/$video.upload.mp4" 2>&-)" printf '
%iMB / %iMB
\n' \ "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))" sleep 1 -- 2.39.2