]> git.plutz.net Git - rawnet/commitdiff
change upload names to allow for transcoding
authorPaul Hänsch <paul@plutz.net>
Thu, 21 Oct 2021 15:40:24 +0000 (17:40 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 21 Oct 2021 15:40:24 +0000 (17:40 +0200)
db_video.sh
index.cgi
page_channel.sh
page_video.sh
upload.sh

index 86163a289f824bbb69e9dc67ba5205065831a52f..e2cc09d78196d5f35161519dafb810c699441f06 100755 (executable)
@@ -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
index 2dec18fa91c45a98a27040b1c6115383f476f6fd..0d3c66885e4892f256de8aa4d6ebc1cb7a3208ca 100755 (executable)
--- 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/}"
     ;;
index a1e0161d95c9fa90a952803aed48300d313a4dac..89720d2acb9faa74a84ca9bc12c6fb760d193416 100755 (executable)
@@ -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]
index 28061c2e18f458aa32ae8d9ab6badb7ba05dc21a..3d425e32044168184bc9d5a0ce20980cf1ff2207 100755 (executable)
@@ -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}]
index dd678fef8a6aa4020b0f623b2b82e6139e0d3e20..63704071050e2683ef0374581c616408c786b855 100755 (executable)
--- a/upload.sh
+++ b/upload.sh
@@ -40,11 +40,11 @@ frame_uploadprogress() {
   </head><body id=uploadprogress>
   ' "$_BASE"
   printf '<div class=progress><div class=bar style="width: 0%%;"></div><div class=count>%i / %i</div></div>\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 '<div class=progress><div class=bar style="width:%i%%;"></div><div class=count>%iMB / %iMB</div></div>\n' \
       "$(( stat * 100 / size ))" "$((stat / 1048576))" "$((size / 1048576))"
     sleep 1