From 47b905d14103c01625d16fe557e63e34317c6453 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 5 Oct 2015 23:44:08 +0000 Subject: [PATCH] new folder browse section svn path=/trunk/; revision=94 --- actions/watch.sh | 18 ++++++--- globals.sh | 3 +- pages/common.sh | 90 +++-------------------------------------- pages/list.sh | 90 ++++++++++++++++++++++++++++++++++++++--- pages/tree.sh | 45 +++++++++++++++++++++ pages/view.sh | 23 +++++++++-- templates/common.css.sh | 30 +++++++++++--- templates/list.html.sh | 1 + templates/tree.html.sh | 42 +++++++++++++++++++ templates/view.html.sh | 4 +- 10 files changed, 238 insertions(+), 108 deletions(-) create mode 100755 pages/tree.sh create mode 100755 templates/tree.html.sh diff --git a/actions/watch.sh b/actions/watch.sh index 2a91ce8..d098717 100755 --- a/actions/watch.sh +++ b/actions/watch.sh @@ -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}" diff --git a/globals.sh b/globals.sh index 1bc1ae9..4b4590f 100755 --- a/globals.sh +++ b/globals.sh @@ -18,11 +18,12 @@ # along with Serve0. If not, see . 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) diff --git a/pages/common.sh b/pages/common.sh index 6b597d5..cb4117b 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -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" < - - Preview not yet available - -

${htmlinfo}

- - - ${minutes}min - ${width}x${height} - $(printf %s "$tags" |sed -r 's:\|*([^|]+)\|*: \1:g') - -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/list.sh b/pages/list.sh index 94d12ce..2d3cbf3 100755 --- a/pages/list.sh +++ b/pages/list.sh @@ -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 ;;' } + +_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" < + + Preview not yet available + +

${htmlinfo}

+ + + ${minutes}min + ${width}x${height} + $(printf %s "$tags" |sed -r 's:\|*([^|]+)\|*: \1:g') + +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 index 0000000..40a50cc --- /dev/null +++ b/pages/tree.sh @@ -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 . + +. $_EXEC/pages/common.sh + +directory="$(invalidate "${_GET[d]}" '(.*/)?\.\.(/.*)?|' /)" + +filelist(){ + debug "Filelist with dir = $directory" + + [ -n "${directory#/}" ] && printf %s ".." + + find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type d \ + | sort \ + | while read dir; do + name="${dir##*/}" + printf %s "$(htmlsafe "$name")" + 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 "$(htmlsafe "$name")" \ + || printf %s "$(htmlsafe "$name")" + done +} + diff --git a/pages/view.sh b/pages/view.sh index 639bf0a..97b8e37 100755 --- a/pages/view.sh +++ b/pages/view.sh @@ -17,14 +17,29 @@ # You should have received a copy of the GNU Affero General Public License # along with Serve0. If not, see . +. $_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#/}" diff --git a/templates/common.css.sh b/templates/common.css.sh index 233e81d..cfc84e7 100755 --- a/templates/common.css.sh +++ b/templates/common.css.sh @@ -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; diff --git a/templates/list.html.sh b/templates/list.html.sh index 06d4110..a5096d3 100755 --- a/templates/list.html.sh +++ b/templates/list.html.sh @@ -48,6 +48,7 @@ cat < Add Tags Preferences + Browse Folders
diff --git a/templates/tree.html.sh b/templates/tree.html.sh new file mode 100755 index 0000000..9ddffbe --- /dev/null +++ b/templates/tree.html.sh @@ -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 . + +cat < + + + + Clear All + + +
+
    + $(filelist) +
+ $(. $_EXEC/templates/tagger.html.sh) +
+ + + + $(. $_EXEC/templates/preferences.html.sh) +EOF + +# vi:set filetype=html: diff --git a/templates/view.html.sh b/templates/view.html.sh index e622658..c92db05 100755 --- a/templates/view.html.sh +++ b/templates/view.html.sh @@ -39,7 +39,7 @@ cat <
- Dismiss + Dismiss

$info

@@ -99,7 +99,7 @@ cat <
    - $(thumblist) + $([ -n "$info" ] && thumblist || filelist)
-- 2.39.2