fi
}
-_by_name(){ find ${_DATA}/videos/ -mindepth 1 -maxdepth 1 -printf '%f\n' |sort |egrep -i "$file_pattern" }
-_by_date(){ ls -c ${_DATA}/videos/ |egrep -i "$file_pattern" }
-_by_length(){ find ${_DATA}/by_length/ -mindepth 1 -maxdepth 1 -printf '%f\n' |sort |sed -r 's:[0-9]{5} - ::' }
+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;;';;
+ *) printf '%s\n' "${_DATA}/meta/"*meta |sed -r 's;^.*/;;;s;\.meta$;;';;
+ esac
+}
thumblist() {
cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&pn=${page}"
if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then
cat "$cache"
else
- filterex="q0"
- for each in $(sed 's,\^, ,g' <<<"$filter"); do
- if egrep -q '^!' <<<"$each"; then
- this="$(sed 's,^!,,' <<<"$each")"
- filterex="/${this}/q1;{${filterex}}"
- else
- filterex="/${each}/{${filterex}}"
- fi
+ 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
-
- case "$order" in
- Date) genlist="_by_date"
- ;;
- Length) genlist="_by_length"
- ;;
- *) genlist="_by_name"
- ;;
- esac
- if [ -n "$search" ] ; then
- #$genlist |egrep -i "$search"
- $genlist |sed -rn 's:^(.+)$:'"${_DATA}"'/meta/\1'.meta':p' |xargs -d\\n egrep -sil "$search" |sed -rn 's:^(.*/)+([^/]+)\.meta$:\2:p'
+ genlist \
+ | if [ -n "$search" ] ; then
+ xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
+ | xargs -d '\n' egrep -sil "$search" \
+ | sed -r 's;^.*/;;;s;\.meta$;;'
elif [ "$filterex" != "q0" ]; then
- $genlist |while read video; do
- [ -r "${_DATA}/meta/$video.meta" ] && sed -rn "2{$filterex;q1}" "${_DATA}/meta/$video.meta" && printf '%s\n' "$video"
- done
+ xargs -d '\n' printf "${_DATA}/meta/%s.meta\n" \
+ | xargs -d '\n' sed -srn ":a;N;2!ba;{${filterex}}"
else
- $genlist
- fi |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p |tee "$cache"
- fi | while read line; do
+ cat
+ fi \
+ | sed -n "$(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p" \
+ | tee "$cache"
+ fi \
+ | while read line; do
_printVideo "$line"
done
}