# == FILE FORMAT ==
# ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE
-# (void|private|hidden|public)
+# (private|hidden|public)
# == GLOBALS ==
-unset 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
+UNSET_VIDEO='unset \
+ 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 \
+ VIDEO_FILE VIDEO_THUMB VIDEO_MP4 VIDEO_WEBM
+'
LOCAL_VIDEO='local \
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
+ VIDEO_DESCR_CACHE VIDEO_FUTUREUSE \
+ VIDEO_FILE VIDEO_THUMB VIDEO_MP4 VIDEO_WEBM
'
+eval "$UNSET_VIDEO"
+
read_video() {
local video="$1" vid_db="$_DATA/$CHANNEL_ID/videos.db"
[ "$CHANNEL_ID" ] || return 1
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=''
+ VIDEO_FILE='' VIDEO_THUMB='' VIDEO_MP4='' VIDEO_WEBM=''
if [ $# -eq 0 ]; then
read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \
VIDEO_DESCRIPTION="$(UNSTRING "$VIDEO_DESCRIPTION")"
VIDEO_COVER="$(UNSTRING "$VIDEO_COVER")"
VIDEO_DESCR_CACHE="$(UNSTRING "$VIDEO_DESCR_CACHE")"
+
+ VIDEO_FILE="$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4"
+ VIDEO_THUMB="$_DATA/$CHANNEL_ID/${VIDEO_ID}.thumb.jpg"
+ VIDEO_MP4="$_DATA/$CHANNEL_ID/${VIDEO_ID}.mp4"
+ VIDEO_WEBM="$_DATA/$CHANNEL_ID/${VIDEO_ID}.webm"
else
- unset 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
+ eval "$UNSET_VIDEO"
return 1
fi
}
update_video(){
- local id="${1}" name description resx resy length cover status uploader \
+ local id="${1:=${VIDEO_ID}}" 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 vid_db="$_DATA/$CHANNEL_ID/videos.db"
- [ "$CHANNEL_ID" ] || return 1
+ local FILE THUMB MP4 WEBM arg cnt vid_db="$_DATA/$CHANNEL_ID/videos.db"
+ [ "$id" -a "$CHANNEL_ID" ] || return 1
- video="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.upload.mp4"
- thumb="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.thumb.jpg"
+ FILE="$_DATA/$CHANNEL_ID/${id}.upload.mp4"
+ THUMB="$_DATA/$CHANNEL_ID/${id}.thumb.jpg"
+ # MP4="$_DATA/$CHANNEL_ID/${id}.mp4"
+ # WEBM="$_DATA/$CHANNEL_ID/${id}.webm"
for arg in "$@"; do case $arg in
name=*) name="${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>&-)"
+ if [ -f "$FILE" -a -r "$FILE" ]; then
+ arg="$(echo; ffprobe -show_entries format=duration:stream=width,height "$FILE" 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
+ if [ "${length}" -a ! "${THUMB}" -nt "${FILE}" ]; 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"
+ ffmpeg -nostdin -y -ss "$((cnt * ${length%.*} / 11))" -i "$FILE" \
+ -frames 1 "${THUMB%.jpg}_$((cnt - 1)).jpg"
done 2>&-
- montage "${thumb%.jpg}"_[0-9].jpg \
+ 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
+ -interlace line -quality 85 "${THUMB}"
+ rm -- "${THUMB%.jpg}"_[0-9].jpg
fi
if LOCK "$vid_db"; then
"${resy:-${resy-${RESY}}${resy+0}}" \
"${length:-${length-${LENGTH}}${length+0}}" \
"$(STRING "${cover-$(UNSTRING "$COVER")}")" \
- "${status:-${status-${STATUS}}${status+void}}" \
+ "${status:-${status-${STATUS}}${status+private}}" \
"${uploader:-${uploader-${UPLOADER}}${uploader+\\}}" \
"${hits:-${hits-${HITS}}${hits+0}}" \
"$(printf %s "${description-$(UNSTRING "$DESCRIPTION")}" |markdown |STRING)" \
return 1
fi
# ID NAME DESC RESX RESY LENGTH COVER STATUS UPLDR HITS FUTUREUSE
- printf '%s \\ \\ 0 0 0 \\ void %s 0 \\\n' \
+ printf '%s \\ \\ 0 0 0 \\ private %s 0 \\\n' \
"$video" "$(STRING "$USER_ID")" >>"$vid_db"
RELEASE "$vid_db"
else
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_ID/$VIDEO_ID/#UPDATE_SUCCESS"
else
elif [ "$(POST delconfirm)" != confirm ]; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOT_CONFIRMED"
elif delete_video "$VIDEO_ID"; then
- 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"
+ rm -f -- "$VIDEO_FILE" "$VIDEO_THUMB" "$VIDEO_MP4" "$VIDEO_WEBM"
REDIRECT "${_BASE}/channel/$CHANNEL_ID/#DELETE_CONFIRM"
else
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOLOCK"
if ! AUTHOR; then
head -c "$CONTENT_LENGTH" >/dev/null
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOTALLOWED"
- elif [ "$VIDEO_STATUS" != void ]; then
+ elif [ -f "$VIDEO_FILE" ]; then
head -c "$CONTENT_LENGTH" >/dev/null
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOCLOBBER"
- elif UPLOAD "$_DATA/$CHANNEL_ID/$VIDEO_ID.upload.mp4"; then
- update_video "$VIDEO_ID" status=private
- VIDEO_STATUS=private
+ elif UPLOAD "$VIDEO_FILE"; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/edit"
fi
fi
yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF
[form .video .edit method=POST
[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)]
+ [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]
printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' ''
frame_uploadprogress
-elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$VIDEO_STATUS" = void ]; 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" ] && 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)}")]]
- $( AUTHOR && [ $VIDEO_STATUS = void ] && printf '
[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]
- ]')
- $(AUTHOR && printf '[a .button href="edit" edit]')
+ ]
+ [a .button href="edit" edit]
[h1 .name $(HTML "$VIDEO_NAME")]
[div .description . ${VIDEO_DESCR_CACHE}]
EOF
-elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$VIDEO_STATUS" != void ]; 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)}")]]
[video preload=none controls=controls width="$VIDEO_RESX" height="$VIDEO_RESY"
- $([ -f "${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.mp4" ] \
+ $([ -f "$VIDEO_MP4" ] \
&& printf '[source src="%s/video/%s/%s.mp4" type="video/mp4"]' \
"$_BASE" "$CHANNEL_ID" "$VIDEO_ID"
- [ -f "${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.webm" ] \
+ [ -f "$VIDEO_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"
+ [ ! -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."
)]
$(AUTHOR && printf '[a .button href="edit" edit]')
[h1 .name $(HTML "$VIDEO_NAME")]