#!/bin/sh #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #(at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program. If not, see . COMPLETE=/media/storage/Downloads/Completed/ DEST=/media/storage/Videos/ cd $COMPLETE ls $DEST > ./shows.txt # Strips any underscores and replaces them with spaces find . -maxdepth 1 | while read FILE do y=`echo $FILE | sed 's/\_/ /g'` mv "$FILE" "$y" done rm -rf *.1 # Removes duplicate folders, sometimes SABnzbd creates them on startup find . -iname "*sample*.avi" -print0 | xargs -0 rm -v >> rm.log find . -iname "*sample*.mkv" -print0 | xargs -0 rm -v >> rm.log find . -iname "*.nfo.1" -print0 | xargs -0 rm -v >> rm.log # Removes duplicate nfo files find . -iname "*.nzb" -print0 | xargs -0 rm -v >> rm.log # Don't need NZB's for what I just downloaded find . -iname "00*" -print0 | xargs -0 rm -v >> rm.log # Random junk files that come with albums find . -iname "*.m3u" -print0 | xargs -0 rm -v >> rm.log # Gets rid of playlist files # Renames avi's and mkv files to the name of the folder they are in. find . -maxdepth 1 -type d | while read FILE do cd "$FILE" y=`pwd | echo $(sed 's,^\(.*/\)\?\([^/]*\),\2,').avi` sleep 1 # Sometimes things don't get named first, debugging. mv *.avi "$y" z=`pwd | echo $(sed 's,^\(.*/\)\?\([^/]*\),\2,').mkv` sleep 1 # Sometimes things don't get named first, debugging. mv *.mkv "$z" cd - done sleep 1 # Moves the avi's and mkv files to their folders in the $DEST directory. cat shows.txt | while read line do if [ "$line" != "" ] || [ "$line" != " " ] || [ "$line" != "\n" ]; then # It's a bad idea if it decides to remove anything with a space, trust me. find . -iname "$line*.avi" -print0 | xargs -0 mv -t "$DEST$line/" find . -iname "$line*.mkv" -print0 | xargs -0 mv -t "$DEST$line/" sleep 1 #Make sure it doesn't try to delete things too soon. find . -iname "$line*" -maxdepth 1 -print0 | xargs -0 rm -rfv >> rm.log #Remove this line to not delete directories. fi done rm shows.txt