From: Paul Hänsch Date: Tue, 21 Dec 2021 22:06:41 +0000 (+0100) Subject: improved auto grouping X-Git-Url: http://git.plutz.net/?p=serve0;a=commitdiff_plain;h=dad9cd471358d165f1de2ce8d5806703ac85f5bb improved auto grouping --- diff --git a/db_meta.sh b/db_meta.sh index 9f427fc..d2d6999 100755 --- a/db_meta.sh +++ b/db_meta.sh @@ -28,15 +28,15 @@ read_meta() { # Global exports META_LENGTH='' META_WIDTH='' META_HEIGHT='' META_TAGS='' - META_COMMENT='' META_NAME='' META_GROUP='' + META_COMMENT='' META_NAME='' META_GROUP='' META_GROUPORDER='' if [ $# -eq 0 ]; then read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT \ - META_NAME META_GROUP + META_NAME META_GROUP META_GROUPORDER elif [ "$name" -a -f "$meta_db" -a -r "$meta_db" ]; then read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT \ - META_NAME META_GROUP <<-EOF - $(grep -F " ${name}${CR}" "$meta_db") + META_NAME META_GROUP META_GROUPORDER <<-EOF + $(grep -F " ${name}${CR}" "$meta_db" |dbmeta_autogroup) EOF fi if [ "$META_NAME" ]; then @@ -155,10 +155,38 @@ list_meta(){ pfx="$(STRING "${pfx#/}")" [ "$pfx" = '\' ] && pfx='' || pfx="${pfx}/" - while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP; do + dbmeta_autogroup "$meta" \ + | while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP; do printf '%i %i %i tags=%s comment=%s %s%s\r %s\n' \ $LENGTH $WIDTH $HEIGHT "${TAGS#tags=}" \ "${COMMENT#comment=}" "${pfx}" "${NAME%${CR}}" "${GROUP:-\\}" - done <"$meta" + done done } + +dbmeta_autogroup(){ + sed -E ' + # perform auto grouping if group id is missing or empty + /\r$/bAUTOGROUP; s;\r \\$;\r;; tAUTOGROUP; + + # skip auto grouping if manual group id is present + /\r .+$/b; + + :AUTOGROUP + # save original dataset + h; + + # strip all fields but the name + s;^[^\t]+ [^\t]+ [^\t]+ [^\t]+ [^\t]+ ;; + # strip common suffixes of web video sites + s;-([0-9a-zA-Z_-]{11}|ph[0-9a-f]{13}|[0-9]{6,})\r$;-\r;; + + # replace all numeric parts and append numerals to an ordering field + # the group id will be made up of only the non-numeric character frame + # the ordering field will hold all numbers from the name + :X s;^([^\r0-9]*)([0-9]+)([^\r0-9]*)\r\t?([0-9]*)$;\1\r\3\r \4\2;; tX; + + # append group id and ordering field to dataset + H; g; s;\n;\t;; + ' "$@" +} diff --git a/list.sh b/list.sh index 65d929a..6245261 100755 --- a/list.sh +++ b/list.sh @@ -87,24 +87,14 @@ list_filter(){ } list_order(){ - local fm fn fn al length ln h w t c name buffer l + local fm fn fn al length ln h w t c name group o buffer l if [ $ORDER = Name ]; then sort -k6 elif [ $ORDER = Group ]; then - sed -E ' - /^[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*\r$/bX; - /^[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*\r\t\\$/bX; - s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t)([^\r]*)\r\t(.*)$;\1\r\3 \2\r\t;; - t; - :X - s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)-([0-9a-zA-Z_-]{11}\r|ph[0-9a-f]{13}\r|[0-9]{8}\r)(.*)$;\1-\r\3 \2;; - t; - s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)([0-9]+)(.*)$;\1\r\3 \2;; - tX;' \ - | { sort -n -k7 -k8 -k9 -k10 -k11 |sort -s -k6,6 ; echo '0 0 0 tags= comment= _'; } \ - | while read -r length w h t c name; do - if [ "${ln%% *}" = "${name%% *}" ]; then + { sort -n -k8 -k6,6 |sort -s -k7,7 ; echo '0 0 0 tags= comment= _'; } \ + | while read -r length w h t c name group o; do + if [ "${ln%% *}" = "${group}" ]; then al=$((al + length)) buffer="${buffer}${BR}$length $w $h $t $c $name" else @@ -114,13 +104,9 @@ list_order(){ al="$length" buffer="$length $w $h $t $c $name" fi - ln="$name" + ln="$group" done \ - | sort -s -n -k1,1 |sed -E 's;^[0-9]+\t;;;' \ - | sed -E ' - s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t)\r([0-9A-Za-z:=]{16}) ([^ ]+)$;\1\3\r\t\2;; t; - :X s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*)\r([^ ]*) ([^ ]+)( .*)?$;\1\3\2\4;; tX - ' + | sort -s -n -k1,1 |sed -E 's;^[0-9]+\t;;;' elif [ $ORDER = Length ]; then sort -sn -k1 elif [ $ORDER = Date ]; then