Author Topic: Complete Torrent Automation (with Plex)  (Read 62443 times)

Complete Torrent Automation (with Plex)
on: May 31, 2014, 10:23:55 AM
UPDATE 09/11/14:

So been playing with this a little more and have realised that I have over complicated things..

Now I just have the below script in uTorrent to run on completion, and so far so good, the script copies the files from the uTorrent folder to the destination to doesn't interrupt the torrent seeding.

I've also made it run hidden changing filebot to filebot.launcher.exe in the command, so if you are running the server and MC on the same machine it doesn't popup the command line version

I've also updated the music format, but still advise against using it because it is rubbish to be honest, and handles music file by file rather than looking at the album as a whole, which means a various artists album will copy to a folder per artist.

filebot.launcher.exe -script fn:amc --output "D:/Media1" --log-file amc.log --action copy --conflict override -non-strict --def "ut_dir=%D" "ut_file=%F" "ut_kind=%K" "ut_title=%N" "ut_label=%L" "ut_state=%S" music=N artwork=n plex=localhost deleteAfterExtract=n clean=n excludeList=amc-input.txt "seriesFormat=D:/Media1/TV/{n}/{'S'+s}/{fn}" "animeFormat=D:/Media1/New Films/{n}/{fn}" "movieFormat=D:/Media1/New Films/{n} {y}/{fn}" "musicFormat=D:/Media1/Music/New/{n}/{album+'/'}{pi.pad(2)+'. '}{artist} - {t}"


I'll leave the rest below in case anyone wants to reference it.



AIM:

A script that once uTorrent finishes downloading, it is automatically run to extract and sort the media files in to the correct folders so that you can use specific media folders in plex rather than having to use "Home Movies".

This script is setup to work with Plex and assumes Plex server is running on the local PC, however if you don't have Plex it will still run fine (it's only 1 flag in the filebot script) This can also be changed to notify XBMC, if there is demand for it I'll add variables at the top to control location of server and XMBC/Plex choices? Although not the most difficult thing to work out.

Note: If you setup an RSS feed in uTorrent, you can get it to automatically download TV episodes when they are availble, and they will just appear in your Plex library without you needing to do anything! This is really easy to setup - Google it!

Requirements:

Filebot needs to be installed, this deals with the extract and multimedia sorting, everything else in this script is to make sure uTorrent doesn't have a fit and to then save duplication as a result!

Optional: Plex Media Server - This is designed around Plex, although will still work if you don't have it!

What it does:

  • Uses variables, so is easy to configure
  • Checks to see if the script is already running, if so waits until it's not, otherwise it gets confused
  • Stores a directory listing from the torrent downloads folder so that it doesn't process the same file twice
  • Makes a duplicate of only the file(s) to process, so that uTorrent can continue to seed the original and doesn't either lock the file causing an error or have a fit when it can't find the data
  • Runs filebot which extracts and splits Movies/TV/Anime/Music to different folders as specified, removing unneeded files such as samples, the below also strips subtitles, although I can probably re-add if demand calls for it!
  • Note: Music is disabled below as I don't like how it categorises, but you can enable by changing to music=Y
  • Automatically notifies Plex Server of the update
  • The pause at the end can be removed, I just like to see what has run, and is useful for error checking

The Batch Script (Save as "filebotscript.bat"):

Code: [Select]
echo off
cls

:: Music is disabled but have included a location if you want to enable in the filebot script, however I don't like how it organises music.
:: Variables should not have a slash on the end - the variables have an explanation below.
:: Variables shoud avoid using spaces - only because I don't use them and haven't added relevant
:: READY - DIR where files are downloaded to
:: FILMS TV MUSIC ANIME - These are the media locations

:: CONFIGURABLE BACK SLASH VARIABLES LISTED BELOW - NO SPACES IN FILENAMES

:: AUTOMATEDATA - A location that can be used for storing file lists to stop duplication
set AUTOMATEDATA=D:\Automatedata

:: COMPLETETORRENT - DIR where files are downloaded to in uTorrent
set COMPLETETORRENT=D:\Downloads\Complete

:: TEMPMEDIA - temporary folder where a copy of your downloads is made so that uTorrent doesn't lock files (will only copy new files)
set TEMPMEDIA=D:\Downloads\Temp

:: MEDIA - The main directory of your media - I don't think this really matters as media locations are defined below, and duplicate list is not used in filebot
set MEDIA=D:\Media1


:: CONFIGURABLE FORWARD SLASH VARIABLES LISTED BELOW

set FILMS=D:/Media1/New Films
set TV=D:/Media1/TV
set MUSIC=D:/Media1/Music/New
set ANIME=D:/Media1/Anime


echo.
echo  Create automated data and temp folders - ignore already exists errors
echo  #################################################################
echo.

