]> git.plutz.net Git - serve0/blobdiff - list.sh
altered groupmatch algorithm
[serve0] / list.sh
diff --git a/list.sh b/list.sh
index 950522f1d302eee5a2b0dc075de4cffa7396d70c..a4bdbc797490d31e68700e559476dcc8d02e4319 100644 (file)
--- a/list.sh
+++ b/list.sh
@@ -88,14 +88,18 @@ list_filter(){
 }
 
 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
+  a="${1%$CR}" b="${2%$CR}"
+#  if [ ${#a} -gt ${#b} ]; then
+#    long="$a" short="$b"
+#  else
+#    long="$b" short="$a"
+#  fi
+  # com="$(expr substr "$long" 1 $((${#long} * 3 / 4)))"
+  # com="$(expr substr "$long" 1 $((${#long} - 3)))"
+  ## Cut off youtube- and other site suffixes. Cut of last three characters
+  com="$(printf %s "$a" |sed -E 's;-([0-9a-zA-Z_-]{11}|ph[0-9a-f]{13}|[0-9]{8})$;;; s;...$;;;')"
+  cut="${b#$com}"
+  if [ "${cut}" != "${b}" ]; then
     return 0
   else
     return 1
@@ -122,9 +126,9 @@ list_order(){
       fi
       ln="$name"
     done \
-    | sort -n -k1 |cut -f2- |sed 's;^;metashort\t;;'
+    | sort -sn -k1 |sed -r 's;^[0-9]+\t;metashort\t;;'
   elif [ $ORDER = Length ]; then
-    sort -n -k1 |sed 's;^;metashort\t;;'
+    sort -sn -k1 |sed 's;^;metashort\t;;'
   elif [ $ORDER = Date ]; then
     while read -r fm; do
       sn="${fm##*      }"
@@ -132,7 +136,7 @@ list_order(){
       printf '%i       %s      %s\n' \
              "$(stat -c %Y "$fn")" "${fm%      *}" "$fn"
     done \
-    | sort -rn -k1 |sed -r 's;^[0-9]+\t;metalong\t;;'
+    | sort -srn -k1 |sed -r 's;^[0-9]+\t;metalong\t;;'
   fi
 }
 
@@ -209,7 +213,10 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
 
 { printf '
 [!DOCTYPE HTML]
-[html [head [title Listing]
+[html [head [title '
+  w_bmname
+  printf ' by %s]' "$ORDER"
+  printf '
   [meta name="viewport" content="width=device-width"]
   [link rel=stylesheet href="/style.css" ]
 ] [body