]> git.plutz.net Git - serve0/commitdiff
tagging engine
authorpaul <paul@plutz.net>
Sat, 6 Sep 2014 19:04:08 +0000 (19:04 +0000)
committerpaul <paul@plutz.net>
Sat, 6 Sep 2014 19:04:08 +0000 (19:04 +0000)
svn path=/trunk/; revision=5

actions/filter.sh
actions/meta.sh [new file with mode: 0755]
actions/multitag.sh [new file with mode: 0755]
helpers/genall.sh [new file with mode: 0755]
helpers/genmeta.sh [new file with mode: 0755]
helpers/genthumb.sh [new file with mode: 0755]
pages/videoview.sh
templates/videoview.html.sh
templates/view.html.sh

index 84bd84178c51d0a911d2aa27e28db74d2ca5b3b1..94b87f2c7ce6036f54b4e5458cba35344bc6f313 100755 (executable)
@@ -33,5 +33,5 @@ if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
 done
 fi
 
-echo "?o=${order}&f=${filters}" >>${DATA}/meta/recent
+echo "?o=${order}&f=${filters}" >>${_DATA}/meta/recent
 echo -n "Location: ?o=${order}&f=${filters}\n\n"
diff --git a/actions/meta.sh b/actions/meta.sh
new file mode 100755 (executable)
index 0000000..b5fbe51
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/zsh
+
+info="$_GET[\"i\"]"
+file="{$DATA}/meta/$info.meta"
+
+if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
+(head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do
+  if (egrep -xq 'length=[0-9]{1,5}' <<<"${line}"); then
+    length="$(cut -d= -f2 <<<"${line}")"
+  elif (egrep -xq 'width=[0-9]{1,5}' <<<"${line}"); then
+    width="$(cut -d= -f2 <<<"${line}")"
+  elif (egrep -xq 'height=[0-9]{1,5}' <<<"${line}"); then
+    height="$(cut -d= -f2 <<<"${line}")"
+  elif (egrep -xq 'tag=.+' <<<"${line}"); then
+    tag="$(sed -r 's:^tag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
+    tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
+    tagacc="$tag|$tagacc"
+  elif (egrep -xq 'tags=.+' <<<"${line}"); then
+    tags="$(sed -r 's:^tags=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
+    tags="$(echo -e "${tags}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
+  elif (egrep -xq 'description=.+' <<<"${line}"); then
+    description="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
+    description="$(echo -e "${description}" |sed 's/\r//g;s/\\/\\\\/g;s/</\&lt\;/g;s/>/\&gt\;/g')"
+  elif (egrep -xq 'trash=.+' <<<"${line}"); then
+    trash="true"
+  elif (egrep -xq 'cancel=.+' <<<"${line}"); then
+    cancel="true"
+  elif (egrep -xq 'f=.+' <<<"${line}"); then
+    filter="$(cut -d= -f2- <<<"${line}")"
+  elif (egrep -xq 's=.+' <<<"${line}"); then
+    search="$(cut -d= -f2- <<<"${line}")"
+  elif (egrep -xq 'p=.+' <<<"${line}"); then
+    page="$(cut -d= -f2- <<<"${line}")"
+  elif (egrep -xq 'o=.+' <<<"${line}"); then
+    order="$(cut -d= -f2- <<<"${line}")"
+  fi
+done
+fi
+
+[ -z "$cancel" ] && if [ "$trash" = "true" ]; then
+  rm "${_DATA}/thumbs/$info.jpg" 2>/dev/null
+  mv "${_DATA}/videos/$info" "${_DATA}/meta/$info.meta" "${_DATA}/trash/" 2>/dev/null
+  rm "${_DATA}/cache/$info.cache" 2>/dev/null
+  rm ${_DATA}/cache/\?* 2>/dev/null
+else
+  echo -e "$length\t$width\t$height\t$info" > "$file"
+  echo -e "${tagacc}${tags}" |tr '\n' '|' >> "$file"
+  echo >>"$file"
+  echo -e "${description}" >> "$file"
+  rm "${_DATA}/cache/$info.cache" 2>/dev/null
+  rm ${_DATA}/cache/\?* 2>/dev/null
+fi
+
+echo -n "Location: index.cgi?i=&p=${page}&s=${search}&f=${filter}&o=${order}#$info\n\n"
diff --git a/actions/multitag.sh b/actions/multitag.sh
new file mode 100755 (executable)
index 0000000..127a64e
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/zsh
+
+addtag(){
+  meta="$1"
+  tag="$2"
+  
+  length=0; width=0; height=0;
+  if [ -r "$meta" ]; then
+    head -n1 "$meta" |read length width height info
+    tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')"
+    description="$(sed -n '3,$p' "$meta")"
+  fi
+  
+  egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags"
+  
+  cat <<EOF >"$meta"
+$length        $width  $height $info
+$tags
+$description
+EOF
+}
+
+n=0
+if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
+(head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do
+  if expr "$line" : "tagsel=" >/dev/null; then
+    n=$(($n + 1))
+    tagsel[$n]="$(echo -e "$(sed -nr 's:(^|&)tagsel=(.*)(&|$):\2:;s:&.*$::;s:\+: :g;s:%:\\x:g;p' <<<"$line" )")"
+  elif expr "$line" : "ctag=" >/dev/null; then
+    tag="$(sed -r 's:^ctag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
+    tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
+    for i in {1..$n}; do
+      addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag"
+      rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null
+    done
+  elif expr "$line" : 'tags=.\+' >/dev/null; then
+    tags="$(sed -r 's:^tags=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
+    tags="$(echo -e "${tags}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
+    for i in {1..$n}; do echo "$tags" |while read tag; do
+      addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag"
+      rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null
+    done; done
+  fi
+done
+fi
+
+rm ${_DATA}/cache/\?* 2>/dev/null
+
+echo -n "Location: index.cgi?${QUERY_STRING}#$info\n\n"
diff --git a/helpers/genall.sh b/helpers/genall.sh
new file mode 100755 (executable)
index 0000000..6aab046
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/zsh
+
+dir="$(dirname $0)"
+genmeta="$dir/genmeta.sh"
+genthumb="$dir/genthumb.sh"
+. "$dir/../constants.sh"
+
+addtag(){
+  meta="$1"
+  info="$(basename "$1" |sed -r 's:^(.+)\.meta$:\1:')"
+  tag="$2"
+  
+  length=0; width=0; height=0;
+  if [ -r "$meta" ]; then
+    head -n1 "$meta" |read length width height info
+    tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')"
+    description="$(sed -n '3,$p' "$meta")"
+  fi
+  
+  egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags"
+  
+  cat <<EOF >"$meta"
+$length        $width  $height $info
+$tags
+$description
+EOF
+}
+
+
+for each in *; do
+if (egrep -q "$file_pattern" <<<"$each"); then
+  echo -n "$each ... Thumb ..."
+  $genthumb "$each" "${each}.jpg"
+  echo -n ' Meta ...'
+  $genmeta "$each" "${each}.meta"
+  echo -n ' Tags ...'
+  for tag in $*; do
+    addtag "${each}.meta" "$tag"
+  done
+  echo ' Done!'
+fi; done
diff --git a/helpers/genmeta.sh b/helpers/genmeta.sh
new file mode 100755 (executable)
index 0000000..805bde1
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/zsh
+
+video="$1"
+meta="$2"
+
+if [ -r "$meta" ]; then
+  tags="$(sed -n 2p "$meta")"
+  description="$(sed -n '3,$p' "$meta")"
+fi
+
+eval $(mplayer -noconsolecontrols -input file=/dev/null -slave -really-quiet -identify -frames 0 -ao null -vo null "$video" |sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;')
+
+[ -z "$tags" ] && tags='|'
+
+cat <<EOF >"$meta"
+$length        $width  $height $(basename "$video")
+$tags
+$description
+EOF
diff --git a/helpers/genthumb.sh b/helpers/genthumb.sh
new file mode 100755 (executable)
index 0000000..625b729
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/zsh
+
+video="$1"
+thumb="$2"
+
+eval $(mplayer -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;')
+
+[ -z "$length" -o -z "$width" -o -z "$height" ] && exit 0
+
+if [ "$(($height*1000/$width))" -gt "750" ]; then
+  width="$((75*$width/$height))"
+  height=75
+else
+  height="$((100*$height/$width))"
+  width=100
+fi
+[ -z $width ] && width=100
+[ -z $height ] && height=100
+chunk="$(($length / 5))"
+
+for cnt in 1 2 3 4; do
+  debug mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video"
+  mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null &
+  mpid="$!"; watch=0
+  while (ps -p "$mpid" >/dev/null 2>/dev/null); do
+      [ "$watch" -gt 10 ] && kill -9 "$mpid" || sleep 1
+      watch="$(($watch+1))"
+  done
+  cp -f 00000009.jpg "${thumb}-${cnt}.jpg" 2>/dev/null
+done
+montage "${thumb}-"[1234]".jpg" -tile 2x2+0+0 -geometry 100x75+3+3 -background "#000000" "${thumb}" 2>/dev/null
+rm 000000[01][0-9].jpg "${thumb}-"[1234]".jpg" 2>/dev/null
+
index c3965a975f5323799bb7f82660164131da9adde3..dacb524bcf7dae126d77bfb81eb94dc2b8d50fed 100755 (executable)
@@ -54,6 +54,7 @@ view() {
     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;')
     
+    video="videos/$info"
     . ${_EXEC}/templates/view.html.sh
   fi
 }
@@ -76,8 +77,8 @@ _printVideo(){
 #    reenc="${_DATA}/vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )"
     mpfake="${_DATA}/mp4/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1.mp4:' <<<"$info" )"
 #    [ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv"
-    [ -r "$meta" ] || ./genmeta.sh "$video" "$meta"
-    [ -r "$thumb" ] || ./genthumb.sh "$video" "$thumb"
+    [ -r "$meta" ] || ". ${_EXEC}/helpers/genmeta.sh" "$video" "$meta"
+    [ -r "$thumb" ] || ". ${_EXEC}/helpers/genthumb.sh" "$video" "$thumb"
     [ -L "$mpfake" ] || ln -s "../$video" "$mpfake"
     video="$(echo "videos/$info" |sed 's/\?/\%6F/g')"
     thumb="$(echo "thumbs/$info.jpg" |sed 's/\?/%6F/g')"
index 504bfe03b62213d7fc56a0215ec2f4169b27c6a3..cb0ed75e7e6d5667461c0903cefa09d2d05711da 100755 (executable)
@@ -18,7 +18,7 @@
 cat <<EOF
   $(filterdiag)
   $(view)
-  <form action="multitag.cgi?f=$filter&amp;s=$search&amp;p=$page&amp;o=$order" method="post" accept-charset="UTF-8">
+  <form action="?action=multitag&amp;f=$filter&amp;s=$search&amp;p=$page&amp;o=$order" method="post" accept-charset="UTF-8">
   <div style="overflow:hidden;">$(thumblist)</div>
   $(tagger)
   </form>
index c17284b23acf5a94689f96c179b723733c290dd9..42f74ac08ee029e2c8878da607f9632be81baf81 100755 (executable)
@@ -21,8 +21,8 @@ cat <<viewEND
     </div>
   
     <div class="videoinfo" id="editmeta" style="display: none;">
-      <form action="meta.cgi?$info" method="post" accept-charset="UTF-8">
-        <input type="hidden" name="f" value="$filter"> <input type="hidden" name="s" value="$search"> <input type="hidden" name="p" value="$page">
+      <form action="?action=meta&amp;i=$info" method="post" accept-charset="UTF-8">
+        <input type="hidden" name="f" value="$filter"> <input type="hidden" name="s" value="$search"> <input type="hidden" name="p" value="$page"> <input type="hidden" name="o" value="$order">
         <input type="hidden" name="length" value="$length"> <input type="hidden" name="width" value="$width">
         <input type="hidden" name="height" value="$height">
         <b>$info</b><a class="panel" href="#" onclick="javascript:hide_inline('editmeta');show_inline('viewmeta')">Cancel</a><br>