I'm fairly new to the forum. I don't know how active I will be, but just recently I've configured my downloads to automate as much as I can.
I have a bunch of downloads that I look for via RSS (specifically mp4 and mkv) and when they download, upon their completion they are automatically renamed to remove as many download tags, render tags and other bits. Then remove all dots and replace them with spaces and add a space between the season and episode tags. Finally, once that's done, the completed files are then moved to a different location where they are further processed.
I thought some people here might like to see how I've got everything for renaming the files and moving them. Plus some of you could drastically improve the scripts I've been using for yourselves. And yes, I know my code is rubbish before anyone mentions it!
This process will work for singular files or multiple files from the same torrent.
You may be in for a long read, just warning you now.
---------------------------------
Current Setup
At the moment, I have a micro form factor dell running windows 10, that I saved from being recycled running qbittorrent. I've set the BIOS to make sure it will auto turn on at a specific time (it's always left on anyway) plus also set it to turn back on after powerloss. So it's always up.
All downloads go to a USB3 external HDD (as it was the easiest way to up the storage, I'm lazy!), then once complete they are moved to a different folder on the same drive to run scripts. The reason to move them to run the scripts is so the scripts won't interfere with other downloads that have yet to finish. Then once all scripts have ran, they are moved to a network share for final processing on a different machine (Adding metadata and the like).
What does my script do?
It will automatically delete any .jpg, .txt, .nfo or .exe files that were included in the download folder. It will then try it's best to rename all files, specifically .mp4 and .mkv files. It will do this by looking for specific words or characters and replacing them. Then once done, uses Robocopy to transfer the files to their last destination.
What's left after the script has ran?
All files and their containing folder are moved to their final destination. An empty folder is left behind in the original location.
What format is the script?
It's a .bat file. So it runs using windows command line. This bat file will push some commands through to powershell but will do so without opening a new session. This means it can work through all commands and not get interrupted.
---------------------------------
OK, so I've read all that stuff above, show me the code already!
Just be aware that this isn't written to be fast or efficient or any of that stuff. Simply because I'm an noob when it comes to code.
Just remember, if you want to use this you'll have to customize it for your setup as this won't work otherwise. Also, be careful and use at your own risk.
Code: Select all
@echo off
REM This changes the drive to the one with my downloads
REM If you don't save to an external drive you can delete these 3 lines.
E:
REM This moves the directory to the final download location
REM you will need to put the location of your download folder here. For example C:\Username\Downloads\FinalDownload
REM in order for the code to work smoother I would recommend you set up your downloads to put temp downloads in
REM a downloads folder, then move them once completed to a different folder. Otherwise this will mess with downloads
REM that are already in progress.
cd "\Downloads\To Transfer"
REM These commands will silently delete any of the following files from the download location
del /s/f/q *.txt
del /s/f/q *.jpg
del /s/f/q *.nfo
del /s/f/q *.exe
REM These commands will automatically rename any mp4 or mkv files in the download. It will get rid of the usual download tags.
REM If you want to add more tags, copy both lines if you want to include mp4 and mkv, then change the name between the 1st ''
REM for example '1080p', then add what you want that to change to in the second set of ''
REM for ecample '' for nothing or ' ' for a space, or 'EXAMPLE TEXT'
REM As the list grows, the batch file will take longer to run through
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.1080p','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.1080p','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.720p','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.720p','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.WEB-DL','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.WEB-DL','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.WEBRIP','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.WEBRIP','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.WEBRip','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.WEBRip','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.AMZN','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.AMZN','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.HULU','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.HULU','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.NF','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.NF','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.H264','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.H264','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.x264','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.x264','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.264','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.264','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.x265','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.x265','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.PROPER','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.PROPER','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.[rarbg]','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.[rarbg]','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.[rartv]','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.[ratv]','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('-NTb','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('-NTb','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('-GHOSTS','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('-GHOSTS','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('-TVSmash','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('-TVSmash','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('-LAZY','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('-LAZY','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('iT','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('iT','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.REPACK','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.REPACK','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.INTERNAL','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.INTERNAL','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.DDP5.1','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.DDP5.1','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.DDP2.0','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.DDP2.0','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.AAC2.0','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.AAC2.0','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.HDTV','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.HDTV','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.BDRIP','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.BDRIP','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.BRRIP','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.BRRIP','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.BluRay','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.BluRay','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('-','') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('-','') + $_.Extension }"
REM These commands will be used to rename the season/episode formatting to include a space
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S01E',' S01 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S01E',' S01 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S02E',' S02 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S02E',' S02 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S03E',' S03 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S03E',' S03 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S04E',' S04 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S04E',' S04 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('S05E',' S05 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('S05E',' S05 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S06E',' S06 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S06E',' S06 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S07E',' S07 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S07E',' S07 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S08E',' S08 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S08E',' S08 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S09E',' S09 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S09E',' S09 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S10E',' S10 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S10E',' S10 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S11E',' S11 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S11E',' S11 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S12E',' S12 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S12E',' S12 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S13E',' S13 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S13E',' S13 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S14E',' S14 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S14E',' S14 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.S15E',' S15 E') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.S15E',' S15 E') + $_.Extension }"
REM These commands will remove the dots and try to clean up the spacing if it's gone funny
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.',' ') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.',' ') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace(' ',' ') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace(' ',' ') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace(' ',' ') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace(' ',' ') + $_.Extension }"
REM This command will then move the newly named mp4 or mkv files to their final location. This works the same as cut paste. NOT copy and paste.
Robocopy "E:\Downloads\To Transfer" Z: /s /mov
---------------------------------
Let's break it down
The 1st command is:
E:
This will change the current directory to the E: drive (this is because I download to an external drive) if you download to your computer, you will normally have a C: drive. If you do, just delete the E: command as it won't apply to you.
The 2nd command is:
cd "\Downloads\To Transfer"
This will change to command prompts location to your download location. If you want to use this script I would recommend setting your downloads to temporarily stay in one location, then once finished, move them to the location the script will run. This will stop it from messing with your on going downloads.
If you are on a regular computer your location might be something like C:\Username\Downloads\Final_Download_Folder
The 3rd set of commands are:
del /s/f/q *.txt
del /s/f/q *.jpg
del /s/f/q *.nfo
del /s/f/q *.exe
These commands will quietly and forcefully delete all text, jpeg, info and executable files all located in your final download location. Most torrent's I download always have all of the above and since it qbittorrent is running pretty much in full auto, I can't be bothered to delete these files each time.
BE SUPER CAREFUL as if you accidentally run this command in the wrong place you could delete files on your drive by accident. If you're uncomfortable, just delete those lines.
The 4th set of commands are:
powershell -command "get-childitem -recurse | dir -Filter *.mkv | Rename-Item -NewName { $_.BaseName.replace('.1080p','your output') + $_.Extension }"
powershell -command "get-childitem -recurse | dir -Filter *.mp4 | Rename-Item -NewName { $_.BaseName.replace('.1080p','your output') + $_.Extension }"
etc, etc.
What these commands do is look in each folder in the final download location that end with a .mp4 and .mkv extension. It will then try to rename the file using words you specify. In the example above it will look for .1080p (as I said, most of my downloads have dots instead of spaces) and replace it with nothing.
It will run through trying to remove .x265 .x264 .1080p .720p .AAC2.0 and more. If you want to add more tags just copy the lines above and change what I've highlighted in italics above. The need to be in single quotes. You can add however many you like. Keep in mind the more you have the longer it may take. Currently it will take about 15 seconds to run through.
The final bit of code is:
Robocopy "E:\Downloads\To Transfer" Z: /s /mov
This will use Robocopy which is robust file copying built into Windows to move your newly renamed files (if you want to move them) to a different location.
For me they move the files from E:\Downloads\To Transfer which is my final download location, to a network drive which is mapped to Z:. if you want to change this for yourself, just edit the italics.
As this uses the move command with Robocopy, it will basically cut and paste from the old location to the new location. Only leaving behind an empty folder. Which you can delete manually, or like me, set up a script to clean this directory once a week.
---------------------------------
If you made it all the way down here, Bravo!
I've been using this script to move files for many months without issues, I've just added the renaming part today and it's already working well and saving me time!
It will take a file that looks like this:
Videofile.S08E11.1080p.WEBRip.DDP5.1.x264-NTb.mkv
and rename it to:
Videofile S08 E11.mkv
Your results will vary as I haven't included all tags, so you'll need to add them as you go.
For someone like me that relies on VSS to automate my downloads, then automatically rename and move them, this is a big time saver.
If you are unfamiliar with command line I would recommend you play with the script in parts to make sure you know how it works, don't just jump in if you're unsure.
Anyway, thanks for reading and I hope this manages to help some of you automate a little bit or inspire you with your own little scripts. As I said, this is quite specific to my use case but yeah... thought I'd post if for you guys.