Advertisement
Guest User

Filebot-watcher bash script (Modified)

a guest
Apr 19th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #!/bin/sh
  2. SETTLE_DOWN_TIME=280s
  3. INOTIFYWAIT_OPTS=--recursive
  4. SETTLE_DOWN_CHECK="5 seconds ago"
  5. inotifywait --monitor "$1" --event create --event moved_to --event modify --exclude '/[.@]' --format '%w%f' $INOTIFYWAIT_OPTS | stdbuf -oL uniq | while read -r FILE; do
  6. TODAY="$(date '+%Y/%m/%d %H:%M:%S %Z')"
  7.  
  8. echo "[INOTIFY] $FILE"
  9.  
  10. # make sure to inform the user that we are waiting for things to settle down
  11. echo "[$TODAY] Waiting $SETTLE_DOWN_TIME seconds for changes to settle down..."
  12.  
  13. # file may yield inode/x-empty for new files
  14. sleep "$SETTLE_DOWN_TIME"
  15.  
  16. # abort if the file is currently being written (i.e. network copy operations can take minutes or hours)
  17. RECENTLY_MODIFIED_FILES="$(find "$1" -type f -newermt "$SETTLE_DOWN_CHECK" -not -path '*/[.@]*' -print -quit)"
  18.  
  19. if [ -n "$RECENTLY_MODIFIED_FILES" ]; then
  20. echo "[$TODAY] $RECENTLY_MODIFIED_FILES was modified less than $SETTLE_DOWN_CHECK"
  21. echo "Processing deferred until next change..."
  22. continue
  23. fi
  24.  
  25. # e.g. video.mp4: video/mp4
  26. if file --mime-type "$FILE" | egrep --quiet "directory|video|audio|empty|octet-stream"; then
  27. ~/bin/filebot -script fn:amc --action hardlink --conflict replace -non-strict --log-file amc.log --def excludeList=".excludes" unsorted=y music=y artwork=y "$@"
  28. else
  29. echo "Ignore: $(file --mime-type "$FILE")"
  30. fi
  31. done
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement