unset CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO CHANNEL_THEME \
CHANNEL_AUTHORS CHANNEL_DESCR_CACHE CHANNEL_FUTUREUSE
+LOCAL_CHANNEL='local \
+ CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO CHANNEL_THEME \
+ CHANNEL_AUTHORS CHANNEL_DESCR_CACHE CHANNEL_FUTUREUSE
+'
+
chan_db="$_DATA/channels.db"
read_channel() {
VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \
VIDEO_DESCR_CACHE VIDEO_FUTUREUSE
-[ "$CHANNEL_ID" ] && vid_db="$_DATA/$CHANNEL_ID/videos.db"
+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
+'
read_video() {
- local video="$1"
+ local video="$1" vid_db="$_DATA/$CHANNEL_ID/videos.db"
+ [ "$CHANNEL_ID" ] || return 1
# Global exports
VIDEO_ID='' VIDEO_NAME='' VIDEO_DESCRIPTION='' VIDEO_RESX='' VIDEO_RESY=''
hits descr_cache futureuse
local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \
DESCR_CACHE FUTUREUSE
- local arg video thumb cnt
+ local arg video thumb cnt vid_db="$_DATA/$CHANNEL_ID/videos.db"
+ [ "$CHANNEL_ID" ] || return 1
+
video="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.upload.mp4"
thumb="${_DATA}/${CHANNEL_ID}/${VIDEO_ID}.thumb.jpg"
}
new_video(){
- local video="${1:-$(randomid)}"
+ local video="${1:-$(randomid)}" vid_db="$_DATA/$CHANNEL_ID/videos.db"
+ [ "$CHANNEL_ID" ] || return 1
if LOCK "$vid_db"; then
if grep -q "^${video} " "$vid_db"; then
}
delete_video() {
- local video="$1"
+ local video="$1" vid_db="$_DATA/$CHANNEL_ID/videos.db"
+ [ "$CHANNEL_ID" ] || return 1
if LOCK "$vid_db"; then
grep -v "^${video} " <"$vid_db" >"${vid_db}.$$"
. "${_EXEC}/cgilite/file.sh"
FILE "${_DATA}/${PATH_INFO#/video/}"
;;
- /|/channel/*) . "${_EXEC}/page_channel.sh";;
+ /channel/*/*/*)
+ action="${PATH_INFO##*/}"
+ video="${PATH_INFO%/*}" video="${video##*/}"
+ channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+ . "$_EXEC/page_video.sh"
+ ;;
+ /channel/*/*/)
+ action=""
+ video="${PATH_INFO%/}" video="${video##*/}"
+ channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+ . "$_EXEC/page_video.sh"
+ ;;
+ /channel/*/*)
+ action="${PATH_INFO##*/}"
+ video=""
+ channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+ . "$_EXEC/page_channel.sh"
+ ;;
+ /channel/*/)
+ action=""
+ video=""
+ channel="${PATH_INFO#/channel/}" channel="${channel%%/*}"
+ . "$_EXEC/page_channel.sh"
+ ;;
+ /|/channel/)
+ . "${_EXEC}/page_channel.sh"
+ ;;
/playlist/*) . "${_EXEC}/page_playlist.sh";;
/search/*) . "${_EXEC}/page_search.sh";;
*) . "${_EXEC}/page_404.sh";;
#!/bin/sh
-. "$_EXEC/db_channel.sh"
-. "$_EXEC/db_video.sh"
-
-channel='' video='' action=''
-path_info="$PATH_INFO"
-path_info="${path_info#/channel/}"
-if [ "$(checkid "${path_info%%/*}")" ]; then
- channel="${path_info%%/*}"
- path_info="${path_info#*/}"
-fi
-if [ "$(checkid "${path_info%%/*}")" ]; then
- video="${path_info%%/*}"
- path_info="${path_info#*/}"
-fi
-action="${path_info}"
-unset path_info
-
-read_channel "$channel" \
-&& vid_db="${_DATA}/${CHANNEL_ID}/videos.db"
+["$includepage_channel" ] && return 0
+includepage_channel="$0"
-AUTHOR(){
- if [ "$CHANNEL_ID" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then
- return 0
- else
- return 1
- fi
-}
+. "$_EXEC/db_channel.sh"
+. "$_EXEC/widgets.sh"
-# Video
-# ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS
+read_channel "$channel"
[ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
newchannel)
fi
;;
update_channel)
- if [ ! "$channel" ]; then
+ if [ ! "$CHANNEL_ID" ]; then
REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
elif [ ! "$USER_ID" ]; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN"
elif ! AUTHOR; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED"
- elif update_channel "$channel" "name=$(POST name)" \
+ elif update_channel "$CHANNEL_ID" "name=$(POST name)" \
"description=$(POST description)" \
"authors=$USER_ID"; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/"
REDIRECT "${_BASE}/channel/$CHANNEL_ID/"
;;
newvideo)
+ . "$_EXEC/db_video.sh"
video="$(POST video |checkid)"
AUTHOR \
if [ ! "$video" ]; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_INVALID_ID"
- elif [ ! "$channel" ]; then
+ elif [ ! "$CHANNEL_ID" ]; then
REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
elif [ ! "$USER_ID" ]; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN"
elif ! AUTHOR; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED"
elif new_video "$video"; then
- REDIRECT "${_BASE}/channel/$CHANNEL_ID/${video}/"
+ REDIRECT "${_BASE}/channel/$CHANNEL_ID/$video/"
else
REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NEWVIDEO_NOLOCK"
fi
;;
esac
-w_video(){
- local thumb
- 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
-
- if read_video; then
- VIDEO_LENGTH="${VIDEO_LENGTH%.*}"
- [ "${VIDEO_STATUS}" = public ] || AUTHOR || return 0
-
- thumb="${_BASE}/video/${CHANNEL_ID}/${VIDEO_ID}.thumb.jpg"
- [ "$NAME" = \\ ] && NAME="(Unnamed Video)"
- printf '[div .video .thumb
- [a href="%s/channel/%s/%s/"
- [h3 . %s]
- [figure [img src="%s" alt=""]]
- [span .duration . %i:%02i]
- [div .description . %s]
- ]
- ]' "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" \
- "$(HTML "${VIDEO_NAME:-(Unnamed Video)}")" \
- "$thumb" \
- "$((VIDEO_LENGTH / 60))" "$((VIDEO_LENGTH % 60))" \
- "$(UNSTRING "$DESCR_CACHE")"
- else
- return 1
- fi
-}
-
-w_channel_list(){
- local vid_db
- local CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \
- CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE CHANNEL_FUTUREUSE
-
- [ "$USER_ID" ] && cat <<-EOF
- [form .channel .newchannel method=POST
- [hidden "channel" "$(timeid)"]
- [submit "action" "newchannel" New Channel]
- ]
- EOF
-
- [ -f "$chan_db" -a -r "$chan_db" ] \
- && while read_channel; do
- vid_db="${_DATA}/${CHANNEL_ID}/videos.db"
-
- cat <<-EOF
- [div .channel
- [div .description
- [h2 [a href="${_BASE}/channel/${CHANNEL_ID}/" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]]
- ${CHANNEL_DESCR_CACHE}
- ]$(
- [ -f "$vid_db" -a -r "$vid_db" ] \
- && while w_video; do :; done <"$vid_db"
- )
- ]
- EOF
- done <"$chan_db"
-}
-
-if [ "$channel" -a "$video" ]; then
- . ${_EXEC}/page_video.sh
-elif [ "$channel" -a "$action" = edit ]; then
+if [ "$CHANNEL_ID" -a "$action" = edit ]; then
AUTHOR || REDIRECT "${_BASE}/$CHANNEL_ID/#ERROR_EDIT_NOTALLOWED"
yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF
[form .channel .edit method=POST
[submit "action" "update_channel_cancel" . Cancel]
]
EOF
-elif [ "$channel" ]; then
+elif [ "$CHANNEL_ID" ]; then
+ vid_db="$_DATA/$CHANNEL_ID/videos.db"
yield_page "$CHANNEL_NAME" "channel" <<-EOF
[nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]
$(AUTHOR && printf ' - [a href="edit" edit]')
[h1 .videos Videos]
[div .videos . $(
AUTHOR && printf '
- [form .video .newvideo method=POST
- [hidden "video" "%s"]
- [submit "action" "newvideo" New Video]
- ]' "$(timeid)"
+ [form .video .newvideo method=POST
+ [hidden "video" "%s"]
+ [submit "action" "newvideo" New Video]
+ ]' "$(timeid)"
[ -f "$vid_db" -a -r "$vid_db" ] \
- && while w_video "$ID"; do :; done <"$vid_db"
+ && while w_video; do :; done <"$vid_db"
)]
EOF
else
yield_page "Channels" "channels" <<-EOF
- $(w_channel_list)
+ $([ "$USER_ID" ] && printf '
+ [form .channel .newchannel method=POST
+ [hidden "channel" "%s"]
+ [submit "action" "newchannel" New Channel]
+ ]' "$(timeid)"
+ )
+ $([ -f "$chan_db" -a -r "$chan_db" ] \
+ && while w_channel; do :; done <"$chan_db"
+ )
EOF
fi
#!/bin/sh
+[ "$includepage_video" ] && return 0
+includepage_video="$0"
+
+. "$_EXEC/db_channel.sh"
. "$_EXEC/db_video.sh"
+. "$_EXEC/widgets.sh"
. "$_EXEC/upload.sh"
+read_channel "$channel"
read_video "$video"
[ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOTLOGGEDIN"
elif ! AUTHOR; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOTALLOWED"
- elif update_video "$video" "name=$(POST name)" \
+ elif update_video "$VIDEO_ID" "name=$(POST name)" \
"description=$(POST description)" \
"status=$(POST status |grep -m1 -xE 'void|private|hidden|public')" \
"uploader=$USER_ID"; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_UPDATE_NOTALLOWED"
elif [ "$(POST delconfirm)" != confirm ]; then
REDIRECT "${_BASE}/channel/$CHANNEL_ID/$VIDEO_ID/#ERROR_NOT_CONFIRMED"
- elif delete_video "$video"; then
+ 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" \
;;
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_ID/$VIDEO_ID/#ERROR_UPLOAD_NOTALLOWED"
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" status=private
+ update_video "$VIDEO_ID" status=private
VIDEO_STATUS=private
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
]
EOF
-elif [ "$channel" -a "$video" -a "$action" = frameuploadprogress ]; then
- AUTHOR || REDIRECT "$_BASE/$channel/$video/#ERROR_EDIT_NOTALLOWED"
+elif [ "$CHANNEL_ID" -a "$VIDEO_ID" -a "$action" = frameuploadprogress ]; then
+ AUTHOR || REDIRECT "$_BASE/$CHANNEL_ID/$VIDEO_ID/#ERROR_EDIT_NOTALLOWED"
printf '%s\r\n' 'Content-Type: text/html' 'Connection: close' ''
frame_uploadprogress
-elif [ "$channel" -a "$video" -a "$VIDEO_STATUS" = void ]; then
+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; }
yield_page "$VIDEO_NAME" "video" <<-EOF
[div .description . ${VIDEO_DESCR_CACHE}]
EOF
-elif [ "$channel" -a "$video" -a "$VIDEO_STATUS" != void ]; then
+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; }
yield_page "$VIDEO_NAME" "video" <<-EOF
#!/bin/sh
+[ "$include_upload" ] && return 0
+include_upload="$0"
+
UPLOAD(){
local file="$1"
local boundary line length=0
</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.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>&-)"
+ while [ ! -f "$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4" \
+ -a ! -f "$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4.upload" ]; do sleep 1; done
+ read size <"$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4.upload"
+ while [ -f "$_DATA/$CHANNEL_ID/${VIDEO_ID}.upload.mp4.upload" ]; do
+ stat="$(stat -c %s "$_DATA/$CHANNEL_ID/${VIDEO_ID}.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
--- /dev/null
+#!/bin/sh
+
+["$include_widgets" ] && return 0
+include_widgets="$0"
+
+. "$_EXEC/db_channel.sh"
+. "$_EXEC/db_video.sh"
+
+AUTHOR(){
+ if [ "$CHANNEL_ID" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+w_video(){
+ local thumb
+ eval "$LOCAL_VIDEO"
+
+ if read_video; then
+ VIDEO_LENGTH="${VIDEO_LENGTH%.*}"
+ [ "${VIDEO_STATUS}" = public ] || AUTHOR || return 0
+
+ thumb="${_BASE}/video/${CHANNEL_ID}/${VIDEO_ID}.thumb.jpg"
+ [ "$NAME" = \\ ] && NAME="(Unnamed Video)"
+ printf '[div .video .thumb
+ [a href="%s/channel/%s/%s/"
+ [h3 . %s]
+ [figure [img src="%s" alt=""]]
+ [span .duration . %i:%02i]
+ [div .description . %s]
+ ]
+ ]' "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" \
+ "$(HTML "${VIDEO_NAME:-(Unnamed Video)}")" \
+ "$thumb" \
+ "$((VIDEO_LENGTH / 60))" "$((VIDEO_LENGTH % 60))" \
+ "$(UNSTRING "$DESCR_CACHE")"
+ else
+ return 1
+ fi
+}
+
+w_channel(){
+ local vid_db
+ eval "$LOCAL_CHANNEL"
+
+ if read_channel; then
+ vid_db="${_DATA}/${CHANNEL_ID}/videos.db"
+
+ cat <<-EOF
+ [div .channel
+ [div .description
+ [h2 [a href="${_BASE}/channel/${CHANNEL_ID}/" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]]
+ ${CHANNEL_DESCR_CACHE}
+ ]$(
+ [ -f "$vid_db" -a -r "$vid_db" ] \
+ && while w_video; do :; done <"$vid_db"
+ )
+ ]
+ EOF
+ else
+ return 1
+ fi
+}