[Script] Automated moving of downloads for SB and CP to post process
#1
Hi All,

Sorry if the title confuses you however I had a need to write a script for moving my completed downloads to specific locations so SickBeard and CouchPotato could post process the files.

I was originally doing this via uTorrent but having to manually set labels was becoming cumbersome, especially when I wasn't always around a computer to change the label if a torrent auto started. So I began seeking alternative ways to make this process completely automated. I am happy to say I have finally written a script to make this work!

Here's a little information on my setup.
I have uTorrent, SickBeard and CouchPotato all running as a service on my HTPC.
SB and CP monitor locations for files to post process (D:\Downloads\TV SHows, and D:\Downloads\Movies).
SickBeard and CouchPotato snatch the files and send the .torrent files to a blackhole location for uTorrent to start the downloads.
uTorrent then spits the completed downloads to a specific location (D:\torrents).
Once the torrent is completed I have setup uTorrent to run a program - my VBScript, which moves files to the SB and CP processing directories (D:\Downloads\TV SHows, and D:\Downloads\Movies) by using keywords in the file or folder name.

For example:-
in the "D:\torrents" folder (the completed downloads folder) I have the following files and folders

Rock.of.Ages.720p - This is a movie FOLDER with an MKV,mp4,avi file within it.
The.Hangover.2.(2011).DVDRip.XviD-MAXSPEED.avi - This is movie FILE
New.Girl.S02E01.HDTV - This is a TV Show FOLDER with and mp4,avi,mkv file within it.
White.Collar.S04E10.HDTV.mp4 - this is a TV Show FILE.

My script scans the file and folder names for key words to separate TV Shows from the rest. Currently, the key words I am using is "hdtv" and "s0" seeing as most tv shows have either one or both of the keywords in the file or folder name. For all other files it classifies them as movies.

So the outcome of the above files is that it will move the "Rock.of.Ages.720p" folder and "The.Hangover.2.(2011).DVDRip.XviD-MAXSPEED.avi" file to D:\Downloads\Movies for CouchPotato to process;
and the "New.Girl.S02E01.HDTV" folder and "White.Collar.S04E10.HDTV.mp4" file to the "D:\Downloads\TV Shows" directory for SickBeard to process.

If anyone has any need for the same sort of functionality please feel free to use my script!
The script is below but here is the link to the moveTorrentScript if you would like to download it. :-)

If anyone has any questions about the script or wants a better explanation please let me know.

Thanks,
Will.


Code:
'====================================================================
' Description: Script to Move Downloaded TV Shows and Movies to
' correct folders based on wildcards in File/Folder Name. Output to
' log file for troubleshooting.
' Created by: William Beckett - 2012
'====================================================================

On Error Resume Next

Dim sTorrents, sTV, sMovie, sFile, oFSO

' create the filesystem object
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Create Log File
Set objLog = oFSO.OpenTextFile("c:\temp\moveTorrentLog.txt", 8, True)

' Set Variables
sTorrents = "D:\torrents\"
sTV = "D:\Downloads\TV Shows\"
sMovie = "D:\Downloads\Movies\"

' Scan each file in the folder
For Each sFile In oFSO.GetFolder(sTorrents).Files
    ' check if the file name contains TV Show Parameters
    If InStr(1, sFile.Name, "hdtv", 1) OR InStr(1, sFile.Name, "s0", 1) <> 0 Then
        ' TV Show Detected - Move File
        objLog.WriteLine Now() & " - " & sFile.Name & " Detected as TV Show - Moving to " & sTV
        oFSO.MoveFile sTorrents & sFile.Name, sTV & sFile.Name
    ' Move all other Files to Movies Directory
    Else objLog.WriteLine Now() & " - " & sFile.Name & " Detected as Movie - Moving to " & sMovie
        oFSO.MoveFile sTorrents & sFile.Name, sMovie & sFile.Name
    End If
    
Next

' Scan each folder
For Each sFolder In oFSO.GetFolder(sTorrents).SubFolders
' check if the folder name contains TV Show Parameters
If InStr(1, sFolder.Name, "hdtv", 1) OR InStr(1, sFolder.Name, "s0", 1) <> 0 Then
    ' TV Show Folder Detected - Move File
    objLog.WriteLine Now() & " - " & sFolder.Name & " Detected as TV Show Folder - Moving to " & sTV
    oFSO.MoveFolder sTorrents & sFolder.Name, sTV & sFolder.Name
' Move all other Files to Movies Directory
Else objLog.WriteLine Now() & " - " & sFolder.Name & " Detected as Movie Folder - Moving to " & sMovie
    oFSO.MoveFolder sTorrents & sFolder.Name, sMovie & sFolder.Name
End If

Next        
    If sTorrents.File.Count = 0 And sTorrents.SubFolders.Count = 0 Then
        objLog.WriteLine Now() & " - There is nothing left to Process..."
        objLog.Close
    End If
Reply

Logout Mark Read Team Forum Stats Members Help
[Script] Automated moving of downloads for SB and CP to post process2