]> git.plutz.net Git - serve0/commitdiff
new folder browse section
authorpaul <paul@plutz.net>
Mon, 5 Oct 2015 23:44:08 +0000 (23:44 +0000)
committerpaul <paul@plutz.net>
Mon, 5 Oct 2015 23:44:08 +0000 (23:44 +0000)
svn path=/trunk/; revision=94

actions/watch.sh
globals.sh
pages/common.sh
pages/list.sh
pages/tree.sh [new file with mode: 0755]
pages/view.sh
templates/common.css.sh
templates/list.html.sh
templates/tree.html.sh [new file with mode: 0755]
templates/view.html.sh

index 2a91ce89b751f976d128f30787c8c21023f96aaa..d0987177c6e157318b6b46ec4e35ed773100ca1a 100755 (executable)
@@ -2,17 +2,19 @@
 
 cgi_refdata
 info="${_GET[i]}"
+location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
 order="${_REF[o]}"
 search="${_REF[s]}"
 filter="${_REF[f]}"
 page="${_REF[pn]}"
 
 watch_link=''
-[ -n "$info" ]   && watch_link="i=$(urlsafe "${info}")&"
-[ -n "$order" ]  && watch_link="${watch_link}o=${order}&"
-[ -n "$search" ] && watch_link="${watch_link}s=${search}&"
-[ -n "$filter" ] && watch_link="${watch_link}f=${filter}&"
-[ -n "$page" ]   && watch_link="${watch_link}pn=${page}"
+[ -n "$location" ] && watch_link="l=$(urlsafe "${location}")&"
+[ -n "$info" ]     && watch_link="i=$(urlsafe "${info}")&"
+[ -n "$order" ]    && watch_link="${watch_link}o=${order}&"
+[ -n "$search" ]   && watch_link="${watch_link}s=${search}&"
+[ -n "$filter" ]   && watch_link="${watch_link}f=${filter}&"
+[ -n "$page" ]     && watch_link="${watch_link}pn=${page}"
 
 meta="${_DATA}/meta/$info.meta"
 head -n1 "$meta" |read length width height filename
@@ -47,7 +49,11 @@ case "${_COOKIE[watch]}" in
     redirect "$videourl"
   ;;
   server)
-    DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null &
+    if [ -n "$info" ]; then
+      DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${_DATA}/videos/$info" >/dev/null 2>/dev/null &
+    elif [ -n "$location" ]; then
+      DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1006 nohup /usr/bin/mplayer -ao pulse --quiet "${treeroot%/}/${location#/}" >/dev/null 2>/dev/null &
+    fi
     redirect "$HTTP_REFERER"
   ;;
   *) redirect "?p=view&${watch_link}"
index 1bc1ae92bbcbdbba139015894a12f71c4b9a8f0f..4b4590f7cc549067e9e06b63e1f0da930102fa3b 100755 (executable)
 # along with Serve0.  If not, see <http://www.gnu.org/licenses/>. 
 
 alias _wiki="stx2any --no-template --link-abbrevs --quote -T html"
-file_pattern='^.*(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmvb)$'
+file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmvb)$'
 
 data_dirs cache meta mp4 videos thumbs trash by_length transcoded
 
 PAGE="${_GET[p]:-${PAGE:-list}}"
+treeroot="${treeroot:-${_DATA}}"
 
 _GET[o]=$( validate "${_GET[o]}"  'Name|Date|Length' Name)
 _GET[pn]=$(validate "${_GET[pn]}" '[1-9][0-9]*' 1)
index 6b597d5abeb1d6b84cdb4f662462067632ff1fee..cb4117b5a9949fae419fdb1c856302198a608fda 100755 (executable)
@@ -39,6 +39,11 @@ taglist=$(
   done |sort -u |grep -xv '' |tee ${_DATA}/cache/taglist
 )
 
