]> git.plutz.net Git - serve0/commitdiff
basics for indexed browsing
authorpaul <paul@plutz.net>
Thu, 12 Jan 2017 00:58:19 +0000 (00:58 +0000)
committerpaul <paul@plutz.net>
Thu, 12 Jan 2017 00:58:19 +0000 (00:58 +0000)
svn path=/trunk/; revision=167

actions/dirindex.sh [new file with mode: 0755]
pages/browse.sh [new file with mode: 0755]
templates/browse.html.sh [new file with mode: 0755]
templates/list.html.sh
templates/playctl.html.sh
templates/quicklinks.html.sh
templates/view.html.sh

diff --git a/actions/dirindex.sh b/actions/dirindex.sh
new file mode 100755 (executable)
index 0000000..baf99bb
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/zsh
+
+# Copyright 2017 Paul Hänsch
+#
+# This file is part of Serve0.
+# 
+# Serve0 is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# Serve0 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with Serve0.  If not, see <http://www.gnu.org/licenses/>. 
+
+directory="$(invalidate "${_GET[d]}" '(.*/)?\.\.(/.*)?|' /)"
+mkdir -p "${treeroot}/${directory#/}/.index"
+
+redirect "?p=browse&d=$(urlsafe "${directory%/}")"
diff --git a/pages/browse.sh b/pages/browse.sh
new file mode 100755 (executable)
index 0000000..95741af
--- /dev/null
@@ -0,0 +1,182 @@
+#!/bin/zsh
+
+# Copyright 2014 - 2017 Paul Hänsch
+#
+# This file is part of Serve0.
+# 
+# Serve0 is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# Serve0 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with Serve0.  If not, see <http://www.gnu.org/licenses/>. 
+
+. $_EXEC/pages/common.sh
+
+LF='
+'
+directory="$(invalidate "${_GET[d]}" '(.*/)?\.\.(/.*)?|' /)"
+[ -d "${treeroot}/${directory#/}/.index" ] && indexed=true || indexed=false
+filters="${_GET[f]}"
+debug "FILTERS: $filters"
+
+present_filter(){
+  printf %s\\n "$*" \
+  | sed -r 's;(^|!|\^|\|)([^!\^\|:]+:);\1;g;s;\^;\n;g' \
+  | sort -r \
+  | sed -r '$q;s;$; \&amp\; ;g'
+}
+
+if [ -n "$search" ]; then
+  TITLE="$search by $order"
+elif [ -n $filter ]; then
+  TITLE="$(present_filter "$filter") by $order"
+else
+  TITLE="List by $order"
+fi
+
+category_selected(){
+  cat="${1}:"
+  filter="$2"
+  [ "$cat" = "none:" ] && cat=''
+
+  printf %s "$taglist_filter" \
+  | sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \
+  | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
+  | sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
+}
+
+_printVideo(){
+  info="$1"
+  cache="${info%/*}/.index/${info##*/}.cache"
+  meta="${info%/*}/.index/${info##*/}.meta"
+
+  if [ "$cache" -ont "$meta" ]; then
+    cat "$cache"
+  else
+    videofile="$info"
+    thumb="${info%/*}/.index/${info##*/}.jpg"
+    [ -f "$thumb" ] || genthumb "$videofile" "$thumb"
+    [ -f "$meta"  ] || genmeta "$videofile" "$meta"
+
+    { read -r length width height filename
+      read -r tags
+    } <"$meta"
+    length=$(validate "$length" '[0-9]+' 0)
+    width=$(validate "$width" '[0-9]+' 0)
+    height=$(validate "$height" '[0-9]+' 0)
+
+    video="$(urlsafe "$info")"
+    thumb="$(urlsafe "$directory/.index/${info##*/}.jpg")"
+    linkinfo="$(urlsafe "${directory%/}/${info##*/}")"
+    htmlinfo="$(htmlsafe "${info##*/}")"
+    attrinfo="$(attribsafe "$info")"
+
+    minutes="$(printf "%d:%02d" $(($length / 60)) $(($length % 60)) )"
+
+    tee "$cache" <<VIDEOend
+      <li id="$attrinfo" class="thumb">
+        <button class="watchlink" name="${linkinfo}" formaction="?action=watch&l=${linkinfo}">
+          <img src="$thumb" alt="Preview not yet available">
+        </button>
+        <h2><a href="?action=watch&l=${linkinfo}">${htmlinfo}</a></h2>
+        
+        <input type="checkbox" name="tagsel" value="${htmlinfo}">
+        <span class="info property">${minutes}min</span>
+        <span class="info property">${width}x${height}</span>
+       $(printf %s "$tags" |sed -r 's:\|*([^|]+)\|*: <span class="info tag">\1</span>:g')
+      </li>
+VIDEOend
+  fi
+}
+
+genlist(){
+  case "$order" in
+    Date)   find "${_DATA}"/videos/ -maxdepth 1 -mindepth 1 -printf '%T@ %f\n' |sort -r |cut -d\  -f2- |egrep -i "$file_pattern";;
+    Length) sed -sn 1p "${_DATA}"/meta/*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';;
+    Name)   find "${_DATA}"/videos/ -maxdepth 1 -mindepth 1 -printf     '%f\n' |sort |egrep -i "$file_pattern";;
+  esac
+}
+
+selectionlist() {
+  cachebase="?o=${order}&s=${search//\//}&f=${filter//\//}"
+  cache="${_DATA}/cache/${cachebase}"
+  if [ -s "$cache" -a "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
+    cat "$cache"
+  else
+    filterex="s;^([0-9]+\t){3}(.+)\n.*$;\2;p"
+    printf '%s\n' "$filter" |tr '^' '\n' \
+    | sed -r 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g' \
+    | while read each; do
+      [ "${each:0:1}" = '!' ] && filterex="/^[^\n]+\n(.*\|)?(${each#?})(\|.*)?$/d;{${filterex}}" \
+                              || filterex="/^[^\n]+\n(.*\|)?(${each})(\|.*)?$/{${filterex}}"
+    done
+      
+    genlist \
+    | if [ -n "$search" ] ; then
+      debug "Applying search: ${search}"
+      xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
+      | xargs -d '\n' egrep -sil "$search" \
+      | sed -r 's;^.*/;;;s;\.meta$;;'
+    elif [ -n "$filter" ]; then
+      debug "Applying filters: ${filter} ++ ${filterex}"
+      xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
+      | xargs -d '\n' sed -srn ":a;N;2!ba;{${filterex}}"
+    else
+      debug "No search or filtering"
+      cat
+    fi \
+    | tee "$cache"
+  fi
+}
+
+thumblist() {
+  selectionlist \
+  | sed -n "$page,$(($page + $pagesize - 1))p" \
+  | while read line; do
+    _printVideo "$line"
+  done
+}
+
+pagecount() {
+  printf "$(( $(selectionlist | wc -l) / $pagesize + 1 ))"
+}
+
+filelist(){
+  debug "Filelist with dir = $directory"
+
+  [ -n "${directory#/}" ] && printf %s "<a class='file directory' href='?p=browse&d=$(urlsafe "${directory%/*}")'>..</a>"
+
+  find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type d \
+  | grep -v '.index' \
+  | sort \
+  | while read dir; do
+    name="${dir##*/}"
+    printf %s "<a class='file directory' href='?p=browse&d=$(urlsafe "${directory%/}/$name")'>$(htmlsafe "$name")</a>"
+  done
+
+  find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type f \
+  | grep -E "$file_pattern" \
+  | sort \
+  | while read -r file; do
+    name="${file##*/}"
+    $indexed && _printVideo "$file" \
+    || printf '<a class="file video" href="?action=watch&l=%s">%s</a>' \
+              "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")"
+  done
+
+  find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type f \
+  | grep -vE "$file_pattern" \
+  | sort \
+  | while read -r file; do
+    name="${file##*/}"
+    printf '<span class="file plain">%s</span>' "$(htmlsafe "$name")"
+  done
+}
+
diff --git a/templates/browse.html.sh b/templates/browse.html.sh
new file mode 100755 (executable)
index 0000000..8bf29a3
--- /dev/null
@@ -0,0 +1,95 @@
+# Copyright 2017 Paul Hänsch
+#
+# This file is part of Serve0
+# 
+# Serve0 is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# Serve0 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with Serve0  If not, see <http://www.gnu.org/licenses/>. 
+
+cat <<EOF
+
+  <input type=radio name=topmenu id=btn_search checked><label for=btn_search>Search</label>
+  <form class="panel" id="search" action="?" method="get" accept-charset="UTF-8">
+    <input type="text" name="s" value="$search" placeholder="Search">
+
+    <select class="order" size="1" name="o" id="o1">
+      <option class="label" selected disabled>Order by</option>
+      <option>Name</option>
+      <option>Date</option>
+      <option>Length</option>
+    </select>
+    <!-- input type="submit" name="submit" value="Find" -->
+
+    <a class="panel clearsearch" href="?">Clear</a>
+  </form>
+
+  <input type=radio name=topmenu id=btn_advfilter><label for=btn_advfilter>Advanced</label>
+  $(. $_EXEC/templates/advfilter.html.sh)
+
+  <input type=radio name=topmenu id=btn_preferences><label for=btn_preferences>Preferences</label>
+  $(. $_EXEC/templates/preferences.html.sh)
+
+  <input type=radio name=topmenu id=btn_morelinks><label for=btn_morelinks>{+}</label>
+  <div class="panel switchable top" id="morelinks">
+    <a class="panel toggle" href="#">Hide</a>
+
+    <a class="panel" href="?p=playctl">Player</a>
+  </div>
+
+  <form action="?action=multitag" method="post" accept-charset="UTF-8">
+    <input type="hidden" name="o" value="${order}">
+    <input type="hidden" name="s" value="${search}">
+    <input type="hidden" name="f" value="${filter}">
+    <input type="hidden" name="pn" value="${page}">
+
+    <ul id="thumblist">
+EOF
+
+  filelist
+
+  pages="$(
+  seq 1 $(pagecount) \
+  | while read pn; do
+    plink="$(($pn * $pagesize - $pagesize + 1))"
+    
+    case "$plink" in
+      $(($page - $pagesize))) class=previous;;
+      $page) class=current;;
+      $(($page + $pagesize))) class=next;;
+      * ) class='';;
+    esac
+  
+    printf '<a class="%s" href="?%spn=%s">%s</a>\n' "$class" "$page_link" "$plink" "$pn"
+  done
+  )"
+
+cat <<EOF
+    </ul>
+    $(. $_EXEC/templates/tagger.html.sh)
+  </form>
+
+  <div class="panel" id="foot">
+    $( $indexed \
+       && printf '<a class="panel toggle" href="#tagger">Add Tags</a>' \
+       || printf '<a class="panel" href="?action=dirindex&d=%s">Spawn Index</a>' "$(urlsafe "$directory")"
+    )
+    <a class="panel toggle" href="#">⇧</a>
+
+    <div class="pagination_nav">
+      <label>Page:</label>
+      ${pages}
+    </div>
+  </div>
+
+EOF
+
+# vi:set filetype=html:
index e6552fdcd95e9aa7417a375a7254d1bafab86c0c..ed41b3ac08da1ec08d72148fba4ea71c292c55bf 100755 (executable)
@@ -42,7 +42,7 @@ cat <<EOF
   <div class="panel switchable top" id="morelinks">
     <a class="panel toggle" href="#">Hide</a>
 
