}
_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(){
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 ))"
+}