]> git.plutz.net Git - serve0/commitdiff
improved browse page (code improvements, page enumeration)
authorpaul <paul@plutz.net>
Sat, 14 Jan 2017 01:12:35 +0000 (01:12 +0000)
committerpaul <paul@plutz.net>
Sat, 14 Jan 2017 01:12:35 +0000 (01:12 +0000)
svn path=/trunk/; revision=168

globals.sh
pages/browse.sh
templates/browse.html.sh

index fed521567fc0060538cd70bda2527a44c5ea5d63..d6dcefdad5f669a2a4823623e1399793794b3830 100755 (executable)
@@ -22,7 +22,7 @@ file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmv
 
 data_dirs cache meta mp4 videos thumbs trash transcoded
 
-PAGE="${_GET[p]:-${PAGE:-list}}"
+PAGE="${_GET[p]:-${PAGE:-browse}}"
 treeroot="${treeroot:-${_DATA}}"
 
 _GET[o]=$( validate "${_GET[o]}"  'Name|Date|Length' Name)
index 95741af55f1542e952e2c9af476a27f19365fabc..9b3e866d5ef55a809e93648ae1938db0d639eb84 100755 (executable)
@@ -53,47 +53,41 @@ category_selected(){
 }
 
 _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>
+  name="$1"
+
+  video="${treeroot%/}/${directory%/}/${name}"
+  thumb="${treeroot%/}/${directory%/}/.index/${name}.jpg"
+   meta="${treeroot%/}/${directory%/}/.index/${name}.meta"
+
+  [ -f "$thumb" ] || genthumb "$video" "$thumb"
+  [ -f "$meta"  ] || genmeta "$video" "$meta"
+
+  { read -r length width height filename
+    read -r tags
+  } <"$meta"
+  read length width height <<-EOF
+       $(validate "$length $width $height" '[0-9]+ [0-9]+ [0-9]+' "0 0 0")
+       EOF
+
+  location="$(attribsafe "${directory%/}/${name}")"
+  thumblocation="$(attribsafe "${directory%/}/.index/${name}.jpg")"
+  display="$(htmlsafe "$name")"
+
+  minutes="$(printf "%d:%02d" $(($length / 60)) $(($length % 60)) )"
+
+  cat <<VIDEOend
+    <li id="${location}" class="thumb">
+      <button class="watchlink" name="${location}" formaction="?action=watch&l=${location}">
+        <img src="${thumblocation}" alt="Preview not yet available">
+      </button>
+      <h2><a href="?action=watch&l=${location}">${display}</a></h2>
+      
+      <input type="checkbox" name="tagsel" value="${location}">
+      <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(){
@@ -136,47 +130,44 @@ selectionlist() {
   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(){
+  dir="${treeroot%/}/${directory#/}"
+
+  find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -printf "directory %P\n" \
+  | sort
+  find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -printf "video %P\n" \
+  | grep -iE "$file_pattern" \
+  | sort
+  find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -printf "plain %P\n" \
+  | grep -viE "$file_pattern" \
+  | sort
 }
 
-filelist(){
+thumblist(){
   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")"
+  filelist \
+  | sed -n "$page,$(($page + $pagesize - 1))p" \
+  | while read -r type name; do
+    case $type in
+      directory)
+        printf '<a class="file directory" href="?p=browse&d=%s">%s</a>\n' \
+               "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")"
+        ;;
+      video)
+        $indexed && _printVideo "$name" \
+        || printf '<a class="file video" href="?action=watch&l=%s">%s</a>\n' \
+                  "$(urlsafe "${directory%/}/$name")" "$(htmlsafe "$name")"
+        ;;
+      plain)
+        printf '<span class="file plain">%s</span>\n' "$(htmlsafe "$name")"
+        ;;
+    esac
   done
 }
 
+pagecount() {
+  printf "$(( $(filelist | wc -l) / $pagesize + 1 ))"
+}
index 8bf29a3a24b348c672d5608de49906709c0250cd..a061ed12b54c85890681d9f198abb5639c113f25 100755 (executable)
@@ -54,7 +54,7 @@ cat <<EOF
     <ul id="thumblist">
 EOF
 
-  filelist
+  thumblist
 
   pages="$(
   seq 1 $(pagecount) \