(Apr 20, 2017, 10:07 AM)Mike Wrote: That is very clever, I'd be curious to see your script using inotify
Ok here is what I have:
inotify:
Code:
#!/bin/bash
watch tv nzb folder
doPROC(){
/home/itk/bin/nzb_complete.sh $1 $2
}
while true
do
fileName=$(inotifywait -e create,moved_to /home/itk/nzb/completed_nzb/tv | sed -r 's/^.*CREATE(,ISDIR)*\s+(.*)$/\2/g')
###Disney JR #####
#Mickey Mouse Club House
if [[ $fileName == *"Mickey"*"Club"* ]]; then
doPROC ava_dis "Mickey Mouse Clubhouse"
#Mickey and The Roadtser Racers
elif [[ $fileName == *"Mickey"*"Race"* ]]; then
doPROC ava_dis "Mickey Roadster Racers"
#Elena of Avalor
elif [[ $fileName == *"Elena"*"Avalor"* ]]; then
doPROC ava_dis Elena
#Sophia the First
elif [[ $fileName == *"Sofia"*"First"* ]]; then
doPROC ava_dis Sofia
#PJ Masks
elif [[ $fileName == *"PJ"*"Masks"* ]]; then
doPROC ava_dis "PJ Masks"
#Goldie and Bear
elif [[ $fileName == *"Goldie"*"Bear"* ]]; then
doPROC ava_dis "Goldie and Bear"
#The Lion Guard
elif [[ $fileName == *"Lion"*"Guard"* ]]; then
doPROC ava_dis "Lion Guard"
#Doc McStuffins
elif [[ $fileName == *"Doc"*"McStuffins"* ]]; then
doPROC ava_dis "Doc McStuffins"
###Nick JR ###
#Paw Patrol
elif [[ $fileName == *"Paw"*"Patrol"* ]]; then
doPROC ava_nick "Paw Patrol"
elif [[ $fileName == *"PAW"*"Patrol"* ]]; then
doPROC ava_nick "Paw Patrol"
#Blue's Clues
elif [[ $fileName == *"Blues"*"Clues"* ]]; then
doPROC ava_nick "Blues Clues"
elif [[ $fileName == *"Blue's"*"Clues"* ]]; then
doPROC ava_nick "Blues Clues"
### NickToons ###
#As Told By Ginger
elif [[ $fileName == *"Told"*"Ginger"* ]]; then
doPROC ntoon "As Told By Ginger"
#Hey Arnold
elif [[ filename == *"Hey"*"Arnold"* ]]; then
doPROC ntoon "Hey Arnold"
#AAAHH!!! Real Monsters
elif [[ $fileName == *"Real"*"Monster"* ]]; then
doPROC ntoon "AAAHH!!! Real Monsters"
#All Grown Up!
elif [[ $fileName == *"Grown"*"Up"* ]]; then
doPROC ntoon "All Grown Up!"
#Doug (want nicktoon only)
elif [[ $fileName == *"Doug"* ]]; then
doPROC ntoon "Doug"
#Rocket Power
elif [[ $fileName == *"Rocket"*"Power"* ]]; then
doPROC ntoon "Rocket Power"
#Rocko's Modern Life
elif [[ $fileName == *"Rocko"*"Modern"*"Life"* ]]; then
doPROC ntoon "Rocko's Modern Life"
#Rugrats
elif [[ $fileName == *"Rugrats"* ]]; then
doPROC ntoon "Rugrats"
#The Wild Thornberrys
elif [[ $fileName == *"Wild"*"Thornberry"* ]]; then
doPROC ntoon "The Wild Thornberrys"
elif [[ $fileName == *"Wild"*"Thornberries"* ]]; then
doPROC ntoon "The Wild Thornberrys"
#Danny Phantom
elif [[ $fileName == *"Danny"*"Phantom"* ]]; then
doPROC ntoon "Danny Phantom"
#Fairly Odd Parents
elif [[ $fileName == *"Fairly"*"Odd"*"Parents"* ]]; then
doPROC ntoon "Fairly OddParents"
elif[[ $fileName == *"Fairly"*"OddParents"* ]]; then
doPROC ntoon 'Fairly OddParents"
#Invader Zim
elif [[ $fileName == *"Invader"*"Zim"* ]]; then
doPROC ntoon "Invader Zim"
elif [[ $fileName == *"Invader"*"ZIM"* ]]; then
doPROC ntoon "Invader ZIM"
#Jimmy Neutron
elif [[ $fileName == *"Jimmy"*"Neutron"* ]]; then
doPROC ntoon "Jimmy Neutron"
### Generic TV Process ###
else
doPROC tv "Generic"
fi
done
"nzb_complete.sh"
Code:
#! /bin/bash
#SABnzbd completed download
shopt -s extglob nullglob
# set password
psswd=$(cat 'PATH/TO/SUDO/PASSWORD')
# variables
LABEL="$1" # nzb type
NAMEVAR="$2"
NZB_NZBPATH="" # NZBPATH to nzb
NZB="" # nzb name
NZBPATH=""
if [ $LABEL == "ava_dis" ]; then
NZBPATH="tv"
elif [ $LABEL == "ava_nick" ]; then
NZBPATH="tv"
elif [ $LABEL == "ava_movie" ]; then
NZBPATH="movie"
elif [ $LABEL == "ntoon" ]; then
NZBPATH="tv"
else
NZBPATH=$LABEL
fi
LAB_PROC() {
#logging
echo "$(date)" - "$NZB" - "$LABEL" >> /mnt/data/Info/log/nzb.log
# ensure user has ownership
echo $psswd | sudo -S chown itk:itk -R "/home/itk/nzb/completed_nzb/$NZBPATH"
sudo chmod 777 -R /home/itk/nzb
#Pushbullet notification
/home/itk/bin/pushbullet "SABnzbd" "$(date) - '$NZB' finished downloading."
#sleep timer
i=240
while [ $i -gt 0 ]; do
echo "please wait..." $i "more seconds"
if [ $i -gt 60 ]; then
let i=i-10
sleep 10
elif [ $i -eq 60 -o $i -lt 60 ]; then
let i=i-5
sleep 5
fi
done
#Check nzb LABEL and process appropriately
if [ "$LABEL" == "anime_dual" ] ; then
cd "/home/itk/nzb/completed_nzb/anime_dual/$NZB"
/home/itk/bin/nzb_mkv_eng $NAMEVAR
elif [ "$LABEL" == "movie" ] ; then
cd "/home/itk/nzb/completed_nzb/movie/$NZB"
/home/itk/bin/nzb_filebot_movie.sh "$NAMEVAR"
elif [ "$LABEL" == "tv" ] ; then
cd "/home/itk/nzb/completed_nzb/tv/$NZB"
/home/itk/bin/nzb_filebot_tv.sh "$NAMEVAR"
#elif [ "$LABEL" == "music" ] ; then
#nzb_filebot
elif [ "$LABEL" == "anime" ] ; then
cd "/home/itk/nzb/completed_nzb/anime/$NZB"
/home/itk/bin/nzb_filebot_anime.sh "$NAMEVAR"
elif [ "$LABEL" == "ava_dis" ] ; then
cd "/home/itk/nzb/completed_nzb/tv/$NZB"
/home/itk/bin/nzb_fb_ava_disjr.sh "$NAMEVAR"
elif [ "$LABEL" == "ava_nick" ] ; then
cd "/home/itk/nzb/completed_nzb/tv/$NZB"
/home/itk/bin/nzb_fb_ava_nickjr.sh "$NAMEVAR"
elif [ "$LABEL" == "ava_movie" ] ; then
cd "/home/itk/nzb/completed_nzb/movie/$NZB"
/home/itk/bin/nzb_fb_ava_movie.sh "$NAMEVAR"
elif [ "$LABEL" == "ntoon" ]; then
cd "/home/itk/nzb/completed_nzb/tv/$NZB"
/home/itk/bin/nzb_fb_ntoon.sh "$NAMEVAR"
fi
}
# get NZBPATH to nzb and name for each folder
cd /home/itk/nzb/completed_nzb/"$NZBPATH"
for f in * ; do
if [[ -d "$f" ]]; then
NZB_NZBPATH="$f"
cd "$NZB_NZBPATH"
NZB=${PWD##*/}
rm -f *.srr *.sfv *.nzb
LAB_PROC 2>&1 | tee -a /mnt/data/Info/log/nzb_dump.log &
xterm -geometry 80x40+1920+10 -e tail --follow --pid=$! /mnt/data/Info/log/nzb_dump.log
wait
cd /home/itk/nzb/completed_nzb/"$NZBPATH"
mv "$NZB_NZBPATH" "/home/itk/nzb/completed_nzb/unproc"
fi
done
A few things I would like to point out.
I split the processes this way for 2 reasons:
1. this was originally my setup when i was just using utorrent w/o a split and the execute after dl cmd would just run the "complete.sh" and sort that way, when i switched to deluge on the split I could not get the execute to run for the life of me so i made different labels dl to separate folders. This birthed the inotify (I can't take full credit for that I found it I believe on stack exchange.) When I found usenet, I made a clone of the inotify/sorting for that, while keeping the deluge stuff. So basically, it was a level of laziness. Instead of rewriting everything, I just used inotify to call the existing script and made small changes to satisfy need.
2. Even if I wasn't too lazy to rewrite, doing it this way made the debugging process much easier when I initially implemented inotify. It also makes adding a new show easier in the debug process aswell. The only pain in the ass is, I have to reboot on change, because I still have trouble making flawless cron jobs, so i just "run on startup" and rarely have an issue.
As you can see, there are 2 seperate "anime" categories, anime and anime_dual. As one may guess anime_dual is for dual audio. As, I am not against subbed only video, if it is in english, that is what i will watch. So why weigh down a HDD with both? anime_dual will actually run "mkvmerge" and then filebot, stripping unwanted audio and sub tracks.
the xterm portion allows me to track progress, if i so wish of the log file real-time. the geometry portion forces it on to my second screen
the pushbullet is a little script i slapped together to allow me to use the api at will with out needing to cut/paste and type email everytime I use it.
this script is self sustaining, meaning, it requires sudo passwords to chown and chmod, and does it on its own. Because who is at their keyboard 24/7? I found a nifty piece of code allowing me to keep my sudo pw in file and call it to the script when it needs a sudo command.
the sleep timer is there for some of the larger NZB that sometimes take a few minutes to unpack. the nature of inotify, is based on an immediate change to the watch folder so as soon as the nzb begins to unpack, the script starts but fails. With the sleep it gives the unpacking time to complete. For those using raw-hd files or 4k ( which ive seen some over 200gb JFC?!) you may need to adjust based on cpu/memory and average filesize.
*"show"*"name"* is how the actual sorting is done for the "special" shows. the '*' stands for any combination of characters and/or whitespaces or lack thereof. so what it does is checks if the dowloaded file or folder is equal to [ (something or nothing)"show"(something or nothing)"name"(something or nothing) ]
and lastly,
$NAMEVAR is mostly for debugging for ensuring the "special" shows are being sorted correctly
hope this helps some and isn't too confusing. I'll be happy to clarify more if necessary. (sorry for bad typing habits
)
LT
edit: the bottom portion of "nzb_complete.sh" will actually scan each folder and subfolder until there are none to do the rename/sort process