From ff37ad4517acb36fbee5ffca5a163920e41ed9ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 30 Sep 2021 16:46:50 +0200 Subject: [PATCH] filter non-public videos, smarter update_channel function --- page_channel.sh | 84 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/page_channel.sh b/page_channel.sh index ebba84d..2e35590 100755 --- a/page_channel.sh +++ b/page_channel.sh @@ -37,19 +37,33 @@ if [ "$channel" -a -f "$chan_db" -a -r "$chan_db" ]; then fi update_channel(){ - local id="${1}" name="${2}" description="${3}" logo="${4}" theme="${5}" \ - authors="${6}" descr_cache="${7}" futureuse="${8}" - local ID INFO + local id="${1}" name description logo theme authors descr_cache futureuse + local ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE + local arg + + for arg in "$@"; do case $arg in + name=*) name="${arg#*=}";; + description=*) description="${arg#*=}";; + logo=*) logo="${arg#*=}";; + theme=*) theme="${arg#*=}";; + authors=*) authors="${arg#*=}";; + esac; done + if LOCK "$chan_db"; then - while read -r ID INFO; do + while read -r ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE; do if [ "$id" = "$ID" ]; then printf '%s %s %s %s %s %s %s %s\n' \ - "$id" "$(STRING "$name")" "$(STRING "$description")" \ - "${logo:-\\}" "${theme:-\\}" "$(STRING "$authors")" \ - "$(printf %s "$description" |markdown |STRING)" \ - "${futureuse:-\\}" + "$id" "$(STRING "${name-$(UNSTRING "$NAME")}")" \ + "$(STRING "${description-$(UNSTRING "$DESCRIPTION")}")" \ + "${logo:-${logo-${LOGO}}${logo+\\}}" \ + "${theme:-${theme-${THEME}}${theme+\\}}" \ + "$(STRING "${authors-$(UNSTRING "${AUTHORS}")}")" \ + "$(printf %s "${description-$(UNSTRING "$DESCRIPTION")}" |markdown |STRING)" \ + "${FUTUREUSE:-\\}" else - printf '%s %s\n' "$ID" "$INFO" + printf '%s %s %s %s %s %s %s %s\n' \ + "$ID" "$NAME" "$DESCRIPTION" "$LOGO" "$THEME" "$AUTHORS" \ + "$DESCR_CACHE" "$FUTUREUSE" fi done <"$chan_db" >"${chan_db}.$$" mv -- "${chan_db}.$$" "${chan_db}" @@ -60,7 +74,7 @@ update_channel(){ } AUTHOR(){ - if [ "$channel" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then + if [ "$CHANNEL_ID" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then return 0 else return 1 @@ -97,8 +111,9 @@ AUTHOR(){ REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" elif ! AUTHOR; then REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" - elif update_channel "$channel" "$(POST name)" "$(POST description)" \ - "" "" "$USER_ID" "" ""; then + elif update_channel "$channel" "name=$(POST name)" \ + "description=$(POST description)" \ + "authors=$USER_ID"; then REDIRECT "${_BASE}/channel/${channel}/" else REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOLOCK" @@ -140,16 +155,29 @@ AUTHOR(){ esac w_video(){ - local CID="$1" thumb - local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE - if read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE; then - thumb="${_BASE}/${CID}/thumb_${ID}.jpg" + 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 -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; then + VIDEO_NAME="$(UNSTRING "$VIDEO_NAME")" + VIDEO_DESCRIPTION="$(UNSTRING "$VIDEO_DESCRIPTION")" + VIDEO_DESCR_CACHE="$(UNSTRING "$VIDEO_DESCR_CACHE")" + + [ "${VIDEO_STATUS}" = public ] || AUTHOR || return 0 + + thumb="${_BASE}/${CHANNEL_ID}/thumb_${VIDEO_ID}.jpg" [ "$NAME" = \\ ] && NAME="(Unnamed Video)" printf '[div .video .thumb [h3 [a href="%s/channel/%s/%s/" . %s]] [figure [img src="%s" alt=""]] [div .description . %s] - ]' "$_BASE" "$CID" "$ID" "$(UNSTRING "$NAME" |HTML)" "$thumb" "$(UNSTRING "$DESCR_CACHE")" + ]' "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" \ + "$(HTML "${VIDEO_NAME:-(Unnamed Video)}")" \ + "$thumb" "$(UNSTRING "$DESCR_CACHE")" else return 1 fi @@ -157,18 +185,26 @@ w_video(){ w_channel(){ local vid_db - local ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE - if read -r ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE; then - vid_db="${_DATA}/${ID}/videos.db" - [ "$NAME" = \\ ] && NAME="(UNNAMED CHANNEL)" + local CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \ + CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE CHANNEL_FUTUREUSE + + if read -r CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \ + CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \ + CHANNEL_FUTUREUSE; then + CHANNEL_NAME="$(UNSTRING "$CHANNEL_NAME")" + CHANNEL_DESCRIPTION="$(UNSTRING "$CHANNEL_DESCRIPTION")" + CHANNEL_AUTHORS="$(UNSTRING "$CHANNEL_AUTHORS")" + CHANNEL_DESCR_CACHE="$(UNSTRING "$CHANNEL_DESCR_CACHE")" + + vid_db="${_DATA}/${CHANNEL_ID}/videos.db" cat <<-EOF [div .channel [div .description - [h2 [a href="${_BASE}/channel/${ID}/" $(UNSTRING "${NAME}" |HTML)]] - $(UNSTRING "$DESCR_CACHE") + [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 "$ID"; do :; done <"$vid_db" + && while w_video; do :; done <"$vid_db" ) ] EOF -- 2.39.2