mkdir %AUTOMATEDATA%
mkdir %TEMPMEDIA%



echo.
echo  Check if script is already running
echo  #################################################################
echo.

:RUNNINGCHECK
if exist %AUTOMATEDATA%\running.txt goto PLEASEHOLD
GOTO:NEXTPLEASE

:PLEASEHOLD

REM Hold for 30 seconds then re-check

echo script running... waiting 30 seconds for re-try
ping 1.1.1.1 /n 1 /w 30000 > NUL
GOTO:RUNNINGCHECK

:NEXTPLEASE

REM Create a file to flag script is running and proceed to run the rest of the script.

echo This file just shows script is running, delete file if script is not running > %AUTOMATEDATA%\running.txt


echo.
echo  Get Dir listing and save to temporary text file so next time the same files are not copied
echo  #################################################################
echo.

dir "%COMPLETETORRENT%" /b > "%AUTOMATEDATA%\templist.txt"

echo.
echo  Copy files to safe "TempTorrent" location excluding those present last time this was run
echo  #################################################################
echo.

XCOPY "%COMPLETETORRENT%" "%TEMPMEDIA%" /C /S /H /Y /J /Exclude:%AUTOMATEDATA%\done.txt

REM Below line removed as date redundant following addition of exclude list, date string converts to US date format.
REM XCOPY "%COMPLETETORRENT%" "%TEMPMEDIA%" /C /S /H /Y /J /D:%date:~3,2%-%date:~0,2%-%date:~8,2%


echo.
echo  Delete old list and replace with temp list.
echo  #################################################################
echo.

del "%AUTOMATEDATA%\done.txt"
ren "%AUTOMATEDATA%\templist.txt" done.txt
 
echo.
echo  Run Filebot - unrecognised files will remain in the "TempTorrent" location
echo  #################################################################
echo.

:: If using XBMC, replace plex below with XBMC

"C:\Program Files\FileBot\filebot" -script fn:amc --output "%MEDIA%" --log-file amc.log --action move --conflict override -non-strict "%TEMPMEDIA%" --def music=N artwork=n plex=localhost deleteAfterExtract=y clean=y "seriesFormat=%TV%/{n}/{'S'+s}/{fn}" "animeFormat=%ANIME%/{n}/{fn}" "movieFormat=%FILMS%/{n} {y}/{fn}" "musicFormat=%MUSIC%/{n}/{fn}"

REM Delete running indicator file

del "%AUTOMATEDATA%\running.txt"

pause



This is the old script for reference:
(click to show/hide)


This is just an admin script that resets validation and running indicators in case something went wrong, you shouldn't need this with the version of the script above, unless you exit the script before it completes.

Code: [Select]
echo off
cls

:: AUTOMATEDATA - A location that can be used for storing file lists to stop duplication

REM This will clear done list and re run normal process

set AUTOMATEDATA=D:\Automatedata

echo none > "%AUTOMATEDATA%\done.txt"

REM Delete running indicator file

del "%AUTOMATEDATA%\running.txt"

filebotscript.bat


uTorrent Settings:

Last Edit: November 09, 2014, 23:06:36 PM by XEntity #187;

Re: Complete Torrent Automation (with Plex)
Reply #1 on: September 20, 2014, 06:34:37 AM
So I've run into a few problems trying to run this script.  First it wasn't exclusing the files that had already been extracted.  So I added --def excludeList=amc.txt to the amc script. Also, it was mostly working well initially, but now it's prompting me with a y/n question, which results in the whole preocess not being automated. Here is the full script I am running now, and a screen grab:
echo  #################################################################
echo.

   dir "%READY%" /b > %GENERAL%\templist.txt

echo.
echo  Copy files to safe "Ready" location excluding those present last time this was run
echo  #################################################################
echo.

   XCOPY %READY% %COMPLETE% /C /S /H /Y /J /Exclude:%GENERAL%\done.txt

echo.
echo  Delete old list and replace with temp list.
echo  #################################################################
echo.

   del %GENERAL%\done.txt
   ren %GENERAL%\templist.txt done.txt
 
echo.
echo  Run Filebot - unrecognised files will remain in the "Ready" location
echo  #################################################################
echo.

   "C:\Program Files\FileBot\filebot" -script fn:amc --output "%MEDIA%" --log-file amc.log --action move --conflict override -non-strict "%COMPLETE%" --def excludeList=amc.txt --def music=N artwork=y plex=localhost deleteAfterExtract=n clean=n "seriesFormat=%TV%/{n}/{'S'+s}/{fn}" "animeFormat=%ANIME%/{n}/{fn}" "movieFormat=%FILMS%/{n} {y}/{fn}" "musicFormat=%MUSIC%/{n}/{fn}"

