Page 2 of 2

Re: Scanning for updated files setting appears ignored

PostPosted: Mon Aug 06, 2012 1:30 am
by Gonzakpo
Ok. I see. If we have to wait for Mac OS X to adopt Java 7 this will take loooong hahaha :P

Re: Scanning for updated files setting appears ignored

PostPosted: Sat Apr 27, 2013 6:18 am
by norm
Just in case anyone is interested. I came up with a similar solution to manonmoon only using inotifywait from the inotify-tools suite and python. The python script attached queries serviio REST api to update the library if the library was not already being updated and if the filename was not the same as last updated.

Download, unzip and copy my pc5dczc_lib_update.py (attached) to somewhere on your Linux/NAS box. Eg /usr/bin or somewhere ;). Then paste in the following in to "pc5dczc_auto_refresh.sh"...

  Code:
#!/bin/sh
#
# Automatically updates serviio library
# if library update is not already running uses serviio REST api
# requires inotifytools and python 2.x
# written by norm at forum.serviio.org
#

VideoFolder="/i-data/md0/video" # your video files location
MusicFolder="/i-data/md0/music" # your music files location
PhotoFolder="/i-data/md0/photo" # your image files location
time_between_refresh=90 # minimum time between library refresh. Sleep Xs set to let file operations end.
script_location="/usr/bin" # directory where pc5dczc_lib_update.py is located
name="inotifywait" # do not modify

Background()
{
    if [ ! -x "$(which inotifywait)" ] || [ ! -x "$(which python)" ]; then
        echo "inotifywait or python binaries are missing"
        exit 1
    fi
   inotifywait -mr --timefmt '%H%M%S' --format '%T %f' -e move -e delete -e create  "$1" |
   while read tm file; do
      current=$(date +'%H%M%S')
      delta=`expr $current - $tm`
      if [ $delta -lt 2 -a $delta -gt -2 ]; then
         sleep $time_between_refresh # sleep Xs set to let file operations end
         python "${script_location}/pc5dczc_lib_update.py" "${file}"
      fi
   done
}

case $1 in
   start)
      Background $VideoFolder&
      Background $MusicFolder&
      Background $PhotoFolder&
      echo "Starting Serviio auto refresh ..."
      ;;
   stop)
      killall $name
      echo "Stopping $0"
      ;;
   status)
      _pids=$(pidof $name)
      if test -n "$_pids"; then
         echo "$name is running, pid:"
         pidof $name
      else
         echo "$name not running"
      fi
      ;;
   *)
      echo "use $0 [ start | stop | status ]"
      ;;
esac


I hope that helps someone.

Cheers,

Norm :D