-    <a class="panel treeview" href="?p=tree">Browse Folders</a>
+    <a class="panel treeview" href="?p=browse">Browse Folders</a>
     <a class="panel" href="?p=playctl">Player</a>
   </div>
 
index e43beedb1966521d9b371bb8843ce281c3350b65..9152db4e4f0f637d9819c2d61c616ecb4dcc2e05 100755 (executable)
@@ -29,7 +29,7 @@ cat <<EOF
   </select>
   <!-- input type="submit" name="submit" value="Find" -->
 
-  <a class="panel" href="${info:+?p=list&amp;${page_this}}${directory:+?p=tree&amp;d=${directory}&amp;${page_this}}#$(urlsafe $info)">Dismiss</a>
+  <a class="panel" href="${info:+?p=list&amp;${page_this}}${directory:+?p=browse&amp;d=${directory}&amp;${page_this}}#$(urlsafe $info)">Dismiss</a>
 </form>
 
 <input type=radio name=topmenu id=btn_playctl><label for=btn_playctl>Audio</label>
@@ -55,7 +55,7 @@ cat <<EOF
   <a class="panel toggle" href="#">Hide</a>
 
   <a class="panel listview" href="?p=list">Index view</a>
-  <a class="panel treeview" href="?p=tree">Browse Folders</a>
+  <a class="panel treeview" href="?p=browse">Browse Folders</a>
 </div>
 
 
