X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=page_video.sh;h=3215bbb30d7a57237868eea8b617df14ab52774b;hb=2adea9f215c202bd7054ffdb0b379f4cf1db3fd1;hp=b7b9953787d44effcf2913027ab5ab0b0a3f3ff5;hpb=ba23425f0e01d62612b425c2e7b96517df1c9fde;p=rawnet diff --git a/page_video.sh b/page_video.sh old mode 100644 new mode 100755 index b7b9953..3215bbb --- a/page_video.sh +++ b/page_video.sh @@ -1,173 +1,72 @@ #!/bin/sh -# ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS (void|private|hidden|public) UPLOADER HITS DESCR_CACHE FUTUREUSE +[ "$includepage_video" ] && return 0 +includepage_video="$0" -if [ "$video" -a -f "$vid_db" -a -r "$vid_db" ]; then - read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \ - VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \ - VIDEO_DESCR_CACHE VIDEO_FUTUREUSE <<-EOF - $(grep "^${video} " "${vid_db}") - EOF - if [ "$VIDEO_ID" ]; then - VIDEO_NAME="$(UNSTRING "$VIDEO_NAME")" - VIDEO_DESCRIPTION="$(UNSTRING "$VIDEO_DESCRIPTION")" - VIDEO_COVER="$(UNSTRING "$VIDEO_COVER")" - VIDEO_DESCR_CACHE="$(UNSTRING "$VIDEO_DESCR_CACHE")" - else - video='' - fi -fi - -update_video(){ - local id="${1}" name description resx resy length cover status uploader \ - hits descr_cache futureuse - 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" - - for arg in "$@"; do case $arg in - name=*) name="${arg#*=}";; - description=*) description="${arg#*=}";; - cover=*) cover="${arg#*=}";; - status=*) status="${arg#*=}";; - uploader=*) uploader="${arg#*=}";; - hits=*) hits="${arg#*=}";; - esac; done - - if [ -f "$video" -a -r "$video" ]; then - arg="$(echo; ffprobe -show_entries format=duration:stream=width,height "$video" 2>&-)" - resx="${arg#*width=}"; resx="${resx%%${BR}*}" - resy="${arg#*height=}"; resy="${resy%%${BR}*}" - length="${arg#*duration=}"; length="${length%%${BR}*}" - fi - if [ "${length%.*}" -a ! "${thumb}" -nt "${video}" ]; then - for cnt in 1 2 3 4 5 6 7 8 9 10; do - ffmpeg -nostdin -y -ss "$((cnt * ${length%.*} / 11))" -i "$video" \ - -frames 1 "${thumb%.jpg}_$((cnt - 1)).jpg" - done 2>&- - montage "${thumb%.jpg}"_[0-9].jpg \ - -background "#000000" \ - -tile 10x1 -geometry 320x180+0+0 \ - -interlace line -quality 85 "${thumb}" - rm -- "${thumb%.jpg}"_[0-9].jpg - fi - - if LOCK "$vid_db"; then - while read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \ - DESCR_CACHE FUTUREUSE; do - if [ "$id" = "$ID" ]; then - printf '%s %s %s %i %i %f %s %s %s %i %s %s\n' \ - "$id" "$(STRING "${name-$(UNSTRING "$NAME")}")" \ - "$(STRING "${description-$(UNSTRING "$DESCRIPTION")}")" \ - "${resx:-${resx-${RESX}}${resx+0}}" \ - "${resy:-${resy-${RESY}}${resy+0}}" \ - "${length:-${length-${LENGTH}}${length+0}}" \ - "$(STRING "${cover-$(UNSTRING "$COVER")}")" \ - "${status:-${status-${STATUS}}${status+void}}" \ - "${uploader:-${uploader-${UPLOADER}}${uploader+\\}}" \ - "${hits:-${hits-${HITS}}${hits+0}}" \ - "$(printf %s "${description-$(UNSTRING "$DESCRIPTION")}" |markdown |STRING)" \ - "${FUTUREUSE:-\\}" - else - printf '%s %s %s %i %i %f %s %s %s %i %s %s\n' \ - "$ID" "$NAME" "$DESCRIPTION" "$RESX" "$RESY" "$LENGTH" \ - "$COVER" "$STATUS" "$UPLOADER" "$HITS" "$DESCR_CACHE" \ - "$FUTUREUSE" - fi - done <"$vid_db" >"${vid_db}.$$" - mv -- "${vid_db}.$$" "${vid_db}" - RELEASE "$vid_db" - else - return 1 - fi -} - -UPLOAD(){ - local file="$1" - local boundary line last - - [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1 - - boundary="${CONTENT_TYPE#*; boundary=}" - boundary="${boundary%%;*}" +. "$_EXEC/db_channel.sh" +. "$_EXEC/db_video.sh" +. "$_EXEC/upload.sh" +. "$_EXEC/transcoding.sh" - head -c "$CONTENT_LENGTH" \ - | sed -nE ' - # discard lines prior to boundary - /^--'"${boundary}"'\r?$/!b; - # discard lines until first blank - :A; n; /^\r?$/!bA; n; - # print lines until boundary ( = actual file upload) - :FILE; p; n; - /^--'"${boundary}"'(--)?\r?$/!bFILE; - # discard remaining lines - :END; $q; n; bEND; - ' >"$file" - truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file" -} +read_channel "$channel" +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" - elif update_video "$video" "name=$(POST name)" \ + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOTALLOWED" + elif update_video "$VIDEO_ID" "name=$(POST name)" \ "description=$(POST description)" \ - "status=$(POST status |grep -m1 -xE 'void|private|hidden|public')" \ + "status=$(POST status |grep -m1 -xE '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" - elif LOCK "$vid_db"; then - while read -r id tail; do - [ "$id" != "$video" ] && printf '%s %s\n' "$id" "$tail" - done <"$vid_db" >"${vid_db}.$$" - mv -- "${vid_db}.$$" "$vid_db" - rm -- "${_DATA}/${channel}/${video}.mp4" "${_DATA}/${channel}/${video}_thumb.jpg" - RELEASE "$vid_db" - REDIRECT "${_BASE}/channel/${channel}/#DELETE_CONFIRM" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOT_CONFIRMED" + elif delete_video "$VIDEO_ID"; then + rm -f -- "$VIDEO_FILE" "$VIDEO_THUMB" "$VIDEO_MP4" "$VIDEO_WEBM" \ + "${VIDEO_MP4%.mp4}".*.mp4 "${VIDEO_WEBM%.webm}".*.webm + 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 -if [ "$REQUEST_METHOD" = POST -a "$channel" -a "$video" ]; then +if [ "$REQUEST_METHOD" = POST -a "$CHANNEL_ID" -a "$VIDEO_ID" ]; then if ! AUTHOR; then head -c "$CONTENT_LENGTH" >/dev/null - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOTALLOWED" - elif [ "$VIDEO_STATUS" != void ]; then + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOTALLOWED" + elif [ -f "$VIDEO_FILE" ]; then head -c "$CONTENT_LENGTH" >/dev/null - REDIRECT "${_BASE}/channel/${channel}/${video}/#ERROR_UPLOAD_NOCLOBBER" - elif UPLOAD "$_DATA/$channel/$video.mp4"; then - update_video "$video" status=private - VIDEO_STATUS=private + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOCLOBBER" + elif UPLOAD "$VIDEO_FILE"; then + transcode "$VIDEO_FILE" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/edit" fi fi -if [ "$channel" -a "$video" -a "$action" = edit ]; then - AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED" +if [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$action" = edit ]; then + AUTHOR || REDIRECT "$_BASE/$CHANNEL_ID/$VIDEO_ID/#ERROR_EDIT_NOTALLOWED" yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF [form .video .edit method=POST - [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name"] - [fieldset .status $([ $VIDEO_STATUS = void ] && printf "disabled=disabled") - [radio "status" "private" #status_private $(checked $VIDEO_STATUS private void)] + [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name" autocomplete=off] + [fieldset .status $([ ! -f "$VIDEO_FILE" ] && printf "disabled=disabled") + [radio "status" "private" #status_private $(checked $VIDEO_STATUS private)] [label for=status_private tooltip="Video is only visible to channel authors" Private] [radio "status" "hidden" #status_hidden $(checked $VIDEO_STATUS hidden)] [label for=status_hidden tooltip="Video will not be listed but can be viewed by anyone knowing the URL" Hidden] @@ -185,80 +84,60 @@ if [ "$channel" -a "$video" -a "$action" = edit ]; then ] EOF -elif [ "$channel" -a "$video" -a "$action" = frameuploadprogress ]; then - AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED" - printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' '' - printf ' - - Upload Progress - - - ' - while [ "$VIDEO_STATUS" = void ]; do - printf '%i\n' "$(stat -c %s "$_DATA/$channel/$video.mp4" 2>&-)" - sleep 1 - read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \ - VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \ - VIDEO_DESCR_CACHE VIDEO_FUTUREUSE <<-EOF - $(grep "^${video} " "${vid_db}") - EOF - done - printf 'Ready!\n' - printf '' +elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$action" = frameuploadprogress ]; then + AUTHOR || REDIRECT "$_BASE/$CHANNEL_ID/$VIDEO_ID/#ERROR_EDIT_NOTALLOWED" + frame_uploadprogress -elif [ "$channel" -a "$video" -a "$action" = frameupload ]; then - AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED" - printf '%s\r\n' 'Content-Type: text/html' '' - [ "$VIDEO_STATUS" = void ] && "$_EXEC"/cgilite/html-sh.sed <<-EOF - [!DOCTYPE HTML] - [html [head - [title Upload Form] - ][body +elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a ! -f "$VIDEO_FILE" ] && AUTHOR; then + yield_page "$VIDEO_NAME" "video" <<-EOF + [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]] + [iframe src="frameuploadprogress" width="100%%" height="50" + [a href="freameuploadprogress" Iframe: Upload progress] + ] [form .upload method=POST enctype="multipart/form-data" [input type=file name=upload] [submit "action" "video_upload" Upload] ] - ]] - EOF - [ "$VIDEO_STATUS" != void ] && "$_EXEC"/cgilite/html-sh.sed <<-EOF - [!DOCTYPE HTML] - [html [head - [title Upload Form] - ][body - [a href="./" target="_parent" . Reload Page!] - ]] + [a .button href="edit" edit] + [h1 .name $(HTML "$VIDEO_NAME")] + [div .description . ${VIDEO_DESCR_CACHE}] EOF -elif [ "$channel" -a "$video" ]; then - [ $VIDEO_STATUS = public -o $VIDEO_STATUS = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; } +elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a -f "$VIDEO_FILE" ]; 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)}")]] - $( AUTHOR && [ $VIDEO_STATUS = void ] && printf ' - [iframe src="frameuploadprogress" width="100%%" height="50" - [a href="freameuploadprogress" Iframe: Upload progress] - ] - [iframe src="frameupload" width="100%%" height="50" - [form .upload method=POST enctype="multipart/form-data" - [input type=file name=upload] - [submit "action" "video_upload" Upload] - ] - ]') - $( [ $VIDEO_STATUS != void ] && printf ' - [video - [source src="%s/video/%s/%s.mp4"] - ]' "$_BASE" "$channel" "$video" - ) + [video preload=none controls=controls width="$VIDEO_RESX" height="$VIDEO_RESY" + $([ -f "$VIDEO_MP4" ] \ + && printf '[source src="%s/video/%s/%s.mp4" type="video/mp4"]' \ + "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" + [ -f "$VIDEO_WEBM" ] \ + && printf '[source src="%s/video/%s/%s.webm" type="video/webm"]' \ + "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" + [ ! -f "$VIDEO_MP4" -a ! -f "$VIDEO_WEBM" ] \ + && printf '[source src="%s/video/%s/%s.upload.mp4" type="video/mp4"] %s' \ + "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" \ + "The video has not yet been transcoded and may not be displayed correctly." + )] + $([ ! -f "$VIDEO_MP4" -a ! -f "$VIDEO_WEBM" ] && { + read file <"$_DATA/transcoding.queue" + if [ "$file" = "$VIDEO_FILE" ]; then + printf '[div .transcoding . This video is currently being + converted to various publishing formats. It may not be + rendered correctly until the conversion is finished.]' + elif grep -qFx "$VIDEO_FILE" "${_DATA}/transcoding.queue"; then + printf '[div .transcoding . This video is not yet converted to a + suitable publishing format. It may not be rendered + correctly until the conversion is finished. The conversion + will start automatically once previous jobs have been + finished.]' + else + printf '[div .transcoding Publishing formats do not seem to be + available for this video. It may be possible that the + uploaded file is broken and cannot be transcoded.]' + fi + }) $(AUTHOR && printf '[a .button href="edit" edit]') [h1 .name $(HTML "$VIDEO_NAME")] [div .description . ${VIDEO_DESCR_CACHE}]