+list_categories(){
+  echo none
+  printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
+}
+
 genthumb(){
   videofile="$1"
   thumb="$2"
@@ -53,88 +58,3 @@ genmeta(){
 
   "${_EXEC}"/helpers/genmeta.sh "$videofile" "$meta" >/dev/null
 }
-
-_printVideo(){
-  info="$1"
-  cache="${_DATA}/cache/$info.cache"
-  meta="${_DATA}/meta/$info.meta"
-
-  if [ "$cache" -nt "$meta" ]; then
-    cat "$cache"
-  else
-    videofile="${_DATA}/videos/$info"
-    thumb="${_DATA}/thumbs/${info}.jpg"
-    [ -r "$thumb" ] || genthumb "$videofile" "$thumb"
-    [ -r "$meta"  ] || genmeta "$videofile" "$meta"
-
-    head -n1 "$meta" |read length width height filename
-    [ -z "$length" ] && length=0
-    [ -z "$width"  ] && width=0
-    [ -z "$height" ] && height=0
-
-    tags="$(sed -n 2p "$meta")"
-    video="$(urlsafe "videos/$info")"
-    thumb="$(urlsafe "thumbs/$info.jpg")"
-    linkinfo="$(urlsafe "$info")"
-    htmlinfo="$(htmlsafe "$info")"
-
-    [ "$(($length % 60))" -lt 10 ] && minutes="$(($length / 60)):0$(($length % 60))" \
-                                   || minutes="$(($length / 60)):$(($length % 60))"
-
-    tee "$cache" <<VIDEOend
-      <li class="thumb">
-        <a class="watchlink" name="${linkinfo}" href="?action=watch&i=${linkinfo}">
-          <img src="$thumb" alt="Preview not yet available">
-        </a>
-        <h2>${htmlinfo}</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)   ls -c "${_DATA}"/videos/ |egrep -i "$file_pattern";;
-    Length) sed -sn 1p "${_DATA}"/meta/*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';;
-    Name)   printf '%s\n' "${_DATA}"/videos/* |sed -r 's;^.*/;;;';;
-  esac
-}
-
-thumblist() {
-  cache="${_DATA}/cache/${pagesize}?o=${order}&s=${search}&f=${filter}&pn=${page}"
-  if [ "$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' \
-    | 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 \
-    | sed -n "$page,$(($page + $pagesize - 1))p" \
-    | tee "$cache"
-  fi \
-  | while read line; do
-    _printVideo "$line"
-  done
-}
index 94d12cecf934f132dfa49bd4f8be6af0c5bf572a..2d3cbf3bad443f2eb5c0aec98ee6c8afbc60dca9 100755 (executable)
@@ -31,11 +31,6 @@ quicklinks(){
   echo $output
 }
 
-list_categories(){
-  echo none 
-  printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
-}
-
 category_selected(){
   cat="${1}:"
   filter="$2"
@@ -46,3 +41,88 @@ category_selected(){
   | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
   | sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
 }
+
+_printVideo(){
+  info="$1"
+  cache="${_DATA}/cache/$info.cache"
+  meta="${_DATA}/meta/$info.meta"
+
+  if [ "$cache" -nt "$meta" ]; then
+    cat "$cache"
+  else
+    videofile="${_DATA}/videos/$info"
+    thumb="${_DATA}/thumbs/${info}.jpg"
+    [ -r "$thumb" ] || genthumb "$videofile" "$thumb"
+    [ -r "$meta"  ] || genmeta "$videofile" "$meta"
+
+    head -n1 "$meta" |read length width height filename
+    [ -z "$length" ] && length=0
+    [ -z "$width"  ] && width=0
+    [ -z "$height" ] && height=0
+
+    tags="$(sed -n 2p "$meta")"
+    video="$(urlsafe "videos/$info")"
+    thumb="$(urlsafe "thumbs/$info.jpg")"
+    linkinfo="$(urlsafe "$info")"
+    htmlinfo="$(htmlsafe "$info")"
+
+    [ "$(($length % 60))" -lt 10 ] && minutes="$(($length / 60)):0$(($length % 60))" \
+                                   || minutes="$(($length / 60)):$(($length % 60))"
+
+    tee "$cache" <<VIDEOend
+      <li class="thumb">
+        <a class="watchlink" name="${linkinfo}" href="?action=watch&i=${linkinfo}">
+          <img src="$thumb" alt="Preview not yet available">
+        </a>
+        <h2>${htmlinfo}</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)   ls -c "${_DATA}"/videos/ |egrep -i "$file_pattern";;
+    Length) sed -sn 1p "${_DATA}"/meta/*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';;
+    Name)   printf '%s\n' "${_DATA}"/videos/* |sed -r 's;^.*/;;;';;
+  esac
+}
+
+thumblist() {
+  cache="${_DATA}/cache/${pagesize}?o=${order}&s=${search}&f=${filter}&pn=${page}"
+  if [ "$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' \
+    | 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 \
+    | sed -n "$page,$(($page + $pagesize - 1))p" \
+    | tee "$cache"
+  fi \
+  | while read line; do
+    _printVideo "$line"
+  done
+}
diff --git a/pages/tree.sh b/pages/tree.sh
new file mode 100755 (executable)
index 0000000..40a50cc
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/zsh
+
+# Copyright 2014, 2015 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
+
+directory="$(invalidate "${_GET[d]}" '(.*/)?\.\.(/.*)?|' /)"
+
+filelist(){
+  debug "Filelist with dir = $directory"
+
+  [ -n "${directory#/}" ] && printf %s "<a class='file directory' href='?p=tree&d=$(urlsafe "${directory%/*}")'>..</a>"
+
+  find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type d \
+  | sort \
+  | while read dir; do
+    name="${dir##*/}"
+    printf %s "<a class='file directory' href='?p=tree&d=$(urlsafe "${directory%/}/$name")'>$(htmlsafe "$name")</a>"
+  done
+
+  find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type f \
+  | sort \
+  | while read file; do
+    name="${file##*/}"
+    printf %s\\n "$name" |egrep -q "$file_pattern" && \
+       printf %s "<a class='file video' href='?action=watch&l=$(urlsafe "${directory%/}/$name")'>$(htmlsafe "$name")</a>" \
+    || printf %s "<span class='file plain'>$(htmlsafe "$name")</span>"
+  done
+}
+
index 639bf0af734bf4ecef48d9635322c906bd0aba37..97b8e37ea672b98e18e69666e47cdf59e8402895 100755 (executable)
 # 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/list.sh
+. $_EXEC/pages/tree.sh
+
 info="${_GET[i]}"
-. $_EXEC/pages/common.sh
+location="$(invalidate "${_GET[l]}" '(.*/)?\.\.(/.*)?|' /)"
+directory="${location%/*}"
 
 meta="${_DATA}/meta/$info.meta"
-video="${_DATA}/videos/$info"
+[ -n "$info" ] && video="${_DATA}/videos/$info" \
+               || video="${treeroot%/}/${location#/}"
 tags="$(sed -n '2p' "$meta")"
 description="$(sed -n '3,$p' "$meta")"
 length=0; width=0; height=0;
-eval $(mplayer -noconsolecontrols -input file=/dev/null -slave -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null\
-| sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;')
+
+debug "Analysing video: $video"
+echo '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \
+| sort \
+| sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p;
+           s:ID_VIDEO_HEIGHT=(.*):\1:p;
+           s:ID_VIDEO_WIDTH=(.*):\1:p;' \
+| tr '\n' ' ' \
+| read length height width 2>/dev/null
+
 video="videos/$info"
+[ -n "$info" ] && video="videos/$info" \
+               || video="${location#/}"
index 233e81d72d9cef61524657e75f600d6c86f688a9..cfc84e7420cb174e62957075c7e9a8cf7d28d58e 100755 (executable)
@@ -215,7 +215,6 @@ a.panel {
   word-wrap: break-word;
 }
 
-
 /* == Thumblist == */
 
 #thumblist {
@@ -229,14 +228,14 @@ a.panel {
   text-align: left;
   width: 90%;
   padding: 0 .5em;
-  margin: auto;
+  margin: .5%;
   margin-bottom: .75em;
   vertical-align: top;
   word-wrap: break-word;
 }
-@media (min-width: 480px){#thumblist .thumb{width: 49.5%;}}
-@media (min-width: 640px){#thumblist .thumb{width: 33%;}}
-@media (min-width: 1024px){#thumblist .thumb{width: 256px;}}
+@media (min-width: 460px){#thumblist .thumb{width: 48%;}}
+@media (min-width: 620px){#thumblist .thumb{width: 32%;}}
+@media (min-width: 1004px){#thumblist .thumb{width: 250px; margin: 2px;}}
 
 #thumblist .thumb img {
   width: 100%;
@@ -257,6 +256,27 @@ a.panel {
   margin: .75em .5em;
 }
 
+/* == Filelist == */
+
+#thumblist .file {
+  color: #000;
+  display: inline-block;
+  text-align: left;
+  width: 90%;
+  padding: .5em .5em;
+  margin: .5%;
+  margin-bottom: .75em;
+  vertical-align: top;
+  word-wrap: break-word;
+}
+@media (min-width: 460px){#thumblist .file{width: 48%;}}
+@media (min-width: 620px){#thumblist .file{width: 32%;}}
+@media (min-width: 1004px){#thumblist .file{width: 250px; margin: 2px;}}
+
+#thumblist .file.directory { background-color: #BBD; }
+#thumblist .file.plain { background-color: #111; color: #777; }
+#thumblist .file.video { background-color: #DBB; }
+
 .panel#tagger .newtag select,
 .panel#tagger .newtag .label{
   display: block;
index 06d4110846aa1ddc7158673d2117b887896308df..a5096d3da65f23e8c582377da1c3afa2dace0262 100755 (executable)
@@ -48,6 +48,7 @@ cat <<EOF
   <div class="panel" id="foot">
     <a class="panel toggle" href="#tagger">Add Tags</a>
     <a class="panel toggle" href="#preferences">Preferences</a>
+    <a class="panel treeview" href="?p=tree">Browse Folders</a>
 
     <div class="pagination_nav">
       <label>Page:</label>
diff --git a/templates/tree.html.sh b/templates/tree.html.sh
new file mode 100755 (executable)
index 0000000..9ddffbe
--- /dev/null
@@ -0,0 +1,42 @@
+# Copyright 2014, 2015 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
+  <form class="panel" id="search" action="?" method="get" accept-charset="UTF-8">
+    <input type="text" name="s" value="$search" placeholder="Search">
+    <input type="submit" name="submit" value="Find">
+
+    <a class="panel clearsearch" href="?p=tree">Clear All</a>
+  </form>
+
+  <form action="?action=multitag&${page_this}" method="post" accept-charset="UTF-8">
+    <ul id="thumblist">
+      $(filelist)
+    </ul>
+    $(. $_EXEC/templates/tagger.html.sh)
+  </form>
+
+  <div class="panel" id="foot">
+    <a class="panel toggle" href="#tagger">Add Tags</a>
+    <a class="panel toggle" href="#preferences">Preferences</a>
+    <a class="panel listview" href="?p=list">Index view</a>
+  </div>
+
+  $(. $_EXEC/templates/preferences.html.sh)
+EOF
+
+# vi:set filetype=html:
index e622658c0bc83684036486bfbd80376e43fe1566..c92db05282b050f857975d8bdd8deba0f9d063f1 100755 (executable)
@@ -39,7 +39,7 @@ cat <<EOF
 </form>
 
 <div class="panel" id="videoview">
-  <a href="?p=list&amp;${page_this}" class="panel">Dismiss</a>
+  <a href="${info:+?p=list&amp;${page_this}}${info:-?p=tree&amp;d=${directory}&amp;${page_this}}" class="panel">Dismiss</a>
     <h1>$info</h1>
 
   <div class="video">
@@ -99,7 +99,7 @@ cat <<EOF
 
 <form>
   <ul id="thumblist">
-    $(thumblist)
+    $([ -n "$info" ] && thumblist || filelist)
   </ul>
 </form>