index 099916ca734d35584f8152392e9359b50f13f479..92dfddab92c3f72d34590acec6abdd7deac7a047 100755 (executable)
@@ -42,7 +42,7 @@ cat <<EOF
     <a class="panel toggle" href="#">Hide</a>
 
     <a class="panel listview" href="?p=list">Index view</a>
-    <a class="panel treeview" href="?p=tree">Browse Folders</a>
+    <a class="panel treeview" href="?p=browse">Browse Folders</a>
     <a class="panel" href="?p=playctl">Player</a>
   </div>
 
@@ -53,7 +53,7 @@ cat <<EOF
 
   <div class="panel" id="foot">
     <a class="panel toggle" href="#preferences">Preferences</a>
-    <a class="panel treeview" href="?p=tree">Browse Folders</a>
+    <a class="panel treeview" href="?p=browse">Browse Folders</a>
   </div>
 
   $(. $_EXEC/templates/preferences.html.sh)
index 8c22d6a6983fa61442b8883ae9e002b6114b210b..c0a41193e4f827d00a1702b1d43940ea6428a09c 100755 (executable)
@@ -28,7 +28,7 @@ cat <<EOF
   </select>
   <!-- input type="submit" name="submit" value="Find" -->
 
-  <a class="panel" href="${info:+?p=list&amp;${page_this}}${directory:+?p=tree&amp;d=${directory}&amp;${page_this}}#$(urlsafe $info)">Dismiss</a>
+  <a class="panel" href="${info:+?p=list&amp;${page_this}}${directory:+?p=browse&amp;d=${directory}&amp;${page_this}}#$(urlsafe $info)">Dismiss</a>
 </form>
 
 <input type=radio name=topmenu id=btn_preferences><label for=btn_preferences>Preferences</label>
@@ -39,7 +39,7 @@ cat <<EOF
   <a class="panel toggle" href="#">Hide</a>
 
   <a class="panel listview" href="?p=list">Index view</a>
-  <a class="panel treeview" href="?p=tree">Browse Folders</a>
+  <a class="panel treeview" href="?p=browse">Browse Folders</a>
 </div>