4 file_pattern='^.*\.(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|ogv|webm|iso|rmvb)$'
6 . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh"
10 ORDER="$(GET o |grep -m1 -axE 'Date|Name|Length|Group' || printf Name)"
11 LISTSIZE="$(COOKIE pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 60)"
17 SET_COOKIE +$((86400 * 90)) pagesize="$(POST pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 60)"
18 SET_COOKIE +$((86400 * 90)) mode="$(POST mode |grep -m1 -axE 'browse|index' || printf browse)"
19 SET_COOKIE +$((86400 * 90)) fakemp4="$(POST fakemp4 |grep -m1 -axE 'yes' || printf no)"
20 SET_COOKIE +$((86400 * 90)) downscale="$(POST downscale |grep -m1 -axE 'yes' || printf no)"
21 [ "$(POST index)" = "update" ] && touch -cd @0 "${_DATA}/.index/meta.time"
22 REDIRECT "$(POST ref)"
25 bm="$_DATA/.index/bookmarks"
26 . "$_EXEC/cgilite/storage.sh"
28 s="$(POST search |STRING)"; f="$(POST filter |STRING)"
30 grep -avF " search=$s filter=$f${CR}" "$bm" >"$bm.tmp"
31 [ ! "$(POST delete)" ] \
32 && printf '%s search=%s filter=%s\r\n' \
33 "$(POST name |STRING)" "$s" "$f" >>"$bm.tmp"
37 REDIRECT "$(POST ref)"
40 . "$_EXEC/multitag.sh"
41 REDIRECT "$(POST ref)"
43 thumbnail) if [ -f "$_DATA/$PATH_INFO" ]; then
44 . "$_EXEC/cgilite/file.sh"
45 index="$_DATA/${PATH_INFO%/*}/.index"
46 thumb="$index/${PATH_INFO##*/}"; thumb="${thumb%.*}.jpg"
47 if [ -d "$index" -a ! -f "$thumb" ] && { printf %s "$PATH_INFO" |grep -qE -e "${file_pattern}" ;}; then
48 . "$_EXEC/thumbnail.sh"
49 gen_thumb "$_DATA/$PATH_INFO" "$thumb"
54 download) if [ -f "$_DATA/$PATH_INFO" ]; then
55 . "$_EXEC/cgilite/file.sh"
56 fakemp4="$(COOKIE fakemp4)"
57 downscale="$(COOKIE downscale)"
58 downfile="$_DATA/${PATH_INFO%/*}/.transcode/${PATH_INFO%.*}.480p.webm"
59 if [ "$downscale" = yes -a -f "$downfile" ]; then
60 FILE "$downfile" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
62 FILE "$_DATA/$PATH_INFO" "$([ "$fakemp4" = yes ] && printf 'video/mp4')"
66 delete) if [ -f "$_DATA/$PATH_INFO" ]; then
69 advsearch) if [ -d "$_DATA/$PATH_INFO" ]; then
70 . "$_EXEC/advsearch.sh"
73 spawnindex) if [ -d "$_DATA/$PATH_INFO" ]; then
74 if [ "$(POST recursive)" = yes ]; then
75 find "$_DATA/$PATH_INFO" -depth -type d \! -name .index \
76 -exec mkdir -p '{}'/.index \;
78 mkdir -p "$_DATA/$PATH_INFO/.index"
80 REDIRECT "$(POST ref)"
84 if [ -f "$_EXEC/$PATH_INFO" ]; then
85 . "$_EXEC/cgilite/file.sh"
86 FILE "$_EXEC/$PATH_INFO"
88 elif [ -f "$_DATA/$PATH_INFO" ]; then
91 elif [ -d "$_DATA/$PATH_INFO" ]; then
95 printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n'