Saturday, April 2, 2011

Automate media rename + scrape

Here's the AutoIT script I quickly wrote to automate my media rename + scrape

I've scheduled it to run first thing every morning

; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x/NT
;

$renamerPath =              "C:\Program Files (x86)\theRenamer\theRenamer.exe"
$mediaCompanionPath =       "D:\Program Files (x86)\Media Companion gen2 3.400\mc_com.exe"
$utorrentPath =             "D:\Program Files (x86)\uTorrent\uTorrent.exe"

$tvDownloadDir =            "E:\Bittorrent\Downloads\tv shows\"
$tvNormalMoveDir =          "Q:\TV Shows"
$tvAlternateMoveDir =       "E:\Cinema\TV Shows"

$movieDownloadDir =         "E:\Bittorrent\Downloads\movies\"
$movieNormalMoveDir =       "Q:\Movies"
$movieAlternateMoveDir =    "E:\Cinema\Movies"

;----------------------------------

; check to see if TV show folder has anything
$tvHasFiles = DirGetSize($tvDownloadDir);

; check to see if movie folder has anything
$movieHasFiles = DirGetSize($movieDownloadDir);

if ($tvHasFiles > 0 OR $movieHasFiles > 0) then

   ; if it does, check to see if utorrent is running
    $uTorrentRunning =  ProcessExists("uTorrent.exe"); Will return the PID or 0 if the process isn't found.

    ; if it is, close it
    if ($uTorrentRunning > 0) Then
        ProcessClose($uTorrentRunning)

        Sleep(5000) ;five seconds
    endif

    if ($movieHasFiles > 0) then
        ; check to see if Q folder exists
        $movieNormalDirExists = FileExists($movieNormalMoveDir)

        ; set archive folder
        if ($movieNormalDirExists) then
            $renamerArchiveFolder = $movieNormalMoveDir
        else
            $renamerArchiveFolder = $movieAlternateMoveDir
        endif

        $movieRenamerPath = $renamerPath & " -fetchmovie -ff=" & $movieDownloadDir & _
                                         " -af=" & $renamerArchiveFolder;
        ; run renamer
        RunWait($movieRenamerPath);

        ;Sleep(5000) ;five seconds

        $movieMediaCompanionPath = $mediaCompanionPath & " -m"

        ; run media companion
        RunWait($movieMediaCompanionPath);
    endif

    if ($tvHasFiles > 0) then
        ; check to see if Q folder exists
        $tvNormalDirExists = FileExists($tvNormalMoveDir)

        ; set archive folder
        if ($tvNormalDirExists) then
            $renamerArchiveFolder = $tvNormalMoveDir
        else
            $renamerArchiveFolder = $tvAlternateMoveDir
        endif


        $tvRenamerPath = $renamerPath & " -fetch -ff=" & $tvDownloadDir & _
                                         " -af=" & $renamerArchiveFolder;
        ; run renamer
        RunWait($tvRenamerPath);

        ;Sleep(5000) ;five seconds

        $tvMediaCompanionPath = $mediaCompanionPath & " -e"

        ; run media companion
        RunWait($tvMediaCompanionPath);
    endif

    ; restart utorrent
    if ($uTorrentRunning > 0) Then
        Run($utorrentPath);
    endif
endif

No comments:

Post a Comment