REM Delete running indicator file

   del %GENERAL%\running.txt

pause

Re: Complete Torrent Automation (with Plex)
Reply #2 on: September 20, 2014, 06:38:18 AM

Re: Complete Torrent Automation (with Plex)
Reply #3 on: September 20, 2014, 21:48:23 PM
try xcopy32 rather than xcopy command.
I think Xcopy32 preserves long file names better. Been long long time since I worked with Dos & I guess its true.. dont use it, you forget it!

Its usually the /y command that auto prompts the yes in an xcopy string.

Also looking at your screen shot, you have a lot of errors.
Starting at the top, it looks like you have not SET= GENERAL - so you that is why you getting an error at the top.
SO you prob got other errors to why it is not working.

look at this line :-

  XCOPY %READY% %COMPLETE% /C /S /H /Y /J /Exclude:%GENERAL%\done.txt

again, the error is probably based around not  SET=General in the script



Re: Complete Torrent Automation (with Plex)
Reply #4 on: September 21, 2014, 01:13:35 AM
The copy command itself is fine, I use daily in my script :)

The issue you are having are all of the variables need to be set as per your setup...

If you don't set them then the script doesn't know what it's doing, it wont store a list of existing files and that's why you are seeing the same files being copied...

You should only need to take the full script and change the variables.. the rest will work without amendment!

At the moment it's only running the AMC script all, the rest isn't actually doing anything :)

configure these general and media can be the same dir, but it will copy the "duplicate" lists to the general location

Code: [Select]
REM CONFIGURABLE BACK SLASH VARIABLES LISTED BELOW

set GENERAL=D:\s1
set READY=D:\Downloads\Ready
set COMPLETE=D:\Downloads\Complete
set MEDIA=D:\Media1

REM CONFIGURABLE FORWARD SLASH VARIABLES LISTED BELOW

set FILMS=D:/Media1/New Films
set TV=D:/Media1/TV
set MUSIC=D:/Media1/Music/New
set ANIME=D:/Media1/Anime
Last Edit: September 21, 2014, 01:15:20 AM by XEntity #187;

Re: Complete Torrent Automation (with Plex)
Reply #5 on: September 21, 2014, 10:41:39 AM
Thanks for the advice.  I had already set the parameters, but i did'nt post that part.  I did notice that I had set one to the wrong drive!  I just deleted the script and started anew and everything seems to be working better.  One problem, files that arent a part of an archive get moved to my media folder, and utorrent then cant seed the file.  I use private trackers so I need to seed to keep my ratio. How can I work around this? Is their a copy and move option for uncompressed files?

Re: Complete Torrent Automation (with Plex)
Reply #6 on: September 21, 2014, 21:30:20 PM
The "ready" location should be your finished torrent folder

The "Complete" location should be an empty folder where a temporary copy is created..

Both these locations should not be used in any other references...

The script is designed in such a way not to touch the seeding files, which is why is copies to a temp folder...

Re: Complete Torrent Automation (with Plex)
Reply #7 on: September 22, 2014, 15:07:13 PM
I wonder if my uorrent seetings are affecting this all.  I was having utorrent also move files into my completed folder.  I'm trying now with just leaving the downloads in the same folder,  which will be my ready folder.

Re: Complete Torrent Automation (with Plex)
Reply #8 on: September 23, 2014, 00:28:52 AM
No moving the files should be fine that's how mine is setup, can you post a screen shot of your utorrent folder settings? And also the variables setup in the script? If I get some time I'll get the script to auto create the temp folders as well and put in some error reporting, although you appear to be the only person using it :-) how did you find it?

    • Tekforums.net - It's new and improved!
  • Offline Clock'd 0Ne

  • Clockedtastic
  • Posts: 10,947
  • Administrator
  • Hero Member
Re: Complete Torrent Automation (with Plex)
Reply #9 on: September 23, 2014, 08:04:00 AM
Although I don't use Plex I was considering giving this a go to automate extracting to my media server, but that will probably need more customisation too.

Re: Complete Torrent Automation (with Plex)
Reply #10 on: September 23, 2014, 15:08:26 PM
I'm planning to use it too.... just not yet :-)

Re: Complete Torrent Automation (with Plex)
Reply #11 on: September 23, 2014, 15:13:31 PM
I was trying to run the Filebot + utorrent AMC, but it did nothing, so a few internet searches and I found your post.  Like I've said, it mostly works great, the only problem I seem to have is that iy moves uncompressed files to my media folder, and utorrent doesn't know where yhe file is.



I have it set up where utorrent autmatically stats the script (which I have named amc.bat) after a download finishes, and have simplified things by choosing only a download folder.

The code I'm running is below.  I changed one thing because it wasn't reliably excluding files that were already processed. In the bottom part (the actual amc script) I added "--def excludeList=amc.txt"

