From bce8891e9f27d8aad29436a2771a0027a6012fd7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 4 Dec 2018 20:15:04 +0100 Subject: [PATCH] ordering by grouplength --- index.cgi | 2 +- list.sh | 35 +++++++++++++++++++++++++++++++++-- widgets.sh | 10 ++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/index.cgi b/index.cgi index ad110e0..62e495a 100755 --- a/index.cgi +++ b/index.cgi @@ -15,7 +15,7 @@ file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso FILTER="$(GET f)" SEARCH="$(GET s)" -ORDER="$(GET o |grep -m1 -axE 'Date|Name|Length' || printf Name)" +ORDER="$(GET o |grep -m1 -axE 'Date|Name|Length|Group' || printf Name)" LISTSIZE="$(COOKIE pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 50)" ITEM="$(PATH "${PATH_INFO#/}")" ACTION="$(GET a)" diff --git a/list.sh b/list.sh index e9a98c0..950522f 100644 --- a/list.sh +++ b/list.sh @@ -87,11 +87,42 @@ list_filter(){ fi } +groupmatch(){ + if [ ${#1} -gt ${#2} ]; then + long="$1" short="$2" + else + long="$2" short="$1" + fi + com="$(expr substr "$long" 1 $((${#long} * 3 / 4)))" + cut="${short#$com}" + if [ ${#cut} -lt ${#short} ]; then + return 0 + else + return 1 + fi +} + list_order(){ - local fm fn fn + local fm fn fn al length ln h w t c name buffer l if [ $ORDER = Name ]; then sort -k6 |sed 's;^;metashort\t;;' + elif [ $ORDER = Group ]; then + { sort -k6; echo '0 0 0 tags= comment= _'; } \ + | while read -r length h w t c name; do + if groupmatch "$ln" "$name"; then + al=$((al + length)) + buffer="${buffer}${BR}$length $h $w $t $c $name" + else + printf %s\\n "$buffer" |while read -r l; do + [ "$l" ] && printf '%s %s\n' "$al" "$l" + done + al="$length" + buffer="$length $h $w $t $c $name" + fi + ln="$name" + done \ + | sort -n -k1 |cut -f2- |sed 's;^;metashort\t;;' elif [ $ORDER = Length ]; then sort -n -k1 |sed 's;^;metashort\t;;' elif [ $ORDER = Date ]; then @@ -101,7 +132,7 @@ list_order(){ printf '%i %s %s\n' \ "$(stat -c %Y "$fn")" "${fm% *}" "$fn" done \ - | sort -rn -k1 |cut -f2- |sed 's;^;metalong\t;;' + | sort -rn -k1 |sed -r 's;^[0-9]+\t;metalong\t;;' fi } diff --git a/widgets.sh b/widgets.sh index 896ca6c..ff6f2dd 100644 --- a/widgets.sh +++ b/widgets.sh @@ -56,6 +56,7 @@ fi [ "$ORDER" = Name ] && w_coname=checked [ "$ORDER" = Date ] && w_codate=checked [ "$ORDER" = Length ] && w_colength=checked +[ "$ORDER" = Group ] && w_cogroup=checked w_bookmarks(){ local name='' cf='' cs='' bm="$_DATA/.index/bookmarks" proposed_name='' @@ -116,11 +117,12 @@ w_search(){ [option value=Name %s Name] [option value=Date %s Date] [option value=Length %s Length] + [option value=Group %s Grouplength] ] [input name=s placeholder=Search value="%s"] ] ' \ - "$w_coname" "$w_codate" "$w_colength" \ + "$w_coname" "$w_codate" "$w_colength" "$w_cogroup" \ "$(HTML "$SEARCH")" } @@ -221,11 +223,11 @@ w_advsearch(){ [option value=Name %s Name] [option value=Date %s Date] [option value=Length %s Length] + [option value=Group %s Grouplength] ][button type=submit Apply Filter]] ]' \ - "$w_coname" \ - "$w_codate" \ - "$w_colength" + "$w_coname" "$w_codate" \ + "$w_colength" "$w_cogroup" } w_tagging(){ -- 2.39.2