Automatically Extract and Move Movies (uTorrent-Linux)
The Following script will extract all of your torrent that are in .rar format and move all of your files that are just .avi or .mkv to a USB drive. I use this in conjunction with my WDTV and it works excellently. For this script to work uTorrent must be configured to move completed downloads to another directory other than the directory that the active downloads are in.
To use this script follow these steps:
1.) Create two empty files:
verify.txt on your usb device. The script checks to see if verify.txt is on your usb device to assure the device is plugged in (as to avoid copying files to the mount Dir and not the device.
/etc/extra/database.txt The directory /etc/extra must be created along with the empty file database.txt for this script to function. The script will move text files in and out of /etc/extra/.
2.) Copy the Below script to /bin/extra
3.) be sure to change the permissions chmod 777 /bin/extra
To use this script follow these steps:
1.) Create two empty files:
verify.txt on your usb device. The script checks to see if verify.txt is on your usb device to assure the device is plugged in (as to avoid copying files to the mount Dir and not the device.
/etc/extra/database.txt The directory /etc/extra must be created along with the empty file database.txt for this script to function. The script will move text files in and out of /etc/extra/.
2.) Copy the Below script to /bin/extra
3.) be sure to change the permissions chmod 777 /bin/extra
#!/bin/sh
###Set the following Variables###Leave all of the directories in the same format without the / on the end like in the examples.
#working_dir( a Directory where files will be stored temporarily before transfered to usb by the script)
working_dir=/home/torrent/working
#complete_dir( The Directory that Utorrent puts completed downloads into. Utorrent must be configured to move complete downloads
#to a seperate directory other than its active downloads directory so that unfinished torrents are not moved or extracted.)
complete_dir=/home/torrent/complete
#usb (is the path where you mount your usb that you want the files transfered too.)
usb=/mnt/usb
###Do not change anything below this line####
[ -f $usbverify.txt ] && date >> /var/www/usb/log.txt || exit
find "$complete_dir/" -iname '*.rar' > /etc/extra/alist.txt
diff /etc/extra/alist.txt /etc/extra/database.txt|grep "<"|cut -c 3- > /etc/extra/blist.txt
while read line; do
dirname "$line" >> /etc/extra/clist.txt
done < /etc/extra/blist.txt
sort -u /etc/extra/clist.txt > /etc/extra/dlist.txt
while read line2; do
var=$(ls "$line2"|grep -m 1 ".rar")
var2=$(cat /etc/extra/database.txt|grep "$line2/$var")
if [ "$var2" != "$line2/$var" ]
then
cd "$working"
unrar e "$line2/$var"
echo "$line2/$var" >> /etc/extra/database.txt
mv -n "$working_dir/*.avi" "$usb"
mv -n "$working_dir/*.mkv" "$usb"
echo "moved $var" >> "$usb/log.txt"
fi
done < /etc/extra/dlist.txt
rm /etc/extra/*list.txt
#####Now for Downloads with Just .Avi and .Mkv files#####
find "$complete_dir/" -iname '*.avi' > /etc/extra/alist
diff /etc/extra/alist /etc/extra/database.txt|grep "<"|cut -c 3- > /etc/extra/blist
while read line; do
if [ "$line" != "sample.avi" ]
then
cp -n "$line" "$usb/"
echo "moved $line" >> "$usb/log.txt"
fi
done < /etc/extra/blist
rm /etc/extra/*list
find "$complete_dir/" -iname '*.mkv' > /etc/extra/alist
diff /etc/extra/alist /etc/extra/database.txt|grep "<"|cut -c 3- > /etc/extra/blist
while read line; do
if [ "$line" != "sample.mkv" ]
then
cp -n "$line" "$usb/"
echo "moved $line" >> "$usb/log.txt"
fi
done < /etc/extra/blist
rm -r "$working_dir/*"
find "$usb/" -iname "*sample*" | while read line; do
rm -r "$line"
done
exit
###Set the following Variables###Leave all of the directories in the same format without the / on the end like in the examples.
#working_dir( a Directory where files will be stored temporarily before transfered to usb by the script)
working_dir=/home/torrent/working
#complete_dir( The Directory that Utorrent puts completed downloads into. Utorrent must be configured to move complete downloads
#to a seperate directory other than its active downloads directory so that unfinished torrents are not moved or extracted.)
complete_dir=/home/torrent/complete
#usb (is the path where you mount your usb that you want the files transfered too.)
usb=/mnt/usb
###Do not change anything below this line####
[ -f $usbverify.txt ] && date >> /var/www/usb/log.txt || exit
find "$complete_dir/" -iname '*.rar' > /etc/extra/alist.txt
diff /etc/extra/alist.txt /etc/extra/database.txt|grep "<"|cut -c 3- > /etc/extra/blist.txt
while read line; do
dirname "$line" >> /etc/extra/clist.txt
done < /etc/extra/blist.txt
sort -u /etc/extra/clist.txt > /etc/extra/dlist.txt
while read line2; do
var=$(ls "$line2"|grep -m 1 ".rar")
var2=$(cat /etc/extra/database.txt|grep "$line2/$var")
if [ "$var2" != "$line2/$var" ]
then
cd "$working"
unrar e "$line2/$var"
echo "$line2/$var" >> /etc/extra/database.txt
mv -n "$working_dir/*.avi" "$usb"
mv -n "$working_dir/*.mkv" "$usb"
echo "moved $var" >> "$usb/log.txt"
fi
done < /etc/extra/dlist.txt
rm /etc/extra/*list.txt
#####Now for Downloads with Just .Avi and .Mkv files#####
find "$complete_dir/" -iname '*.avi' > /etc/extra/alist
diff /etc/extra/alist /etc/extra/database.txt|grep "<"|cut -c 3- > /etc/extra/blist
while read line; do
if [ "$line" != "sample.avi" ]
then
cp -n "$line" "$usb/"
echo "moved $line" >> "$usb/log.txt"
fi
done < /etc/extra/blist
rm /etc/extra/*list
find "$complete_dir/" -iname '*.mkv' > /etc/extra/alist
diff /etc/extra/alist /etc/extra/database.txt|grep "<"|cut -c 3- > /etc/extra/blist
while read line; do
if [ "$line" != "sample.mkv" ]
then
cp -n "$line" "$usb/"
echo "moved $line" >> "$usb/log.txt"
fi
done < /etc/extra/blist
rm -r "$working_dir/*"
find "$usb/" -iname "*sample*" | while read line; do
rm -r "$line"
done
exit