Really glad I found this post as you've been more than helpful XEntity.  I'm not good with this stuff, just trying to learn some things lately!

Code: [Select]
echo off
cls

REM Music is disabled but have included a location if you want to enable in the filebot script, however I don't like how it organises music.
REM Variables should not have a slash on the end - the variables have an explanation below.
REM GENERAL - A location that can be used for storing file lists to stop duplication
REM READY - DIR where files are downloaded to
REM COMPLETE - secondary folder where a copy is made so that uTorrent doesn't lock files
REM MEDIA - The main directory of your media - I don't think this really matters as media locations are defined below, and duplicate list is not used in filebot
REM FILMS TV MUSIC ANIME - These are the media locations

REM CONFIGURABLE BACK SLASH VARIABLES LISTED BELOW

set GENERAL=C:\Users\Pedra\Documents
set READY=E:\Completed
set COMPLETE=E:\Torrent Downloads
set MEDIA=F:\Media

REM CONFIGURABLE FORWARD SLASH VARIABLES LISTED BELOW

set FILMS=F:/Media/Movies
set TV=F:/Media/Series
set MUSIC=F:/Media/Music
set ANIME=F:/Media/Anime

echo.
echo  Check if script is already running
echo  #################################################################
echo.

:RUNNINGCHECK
if exist %GENERAL%\running.txt goto PLEASEHOLD
GOTO:NEXTPLEASE

:PLEASEHOLD

REM Hold for 30 seconds then re-check

echo script running... waiting 30 seconds for re-try
ping 1.1.1.1 /n 1 /w 30000 > NUL
GOTO:RUNNINGCHECK

:NEXTPLEASE

REM Create a file to flag script is running and proceed to run the rest of the script.

echo This file just shows script is running, delete file if script is not running > %GENERAL%\running.txt

echo.
echo  Get Dir listing and save to temporary text file so next time the same files are not copied
echo  #################################################################
echo.

dir "%READY%" /b > %GENERAL%\templist.txt

echo.
echo  Copy files to safe "Ready" location excluding those present last time this was run
echo  #################################################################
echo.

XCOPY %READY% %COMPLETE% /C /S /H /Y /J /Exclude:%GENERAL%\done.txt

echo.
echo  Delete old list and replace with temp list.
echo  #################################################################
echo.

del %GENERAL%\done.txt
ren %GENERAL%\templist.txt done.txt
 
echo.
echo  Run Filebot - unrecognised files will remain in the "Ready" location
echo  #################################################################
echo.

"C:\Program Files\FileBot\filebot" -script fn:amc --output "%MEDIA%" --log-file amc.log --action move --conflict override -non-strict "%COMPLETE%" --def excludeList=amc.txt --def music=N artwork=n plex=localhost deleteAfterExtract=n clean=n "seriesFormat=%TV%/{n}/{'S'+s}/{fn}" "animeFormat=%ANIME%/{n}/{fn}" "movieFormat=%FILMS%/{n} {y}/{fn}" "musicFormat=%MUSIC%/{n}/{fn}"

REM Delete running indicator file

del %GENERAL%\running.txt

pause

Re: Complete Torrent Automation (with Plex)
Reply #12 on: September 23, 2014, 16:29:51 PM

I also noticed that I get an error when the script runs related to my parameters.

Re: Complete Torrent Automation (with Plex)
Reply #13 on: September 23, 2014, 20:51:13 PM
Right, I see your problem, and I see why... I'll re-write the script so the variables are easier to understand...

First of all remove the def you added in, I'm not sure of the entire impact, but it was better without, I think this was if the script was re-run and a film then became available, and also ensures moved files are deleted..

Set uTorrent to move to completed (just tick the box with your current settings)

You may want to move your general folder, as it will create an exclusion file in this location, but that's up to you..

Where your problem is:

Currently:
set READY=E:\Completed
set COMPLETE=E:\Torrent Downloads

Change To:
set READY=E:\Completed
set COMPLETE=E:\TempTorrent

You will need to create a folder called TempTorrent (no spaces - this is why you are getting an error, you can probably use "" but it's easier just to not use spaces!)
Last Edit: September 23, 2014, 22:05:47 PM by XEntity #187;

Re: Complete Torrent Automation (with Plex)
Reply #14 on: September 23, 2014, 20:59:02 PM
Although I don't use Plex I was considering giving this a go to automate extracting to my media server, but that will probably need more customisation too.

Script will work as is if you just want to extract... even leaving in the plex line shouldn't cause an issue... if you use XBMC you can replace "plex=" with "XBMC=" in the script...

Let me know what you are planning on doing? I'll probably be able to tell you what changes you need....

I'll be amending this script to make it easier anyway..

0 Members and 2 Guests are viewing this topic.