From 84232e55d22c7ae59ff9709e350d739813c6aaf6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 15 Jul 2018 23:52:35 +0200 Subject: [PATCH] changes in meta format, improved code abstraction --- cgilite | 2 +- index.cgi | 4 +++- indexmeta.sh | 28 ++++++++++++++++++++++++++++ list.sh | 42 ++++++++++++++++++++++++------------------ multitag.sh | 18 ++++++++++-------- style.css | 5 +++++ 6 files changed, 71 insertions(+), 28 deletions(-) diff --git a/cgilite b/cgilite index 813580b..a55a4d8 160000 --- a/cgilite +++ b/cgilite @@ -1 +1 @@ -Subproject commit 813580b4cdebfe5161ef01bcbd126405c3162d7a +Subproject commit a55a4d8fb1dae783a93492c7d9b55d042791864f diff --git a/index.cgi b/index.cgi index 8790fa9..f5880c9 100755 --- a/index.cgi +++ b/index.cgi @@ -3,6 +3,8 @@ [ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}" [ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}" + + file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$' . "$_EXEC/cgilite/cgilite.sh" @@ -34,7 +36,7 @@ elif [ -f "$_DATA/$ITEM" ]; then thumbnail) . "$_EXEC/cgilite/file.sh" index="$_DATA/${ITEM%/*}/.index" - thumb="$index/${ITEM##*/}.jpg" + thumb="$index/${ITEM##*/}"; thumb="${thumb%.*}.jpg" [ -d "$index" -a \! -f "$thumb" ] \ && file="$_DATA/$ITEM" . "$_EXEC/thumbnail.sh" FILE "$thumb" diff --git a/indexmeta.sh b/indexmeta.sh index 84dd26a..30bf32d 100644 --- a/indexmeta.sh +++ b/indexmeta.sh @@ -11,6 +11,7 @@ meta_name() { fn="${fn##*/}" fn="${fn%.*}" STRING "$fn" + printf '\r' } meta_line() { @@ -30,6 +31,33 @@ __EOF "${l-0}" "${w-0}" "${h-0}" "$(meta_name "$video")" } +meta_file(){ + file="$1" + meta="${file%/*}/.index/meta" + name="$(meta_name "$file")" + + if [ -d "${meta%/meta}" ] && LOCK "$meta"; then + grep -vF " ${name}" "$meta" >"$meta.tmp" + meta_line "$file" \ + | tee -a "$meta.tmp" + mv "$meta.tmp" "$meta" + RELEASE "$meta" + fi +} + +meta_info(){ + file="$1" + meta="${file%/*}/.index/meta" + + if [ -d "${meta%/meta}" ]; then + grep -m1 -F " $(meta_name "$file")" "$meta" \ + | grep -xE '[0-9]+ [0-9]+ [0-9]+ tags=[^ ]* comment=[^ ]* .+' \ + || meta_file "$file" + else + printf '0\t0\t0\ttags=\tcomment=\t\r' + fi +} + meta_dir(){ dir="${1}" meta="${dir}/.index/meta" diff --git a/list.sh b/list.sh index 4596dfc..fa657d1 100644 --- a/list.sh +++ b/list.sh @@ -5,14 +5,13 @@ list_item() { name="$(HTML "$1")" path="$(HTML "$ITEM/$1")" - meta="$_DATA/$ITEM/$1"; meta="${meta%/*}/.index/meta" if [ -d "$_DATA/$ITEM/$1" ]; then printf '[a .list .dir href="%s?%s" %s]' \ "$path" "$(HTML "$QUERY_STRING")" "$name" - elif [ -f "$meta" ]; then + else read -r length width height tags comment n <<-EOF - $(grep -m1 -F " $(meta_name "$1")" "$meta") + $(meta_info "$_DATA/$ITEM/$1") EOF printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"][label %s]] @@ -22,11 +21,8 @@ list_item() { "$path" "$path" "$name" \ "$((length / 60))" "$((length % 60))" \ "$width" "$height" \ - "$(printf %s\\n "${tags#tags=}" |tr , ' ' |xargs printf '[span .tag %s]')" \ + "$(UNSTRING "${tags#tags=}" |tr , '\0' |xargs -r0 printf ' [span .tag %s]')" \ "$path" "$path" "$path" - else - printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"][label %s]]]' \ - "$path" "$path" "$name" fi } @@ -124,18 +120,28 @@ list_paginate() { w_tagging(){ printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$(HTML "$REQUEST_URI")" printf '[a href="#" Hide][br]' - find "$_DATA/$ITEM" -path '*/.index/meta' \ - -exec cut -f4 '{}' + \ - | cut -d= -f2- |tr , '\n' | sort -u \ - | while read tag; do - cat_old="${category}"; category="${tag%%:*}" - [ "$category" = "$tag" ] && category="(none)" - [ "$cat_old" -a "$cat_old" != "$category" ] && printf ']]' - [ "$cat_old" != "$category" ] \ - && printf '[fieldset [legend %s:][select name="tag" size=4 multiple' $(HTML "$category") - printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "${tag#*:}")" + tags="$(find "$_DATA/$ITEM" -path '*/.index/meta' -exec cut -f4 '{}' + \ + | cut -d= -f2- |tr , '\n' | sort -u)" + tags="$(UNSTRING "$tags")" + + printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags" + printf %s "$tags" |grep -vF ":" |grep -vxF '' \ + | while read -r tag; do + printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")" done - printf ']][fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]' + printf ']]' + + printf %s "$tags" |cut -sd: -f1 |sort -u \ + | while read -r category; do + printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")" + printf %s "$tags" |grep -wF "${category}" \ + | while read -r tag; do + printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "${tag#*:}")" + done + printf ']]' + done + + printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]' } printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' diff --git a/multitag.sh b/multitag.sh index 0a8e9d4..49bf273 100644 --- a/multitag.sh +++ b/multitag.sh @@ -1,27 +1,29 @@ #!/bin/sh . "$_EXEC/cgilite/storage.sh" +. "$_EXEC/indexmeta.sh" for select in $(seq 1 $(POST_COUNT select)); do file="$_DATA/$ITEM/$(POST select $select)" meta="${file%/*}/.index/meta" - fn="${file##*/}" + + read -r length width height tags comment fn <<-EOF + $(meta_info "$file") + EOF if LOCK "$meta"; then grep -vF " $fn" "$meta" >"${meta}.tmp" - read length width height tags comment x <<-EOF - $(grep -F " $fn" "$meta") - EOF - tags="$(printf '%s' "${tags#tags=}" | tr , '\n')" + tags="$(UNSTRING "${tags#tags=}" |tr , '\n')" for tn in $(seq 1 $(POST_COUNT tag)); do - tags="$tags${BR}$(POST tag $tn |sed -r 's;\t;\\t;g; s;\r;;g;')" + tags="$(printf '%s\n%s' "$tags" "$(POST tag $tn)")" done - tags="$tags${BR}$(POST newtag |sed -r 's;\t;\\t;g; s;\r;;g;')" + tags="$(printf '%s\n%s' "$tags" "$(POST newtag |tr -d '\r')")" + tags="$(printf %s "$tags" |sort -u |tr '\n' ,)" printf '%i\t%i\t%i\ttags=%s\t%s\t%s\n' \ "$length" "$width" "$height" \ - "$(printf %s "$tags" |sort -u |tr '\n' ,)" \ + "$(STRING "${tags#,}")" \ "$comment" "$fn" \ >>"${meta}.tmp" mv "${meta}.tmp" "$meta" diff --git a/style.css b/style.css index 1bbc2ff..d5007a0 100644 --- a/style.css +++ b/style.css @@ -149,6 +149,11 @@ a[href="#advsearch"]:before { background-color: #004; padding: .125em .5em; } +.list.file .tag { + color: white; + background-color: #400; + padding: .125em .5em; +} .list.file input[type="checkbox"] { display: none; } .list.file input[type="checkbox"] + label { -- 2.39.2