]> git.plutz.net Git - serve0/commitdiff
ordering by grouplength
authorPaul Hänsch <paul@plutz.net>
Tue, 4 Dec 2018 19:15:04 +0000 (20:15 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 4 Dec 2018 19:15:04 +0000 (20:15 +0100)
index.cgi
list.sh
widgets.sh

index ad110e070dcfeebb301108fc4bf16d53a72c3324..62e495aed94d5538515f3ba751dc5a625bc67c79 100755 (executable)
--- 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 e9a98c0ecf8e75d8a338c8d06350d612568edaf9..950522f1d302eee5a2b0dc075de4cffa7396d70c 100644 (file)
--- 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
 }
 
index 896ca6cdfab3d97ebdcfd59374221f618100a336..ff6f2ddfacc158f91daa266c67bdb368bdb5527b 100644 (file)
@@ -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(){