]> git.plutz.net Git - rawnet/blob - page_video.sh
simple UI messages about transcoding status
[rawnet] / page_video.sh
1 #!/bin/sh
2
3 [ "$includepage_video" ] && return 0
4 includepage_video="$0"
5
6 . "$_EXEC/db_channel.sh"
7 . "$_EXEC/db_video.sh"
8 . "$_EXEC/upload.sh"
9 . "$_EXEC/transcoding.sh"
10
11 read_channel "$channel"
12 read_video "$video"
13
14 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
15   update_video)
16     if [ ! "$USER_ID" ]; then
17       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOTLOGGEDIN"
18     elif ! AUTHOR; then
19       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOTALLOWED"
20     elif update_video "$VIDEO_ID" "name=$(POST name)" \
21                       "description=$(POST description)" \
22                       "status=$(POST status |grep -m1 -xE 'private|hidden|public')" \
23                       "uploader=$USER_ID"; then
24       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#UPDATE_SUCCESS"
25     else
26       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOLOCK"
27     fi
28     ;;
29   update_video_cancel)
30     REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#CANCELED"
31     ;;
32   delete)
33     if [ ! "$USER_ID" ]; then
34       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOTLOGGEDIN"
35     elif ! AUTHOR; then
36       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOTALLOWED"
37     elif [ "$(POST delconfirm)" != confirm ]; then
38       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOT_CONFIRMED"
39     elif delete_video "$VIDEO_ID"; then
40       rm -f -- "$VIDEO_FILE" "$VIDEO_THUMB" "$VIDEO_MP4" "$VIDEO_WEBM" \
41                "${VIDEO_MP4%.mp4}".*.mp4 "${VIDEO_WEBM%.webm}".*.webm
42       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#DELETE_CONFIRM"
43     else
44       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOLOCK"
45     fi
46     ;;
47 esac
48
49 if [ "$REQUEST_METHOD" = POST -a "$CHANNEL_ID" -a "$VIDEO_ID" ]; then
50   if ! AUTHOR; then
51     head -c "$CONTENT_LENGTH" >/dev/null
52     REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOTALLOWED"
53   elif [ -f "$VIDEO_FILE" ]; then
54     head -c "$CONTENT_LENGTH" >/dev/null
55     REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPLOAD_NOCLOBBER"
56   elif UPLOAD "$VIDEO_FILE"; then
57     transcode "$VIDEO_FILE"
58     REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/edit"
59   fi
60 fi
61
62 if [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$action" = edit ]; then
63   AUTHOR || REDIRECT "$_BASE/$CHANNEL_ID/$VIDEO_ID/#ERROR_EDIT_NOTALLOWED"
64
65   yield_page "$VIDEO_NAME - Edit" "video edit" <<-EOF
66         [form .video .edit method=POST
67           [input name="name" value="$(HTML "$VIDEO_NAME")" placeholder="Video Name" autocomplete=off]
68           [fieldset .status $([ ! -f "$VIDEO_FILE" ] && printf "disabled=disabled")
69             [radio "status" "private" #status_private $(checked $VIDEO_STATUS private)]
70               [label for=status_private tooltip="Video is only visible to channel authors" Private]
71             [radio "status" "hidden" #status_hidden  $(checked $VIDEO_STATUS hidden)]
72               [label for=status_hidden tooltip="Video will not be listed but can be viewed by anyone knowing the URL" Hidden]
73             [radio "status" "public" #status_public $(checked $VIDEO_STATUS public)]
74               [label for=status_public tooltip="Video will be listed publicly" Public]
75           ]
76           [textarea name="description" placeholder="Description" . $(HTML "$VIDEO_DESCRIPTION")]
77           [submit "action" "update_video" . Update]
78           [submit "action" "update_video_cancel" . Cancel]
79           [fieldset .delete
80             [checkbox "delconfirm" "confirm" id="delconfirm"]
81             [label for=delconfirm Delete Video]
82             [submit "action" "delete" Delete Video]
83           ]
84         ]
85         EOF
86
87 elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$action" = frameuploadprogress ]; then
88   AUTHOR || REDIRECT "$_BASE/$CHANNEL_ID/$VIDEO_ID/#ERROR_EDIT_NOTALLOWED"
89   printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' ''
90   frame_uploadprogress
91
92 elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a ! -f "$VIDEO_FILE" ] && AUTHOR; then
93   yield_page "$VIDEO_NAME" "video" <<-EOF
94         [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]]
95         [iframe src="frameuploadprogress" width="100%%" height="50"
96           [a href="freameuploadprogress" Iframe: Upload progress]
97         ]
98         [form .upload method=POST enctype="multipart/form-data"
99           [input type=file name=upload]
100           [submit "action" "video_upload" Upload]
101         ]
102         [a .button href="edit" edit]
103         [h1 .name $(HTML "$VIDEO_NAME")]
104         [div .description . ${VIDEO_DESCR_CACHE}]
105         EOF
106
107 elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a -f "$VIDEO_FILE" ]; then
108   [ "$VIDEO_STATUS" = public -o "$VIDEO_STATUS" = hidden ] || AUTHOR || { . ${_EXEC}/page_404.sh; exit 0; }
109
110   yield_page "$VIDEO_NAME" "video" <<-EOF
111         [nav [a href="../../" Channels] - [a href="../" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - [span $(HTML "${VIDEO_NAME:-(Unnamed Video)}")]]
112         [video preload=none controls=controls width="$VIDEO_RESX" height="$VIDEO_RESY"
113         $([ -f "$VIDEO_MP4" ] \
114           && printf '[source src="%s/video/%s/%s.mp4"  type="video/mp4"]' \
115                     "$_BASE" "$CHANNEL_ID" "$VIDEO_ID"
116           [ -f "$VIDEO_WEBM" ] \
117           && printf '[source src="%s/video/%s/%s.webm" type="video/webm"]' \
118                     "$_BASE" "$CHANNEL_ID" "$VIDEO_ID"
119           [ ! -f "$VIDEO_MP4" -a ! -f "$VIDEO_WEBM" ] \
120           && printf '[source src="%s/video/%s/%s.upload.mp4"  type="video/mp4"] %s' \
121                     "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" \
122                     "The video has not yet been transcoded and may not be displayed correctly."
123         )]
124         $([ ! -f "$VIDEO_MP4" -a ! -f "$VIDEO_WEBM" ] && {
125           read file <"$_DATA/transcoding.queue" 
126           if [ "$file" = "$VIDEO_FILE" ]; then
127             printf '[div .transcoding . This video is currently being
128                     converted to various publishing formats. It may not be
129                     rendered correctly until the conversion is finished.]'
130           elif grep -qFx "$VIDEO_FILE" "${_DATA}/transcoding.queue"; then
131             printf '[div .transcoding . This video is not yet converted to a
132                     suitable publishing format. It may not be rendered
133                     correctly until the conversion is finished. The conversion
134                     will start automatically once previous jobs have been
135                     finished.]'
136           else
137             printf '[div .transcoding Publishing formats do not seem to be
138                     available for this video. It may be possible that the
139                     uploaded file is broken and cannot be transcoded.]'
140           fi
141         })
142         $(AUTHOR && printf '[a .button href="edit" edit]')
143         [h1 .name $(HTML "$VIDEO_NAME")]
144         [div .description . ${VIDEO_DESCR_CACHE}]
145         EOF
146
147 else
148   . "$_EXEC/page_404.sh"
149 fi