Automatic Torrent Extractor/Mover Script
Thanks for visiting Daily Cup of Tech!
Here are a few things that you may want to do while you are visiting:
- Subscribe to the RSS feed
- Take a theme tour and check out some of the best DCoT posts
- Check out our latest posts
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?
7 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.
