Automatic Torrent Extractor/Mover Script
It has been long time since I have watched television like “normal” people. Ever since I found bittorrent, there was no turning back!
The problem that I have is that I am a pack rat! Once I download a TV episode, I don’t want to get rid of it. After all, I used up all that bandwidth!
So, I’ve started organizing my television shows into three categories:
- Downloaded - these are shows that have just completed downloading and are in their original form from the Internet
- Unsorted - these shows are in in one central location and should be in playable format. These are all my new shows that I probably have not watched yet
- Sorted - once I have watched a show, the shows get moved into appropriate folders based on series and season name
The issue that I have run into in the past is that once an episode is downloaded, it may not be in playable format since many shows are archived, typically into RAR files. This means that I needed to manually extract these files or move the playable files to the Unsorted folder so that I could watch them.
I finally got fed up with this and I thought that there had to be a better way. It took me a couple of evenings work but I finally came up with a batch files that does the work for me! I simply have Windows programmed to run the batch file on a regular basis and it extracts all of the RAR files to my preferred location and moves all of the AVI files there as well (without copying the samples).
Here is the contents of that batch file:
@echo off
setlocal
cls
rem Set program variables below:
rem sourcedir - where files are saved once they have been downloaded
set sourcedir=C:\Downloaded
rem destinationdir - where you want all of the playable files to be placed
set destinationdir=C:\Unsorted
rem winrarpath - location of the unrar program
set winrarpath=C:\Program Files\WinRAR\
rem filelist - the name of the file which will store all of the RAR and AVI file names that have been processed
set filelist=FoundFiles.txt
rem tempfile - name of the temporary file that will be created and then deleted during the cleanup process
set tempfile=TempFile.txt
set path="%winrarpath%";%path%
echo Extracting new RAR files...
for /R "%sourcedir%" %%R IN (*.rar) DO find /C "%%R" %filelist% > NUL & if errorlevel 1 call unrar e -o- -y "%%R" *.* %destinationdir%\ & echo %%R>>%filelist%
echo Adding sample AVI files to no copy list...
for /R "%sourcedir%" %%R IN (*sample*.avi) DO find /C "%%R" %filelist% > NUL & if errorlevel 1 echo %%R>>%filelist%
echo Moving new AVI files...
for /R "%sourcedir%" %%R IN (*.avi) DO find /C "%%R" %filelist% > NUL & if errorlevel 1 echo Copying %%R... & copy "%%R" %destinationdir%\ & echo %%R>>%filelist%
echo Cleaning up %filelist%...
for /F %%R IN (%filelist%) DO if exist "%%R" echo %%R>>%tempfile%
del %filelist%
rename %tempfile% %filelist%
All you need to do is copy this file and save it as TorMove.cmd. Then edit the three variables:
- sourcedir
- destinationdir
- winrarpath
- filelist
- tempfile
Only the first three are critical. You just need to make sure that the last two do not clash with other files.
Also, you do not need to use WinRAR. If you do not have this program, UnRAR for Windows will work just fine.
Once you have modified your file, save it and then schedule Windows to run it as often as you want!
If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?
11 Responses to “Automatic Torrent Extractor/Mover Script”
-
Søren Pedersen Says:
May 14th, 2008 at 8:39 amPretty amazing bit of batch magic there! And nice to have you blogging again
-
Aaje Says:
May 17th, 2008 at 7:09 amHi,
I like the script, but it’s less than helpful when the compressed files have cryptic names like “ip-assa.avi”, while the full name of the movie/tv show is something completely else. Usually the movie/show is in a directory, but this script doesn’t take the original directoryname into the extracted directory. Some fiddling with FOR gave me this: Instead of %destinationdir%, put in %destinationdir%%%~pR
Now the original directoryname will be used forthe extracted direcory. I noticed one caveat: I have a directorystructure like D:\video\movies\whatevermovie and the extraction dir is D:\extracted. The extracted directory will be D:\extracted\video\movies\whatevermovie. Slight boo boo, but at least when I extract 20 movies at once all the files are kept together, and possible subs are kept with the movie too.
-
Jason Murray Says:
May 17th, 2008 at 11:03 pmWOW! I must say a huge thank you! I was fed up with doing this manually, and I was doing some research on how to do this automatically when I saw the post of this on LifeHacker! The other thing to mention is if you ar3e running uTorrent, you can have this run after every torrent is finished downloading…
Thanks for the base code! Awesome work!
-
jackbl Says:
May 18th, 2008 at 11:41 amI’ve tried adapting this to use 7-zip
but I get an error about absolute paths. I’m sure i’m not the only one to try this, so could anyone help me out with this change?current (non working) 7z:
@echo off
setlocal
clsrem Set program variables below:
rem sourcedir - where files are saved once they have been downloaded
set sourcedir=D:\sourcerem destinationdir - where you want all of the playable files to be placed
set destinationdir=D:\testrem winrarpath - location of the unrar program
set winrarpath=C:\Program Files\7-Ziprem filelist - the name of the file which will store all of the RAR and AVI file names that have been processed
set filelist=FoundFiles.txtrem tempfile - name of the temporary file that will be created and then deleted during the cleanup process
set tempfile=TempFile.txtset path="%winrarpath%";%path%
echo Extracting new RAR files...
for /R "%sourcedir%" %%R IN (*.rar) DO find /C "%%R" %filelist% > NUL & if errorlevel 1 call 7z e -o- -y "%%R" *.* %destinationdir%\ & echo %%R>>%filelist%echo Adding sample AVI files to no copy list...
for /R "%sourcedir%" %%R IN (*sample*.avi) DO find /C "%%R" %filelist% > NUL & if errorlevel 1 echo %%R>>%filelist%echo Moving new AVI files...
for /R "%sourcedir%" %%R IN (*.avi) DO find /C "%%R" %filelist% > NUL & if errorlevel 1 echo Copying %%R... & copy "%%R" %destinationdir%\ & echo %%R>>%filelist%echo Cleaning up %filelist%...
for /F %%R IN (%filelist%) DO if exist "%%R" echo %%R>>%tempfile%
del %filelist%
rename %tempfile% %filelist%
-
Aaje Says:
May 19th, 2008 at 10:28 amYou changed unrar for 7z, but you forgot the switches (the “e -o- -y” part). Run 7z without any other parts to see what the exact switch should be.
BTW, I’ve hacked the code some more (see previous post), so now it will properly move the files around, so you end up with a directory filled with directories with movies. Note that you need a temp dir though.
@echo off
setlocal
clsrem Set program variables below:
rem sourcedir - where files are saved once they have been downloaded
set sourcedir=L:\video\compressedrem extracteddir - temporary directory where all the movies are extracted to
set extracteddir=L:\video\temprem finaldestdir - where you move all the extracted movies to
set finaldestdir=L:\video\Moviesrem winrarpath - location of the unrar program
set winrarpath=C:\Program Files\WinRAR\rem --------------------------------------------------------------------------------------
rem no config needed below
rem --------------------------------------------------------------------------------------rem filelist - the name of the file which will store all of the RAR and AVI file names that have been processed
set filelist=FoundFiles.txtrem tempfile - name of the temporary file that will be created and then deleted during the cleanup process
set tempfile=TempFile.txtset path="%winrarpath%";%path%
echo Extracting new RAR files...
for /R "%sourcedir%" %%R IN (*.rar *.001) DO find /C "%%R" %filelist% > NUL & if errorlevel 1 call unrar e -o- -y "%%R" *.* %extracteddir%%%~pR\ & echo %%R>>%filelist% & rmdir /S /Q %%~pRecho Moving extracted movies to final directory..
set extracteddirpad=%extracteddir%%sourcedir:~2%
FOR /D %%A IN (%extracteddirpad%\*.*) DO move %%A %finaldestdir%echo Cleanup..
del %filelist%
-
Brad Says:
May 21st, 2008 at 8:36 pmI love this little script. I have no idea what it says and does, but with a little trial and error I got it working. I was wonder if there is some simple additions someone could help me with.
I download my (public domain of course) movies and tv shows and have the finished download sent to the same folder (since I don’t know how to get uTorrent to send them to different folders).
Might there be an additional bit of code that, when moving files, it would move the movies (in a it’s own folder) to one folder and the tv shows (which are individual files that don’t need to be extracted) to a different folder.
That would be great. I will include the code version I’m using if it might help.
@echo off
setlocal
clsrem Set program variables below:
rem sourcedir - where files are saved once they have been downloaded
set sourcedir=D:\Finishedrem extracteddir - temporary directory where all the movies are extracted to
set extracteddir=D:\temprem finaldestdir - where you move all the extracted movies to
set finaldestdir=D:\Moviesrem winrarpath - location of the unrar program
set winrarpath=C:\Program Files\UnRAR\rem ————————————————————————————–
rem no config needed below
rem ————————————————————————————–rem filelist - the name of the file which will store all of the RAR and AVI file names that have been processed
set filelist=FoundFiles.txtrem tempfile - name of the temporary file that will be created and then deleted during the cleanup process
set tempfile=TempFile.txtset path=”%winrarpath%”;%path%
echo Extracting new RAR files…
for /R “%sourcedir%” %%R IN (*.rar *.001) DO find /C “%%R” %filelist% > NUL & if errorlevel 1 call unrar e -o- -y “%%R” *.* %extracteddir%%%~pR\ & echo %%R>>%filelist% & rmdir /S /Q %%~pRecho Moving extracted movies to final directory..
set extracteddirpad=%extracteddir%%sourcedir:~2%
FOR /D %%A IN (%extracteddirpad%\*.*) DO move %%A %finaldestdir%echo Moving new AVI files…
for /R “%sourcedir%” %%R IN (*.avi) DO find /C “%%R” %filelist% > NUL & if errorlevel 1 echo Moving %%R… & Move “%%R” %finaldestdir%\ & echo %%R>>%filelist%echo Cleanup..
del %filelist% -
kevin Says:
May 26th, 2008 at 6:57 pmDCoT:
I was happy to see that you are a fan of bittorrent. I am new to bittorrent and have been confused by the various opinions out there about its benefits and dangers. I am curious about your bittorrent workflow or other readers. Do you use a proxy or any type of mechanism to protect your identity or is this not needed. -
Russell Says:
August 10th, 2008 at 3:58 pmI ran across this while looking for some automated downloading scripts… Basically I want a script that watches for new episodes of the shows I like and automatically adds them to bt.
Anyway… I already have a solution to the multi-format playing issue, and I thought I’d share it as an alternative. I have an old xbox (classic - get on ebay for $50), on which I installed xbox media center (XMC). I HIGHLY recommend it. It will play ANYTHING. I’ve played DVD image files from within multi-part rar files without having to combine, decompress nor mount the image. It streams the files direct from my bt download folder and plays to my gorgeous 36″ HDTV.
Just an option!
-
spectre Says:
May 6th, 2009 at 8:08 amMy script does something similar, here it is:
It contains of 4 files: main.bat, copyextract.bat, process.bat and fragment.txt
The complexity is to support long paths with spaces in them, and that i not only want to process downloaded rar files, but also copy unrared downloads to the same directory instead of a separate directory for each file. Hope someone can use this!
[c:\batch\main.bat]
REM ******************** SET THESE PARAMETERS **************************SET BATCHFOLDER=C:\BATCH
SET DOWNLOADDRIVE=Z:
SET DOWNLOADFOLDER=Z:\Video\TV
SET DOWNLOADSUBFOLDER=New.Episodes
COLOR 1FREM ******************** DO NOT CHANGE THIS ****************************
%DOWNLOADDRIVE%
cd %DOWNLOADFOLDER%
dir %DOWNLOADSUBFOLDER% /S /B > folders.txt
:FOLDERS
set resultfilename=folderresult.txt
copy %BATCHFOLDER%\fragment.txt + folders.txt temp.txt > nul
type temp.txt | find “set filename=” > temp.bat
echo call %BATCHFOLDER%\process.bat >> temp.bat
call temp.bat
type temp.txt | find /v “set filename=” > folders.txt
find “\” folders.txt
if %errorlevel% == 0 goto FOLDERS
del temp.bat
del folders.txt
del temp.txt
for /F “usebackq delims==” %%m in (folderresult.txt) do start /w /D %%~fm %BATCHFOLDER%\copyextract.bat
del folderresult.txtREM ******************** END OF FILE ***********************************
[c:\batch\copyextract.bat]
REM ******************** SET THESE PARAMETERS **************************color 2f
REM ******************** DO NOT CHANGE BELOW ***************************
REM ******************** EXCLUDES SAMPLE FILES FROM COPY JOBS **********
attrib -A *sample* /SREM ******************** CREATES FILELIST OF MKV’s *********************
dir *.mkv /s /b > mkvdir.txt
:MKV
set resultfilename=mkvresult.txt
copy %BATCHFOLDER%\fragment.txt + mkvdir.txt temp.txt > nul
type temp.txt | find “set filename=” > temp.bat
echo call %BATCHFOLDER%\process.bat >> temp.bat
call temp.bat
type temp.txt | find /v “set filename=” > mkvdir.txt
find “\” mkvdir.txt
if %errorlevel% == 0 goto MKV
del temp.bat
del mkvdir.txt
del temp.txtREM ******************** COPIES ALL MKV FILES TO DOWNLOADSUBFOLDER *****
for /F “usebackq delims==” %%m in (mkvresult.txt) do xcopy /Y /M %%~fm
REM ******************** CREATES FILELIST OF AVI’s *********************
dir *.avi /s /b > avidir.txt
:AVI
set resultfilename=aviresult.txt
copy %BATCHFOLDER%\fragment.txt + avidir.txt temp.txt > nul
type temp.txt | find “set filename=” > temp.bat
echo call %BATCHFOLDER%\process.bat >> temp.bat
call temp.bat
type temp.txt | find /v “set filename=” > avidir.txt
find “\” avidir.txt
if %errorlevel% == 0 goto AVI
del temp.bat
del avidir.txt
del temp.txtREM ******************** COPIES ALL AVI FILES TO DOWNLOADSUBFOLDER *****
for /F “usebackq delims==” %%m in (aviresult.txt) do xcopy /Y /M %%~fm
REM ******************** CREATES FILELIST OF RAR’s *********************
dir *.rar /s /b > rardir.txt
:RAR
set resultfilename=rarresult.txt
copy %BATCHFOLDER%\fragment.txt + rardir.txt temp.txt > nul
type temp.txt | find “set filename=” > temp.bat
echo call %BATCHFOLDER%\process.bat >> temp.bat
call temp.bat
type temp.txt | find /v “set filename=” > rardir.txt
find “\” rardir.txt
if %errorlevel% == 0 goto RAR
del temp.bat
del rardir.txt
del temp.txtREM ******************** EXTRACTS ALL FILES TO DOWNLOADSUBFOLDER *******
for /F “usebackq delims==” %%m in (rarresult.txt) do unrar e -o- %%~fm
REM ******************** CLEANUP ***************************************
del mkvresult.txt
del aviresult.txt
del rarresult.txtexit
REM ******************** END OF FILE ***********************************
[c:\batch\process.bat]
echo “%filename%” >> %resultfilename%
REM ******************** END OF FILE ***********************************[c:\batch\fragment.txt]
set filename=NOTE: It is very important that fragment.txt only contains one line and no spaces efter set filename=
-
mitar Says:
May 6th, 2009 at 11:37 amspectre can you explain to me.which part do i have to copy to make cmd or bat (dont understnad) and what do i need to change.my files are in D:\bitlord\.
by the way how can i schedule windows to run cmd and how often. -
Ryan Says:
September 23rd, 2009 at 7:36 amI have a similar setup…
I have utorrent downloading files to x:\downloading. When the torrents are complete utorrent moves them to x:\Torrents. I have a script running whenever the PC is idle for 1 minute that checkes the x:\torrents folder for a specific set of files (names of tv shows i watch). If the script finds something new, it copies it into my New Episodes folder for easy viewing all the new episodes of things I’ve downloaded on my xbox, and also copies it into a storage folder (x:\tv shows\showname\season#\). Once copied the script also deletes the file from x:\torrents. When I’m done watching the new episode I delete it from New Episodes.
But this is no longer ideal. I’ve just started using tvtorrents.com, which requires you upload a lot in order to continue downloading. So right now I seed my finished items from x:\torrents, but ideally I’d like utorrent to download specific shows into x:\tv shows\showname\season#\, seed them from there, and have a script that copies new files from x:\tv shows\showname\season#\ into my New Episodes folder.
I don’t suppose anyone has any ideas about that?
Cheers


