Page 1 of 2
Rename movie to parent folder name (Now with a windows version too!)
Posted: April 10th, 2009, 11:22 pm
by PiNPOiNT
Newzbin does a great job of downloading nzb's into nice clean folder names of a movie, and now i'd like to rename the file inside to the same naming as the parent folder its in.
eg: c:\Movies\This is a good movie\blah blah blah.avi
to
c:\Movies\This is a good movie\This is a good movie.avi
There's a 3rd party program called fileboss that does this, but im sure it can be handled in a simple batch script instead. However i'm not sure how to code it.
The first issue that i can think of is that sometimes a movie comes in 2 parts (cd 1 and 2). So by renaming all files that are extracted can run into issues with things being named the same.
The other issue is if a movie is a extracted video_ts dvd structure, in which case you'd obviously want to leave it in tact.
Any ideas?
Re: Rename movie to parent folder name
Posted: April 13th, 2009, 11:04 pm
by schwarzbro
Hey pinpoint,
I wanted this exact same script and had a friend that new shell scripting write one for me. It's a shell script, so it runs on a Unix system, not Windows. The script will not only rename you movie file to the same name as the directory it's stored in, but will also move it. As a bonus, if you have 2 AVIs that need to be merged, it will do that for you as well. Then it will rename the AVI and move it.
There are 2 variables that you'll need to set to match your setup. The first is NEWDIR. This is where you want the files to be moved (BTW, the script will move the entire directory). The second is OLDDIRTEMP. This is just a temporary directory that the script will use to package files. Nothing will be stored in this directory once the script completes.
It's important to note that this is a post processing script for SABnzdb. It uses the variables that SAB sends to name the directory and movie file. I named mine RenameAndMerge.sh and set it as the default post processing script for Movies in teh SAB admin interface.
Good luck!
#!/bin/sh
OLDDIR=$1
#NEWDIR is where you want the new directory to be created and the files moved to
NEWDIR="/mnt/user/Video/Feature Films/"
#OLDDIRTEMP needs to have write permission
OLDDIRTEMP=/mnt/user/Video/Downloads/outbox/
DIRECTORY=`cd "$OLDDIR"; pwd | awk -F"/" '{print $NF}'`
if [ ! -d "$NEWDIR$DIRECTORY" ];then
mkdir "$NEWDIR$DIRECTORY"
fi
mv "$OLDDIR" "$OLDDIRTEMP"
if [ `find $OLDDIRTEMP -size +629145600c -regex '.*/.*\.avi' | wc -l` -eq 2 ]
then
FIRSTAVI="`find $OLDDIRTEMP -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '1p' | sed 's/^\.//'`"
SECONDAVI="`find $OLDDIRTEMP -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '2p' | sed 's/^\.//'`"
mencoder -forceidx -ovc copy -oac copy -o "$OLDDIRTEMP/tempfile.avi" "$FIRSTAVI" "$SECONDAVI"
fi
for file in $OLDDIRTEMP/*
do
FILETYPE=`echo "$file"|awk -F"." '{print $NF}'`
FILENAME=`echo "$file"|awk -F"/" '{print $NF}'`
mv "$OLDDIRTEMP$FILENAME" "$NEWDIR$DIRECTORY/$DIRECTORY.$FILETYPE"
done
rm -rf $OLDDIRTEMP
Re: Rename movie to parent folder name
Posted: April 14th, 2009, 10:17 am
by PiNPOiNT
Very cool, I'm trying to patch together a windows version of the same thing, but i don't have much free time to work on it these days, ill post it when its working for everyone to test.
What happens with your script if the movie ends up being a non avi file or VIDEO_TS dvd structure?
Re: Rename movie to parent folder name
Posted: April 14th, 2009, 1:13 pm
by markus101
I have been using this script for sometime, I modified one form these forums for my needs, it will also handle WMV files.
http://pastebin.com/faef7dda
Currently it strips off the date from the Foldername when it renames the video file,
but that can be changed by altering this line:
Code: Select all
MOVIE_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
to just be this:
-Markus101
Re: Rename movie to parent folder name
Posted: April 15th, 2009, 9:19 pm
by PiNPOiNT
Ok here we go,
My first attempt at writing a windows version of what i was trying to do.
What it does:
Searches through all folders and subfolders and renames movie files to match their parent folder name. This will rename all files with the extentions AVI MKV WMV ISO IMG NFO TS
C:\films\aliens (1982)\group-aliens.avi
will rename to
aliens (1982).avi
If there are 2 avi files , it will rename them as CD1 and CD2
eg:
C:\films\aliens (1982)\group-aliensA.avi -> aliens (1982) CD1.avi
C:\films\aliens (1982)\group-aliensB.avi -> aliens (1982) CD2.avi
*NOTE*: this is for movies only, it will screw up your TV episodes, so don't run it in a folder that contains any TV files
I've included 2 versions,
testmovierenamer.bat -> allows you to run a test version that will make no changes to your movie files but will show you what your files will look like when you run the actual program
movierenamer.bat -> Runs the actual movie renamer script and WILL make changes.
HOW TO USE:
Unzip the 2 batch files to anywhere you wish
Edit the test batch file, or the actual renamer .bat file with notepad and change the folder path when the script will start searching for films (It can be found near the top of the batch file)
Default: Z:\FILMS
double click the batch file to run.
If you want to export the scripts data to a txt file....
open a dos window (or press start -> run -> cmd.exe)
and type
movierenamer > output.txt
or testmovierenamer > output.txt
Download HERE: http://drop.io/movierenamer
Please post any suggestions or comments
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: May 9th, 2009, 4:05 am
by feerlessleadr
Hi Pinpoint, this is an awesome script.
I am having a little problem with it however in regards to multiple files within a folder.
Sometimes (and it seems to be happening more and more often for some reason) instead of renaming all of the files once to xxx_CD1 and xxx_CD2 and then stop, it will rename the first file again to xxx_CD3, which obviously screws things up a bit.
here is a an output log:
Code: Select all
*************CHECKING FOR AVIs********************
Renaming "dmd-ttee-cd1.avi" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD1.avi
Renaming "dmd-ttee-cd2.avi" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD2.avi
Renaming "dmd-ttee-cd3.avi" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD3.avi
Renaming "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)_CD1.avi" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD4.avi
*************CHECKING FOR MKVs********************
*************CHECKING FOR WMVs********************
*************CHECKING FOR NFOs********************
*************CHECKING FOR IMGs********************
*************CHECKING FOR ISOs********************
*************CHECKING FOR Ts Files*****************
*************CHECKING FOR SUBs********************
Renaming "dmd-ttee-cd1.sub" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD1.sub
Renaming "dmd-ttee-cd2.sub" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD2.sub
Renaming "dmd-ttee-cd3.sub" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD3.sub
Renaming "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)_CD1.sub" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD4.sub
*************CHECKING FOR SRTs********************
*************CHECKING FOR IDXs********************
Renaming "dmd-ttee-cd1.idx" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD1.idx
Renaming "dmd-ttee-cd2.idx" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD2.idx
Renaming "dmd-ttee-cd3.idx" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD3.idx
Renaming "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)_CD1.idx" to "The Lord of the Rings- The Two Towers (2002) (Extended Edition) (3 CD)"_CD4.idx
as you can see I added in 3 sections for .sub files, .srt files and .idx files, as these are quite common in the releases I grab. For all 3 file types within the folder, the first CD is renamed twice, causing a problem.
Is there something I can do to fix this? or perhaps I messed something up with the code:
Here is the modified script:
Code: Select all
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
CLS
REM ********CHANGE PATH BELOW TO YOUR ROOT MOVIE FOLDER*********
CD /D F:\Downloads\Processed Downloads\Movies
ECHO *************CHECKING FOR AVIs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.avi) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.avi
REN !FileName! !ParentFolder!.avi
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.avi) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.avi
REN "%%~B" !ParentFolder!_CD!FileCount!.avi
)
)
)
ECHO *************CHECKING FOR MKVs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.mkv) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.mkv
REN !FileName! !ParentFolder!.mkv
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.mkv) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.mkv
REN "%%~B" !ParentFolder!_CD!FileCount!.mkv
)
)
)
ECHO *************CHECKING FOR WMVs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.wmv) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.wmv
REN !FileName! !ParentFolder!.wmv
)
IF !FileCount! GTR 1 (
ECHO Found !FileCount! MKVs
SET FileCount=0
FOR %%B IN ("%%~A"\*.wmv) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.wmv
REN "%%~B" !ParentFolder!_CD!FileCount!.wmv
)
)
)
ECHO *************CHECKING FOR NFOs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.nfo) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.nfo
REN !FileName! !ParentFolder!.nfo
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.nfo) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.nfo
REN "%%~B" !ParentFolder!_CD!FileCount!.nfo
)
)
)
ECHO *************CHECKING FOR IMGs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.img) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.img
REN !FileName! !ParentFolder!.img
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.img) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.img
REN "%%~B" !ParentFolder!_CD!FileCount!.img
)
)
)
ECHO *************CHECKING FOR ISOs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.iso) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.iso
REN !FileName! !ParentFolder!.iso
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.iso) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.iso
REN "%%~B" !ParentFolder!_CD!FileCount!.iso
)
)
)
ECHO *************CHECKING FOR Ts Files*****************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.ts) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.ts
REN !FileName! !ParentFolder!.ts
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.ts) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.ts
REN "%%~B" !ParentFolder!_CD!FileCount!.ts
)
)
)
ECHO *************CHECKING FOR SUBs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.sub) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.sub
REN !FileName! !ParentFolder!.sub
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.sub) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.sub
REN "%%~B" !ParentFolder!_CD!FileCount!.sub
)
)
)
ECHO *************CHECKING FOR SRTs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.srt) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.srt
REN !FileName! !ParentFolder!.srt
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.srt) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.srt
REN "%%~B" !ParentFolder!_CD!FileCount!.srt
)
)
)
ECHO *************CHECKING FOR IDXs********************
FOR /R . %%A IN (.) DO (
REM ECHO Checking for Movies in %%A
SET ParentFolder="%%~nxA"
SET FileCount=0
FOR %%B IN ("%%~A"\*.idx) DO (
SET /A FileCount+=1
SET FileName="%%~B"
)
IF !FileCount! EQU 1 (
ECHO Renaming !FileName! to !ParentFolder!.idx
REN !FileName! !ParentFolder!.idx
)
IF !FileCount! GTR 1 (
SET FileCount=0
FOR %%B IN ("%%~A"\*.idx) DO (
SET /A FileCount+=1
ECHO Renaming "%%~nxB" to !ParentFolder!_CD!FileCount!.idx
REN "%%~B" !ParentFolder!_CD!FileCount!.idx
)
)
)
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: May 9th, 2009, 8:50 am
by PiNPOiNT
Can you give me a summary of what your file's look like in your movie folder for a movie that's not working like in your example before running it?
a screen shot of the lord of the rings folder for example would be great.
So far i haven't been able to reproduce it
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: May 9th, 2009, 2:03 pm
by feerlessleadr
Hi pinpoint,
I just tested the script again with LOTR2 and LOTR3 with their original names and it happened again.
Here is a screen of LOTR2 folder:
Here is a screen of the LOTR3 folder:
and here is the output log for LOTR3 (I already pasted LOTR2 above:
Code: Select all
*************CHECKING FOR AVIs********************
Renaming "alli-lotr.rotk.ee.cd1.avi" to "The Lord of the Rings- The Return of the King (2003) (Extended) (3 CD)"_CD1.avi
Renaming "alli-lotr.rotk.ee.cd2.avi" to "The Lord of the Rings- The Return of the King (2003) (Extended) (3 CD)"_CD2.avi
Renaming "alli-lotr.rotk.ee.cd3.avi" to "The Lord of the Rings- The Return of the King (2003) (Extended) (3 CD)"_CD3.avi
Renaming "The Lord of the Rings- The Return of the King (2003) (Extended) (3 CD)_CD1.avi" to "The Lord of the Rings- The Return of the King (2003) (Extended) (3 CD)"_CD4.avi
*************CHECKING FOR MKVs********************
*************CHECKING FOR WMVs********************
*************CHECKING FOR NFOs********************
*************CHECKING FOR IMGs********************
*************CHECKING FOR ISOs********************
*************CHECKING FOR Ts Files*****************
*************CHECKING FOR SUBs********************
*************CHECKING FOR SRTs********************
*************CHECKING FOR IDXs********************
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: May 13th, 2009, 10:59 am
by feerlessleadr
Hi Pinpoint, just wondering if you were able to reproduce the problem I was having
Thanks so much for your help with this
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: May 13th, 2009, 12:11 pm
by PiNPOiNT
Sorry dude, i haven't been able to reproduce it.
Are you actually running it? or just viewing the test output for the time being.
You could try copying just that movie somewhere else and run it for real on it and see if it still screws up.
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: May 14th, 2009, 9:58 am
by feerlessleadr
yea, that is the actual script running and not just the test script.
I actually have copied those two movies into a test folder and tried the actual script again but with the same results.
I will try running just your script without my additions and see if that makes a difference.
::UPDATE:: Ok so now I don't know what is going on. I just ran the test script on it in my test folder, and it reported that everything would me renamed properly.
I then ran your original script and it renamed it properly. I then modified your original script by hand to include idx, sub and srt files and it renamed them properly, I then re-ran my old modified script again and it renamed them properly.
So at this point, I have no idea what is wrong, perhaps it was just the volume of movies that I threw at it (almost 700), I don't know.
Thanks for your help.
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: September 14th, 2009, 10:11 am
by koolmatt
Hi PinPoint;
Using too your awsome script, but need support to fix a little bug.
I'm using
http://mymovies.dk, wich got a monitoring folder scan. Mean, each time I add a movie into this monitoring folder, it adds metadata and jpg about the video. prg scan directory name of the imported video, and when i'm using your script, mymovies adds to fast the new directory, because it adds as "UNPACK name of the new vid"....
After operation, when i go to my videos directory, i can see that new imported directory has been renamed without UNPACK mention, but unfortunately, it's too late, as monitoring folder has already scan and save unpack directory.
So my question is: could you add in your script a temp folder step?
Mean, i redirigate movies category to a temp directory, so your script will run correctly, but after that, could you add a command to move all stuff in temp directory to my movies directory? In this way, i'll not suffer anymore of unpacking step...
BR;
Matthieu.
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: November 7th, 2009, 6:40 am
by hopester
Thanks for the windows script pinpoint, it was what I as looking for to tidy up my movie folder.
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: December 5th, 2009, 6:11 pm
by chris1712
Hi there, I wonder if you could advise me on how to modify your script to do the following.....
What I want is, to rename the movie file to the name of the parent folder (or nzb name) but extract to one main dir.
Eg.....
NOT
Z:\HD Movies\Watchmen Directors Cut (2009)\Watchmen Directors Cut (2009).mkv
This instead.....
Z:\HD Movies\Watchmen Directors Cut (2009).mkv
Make sense? I've tried editing your bat but windows scripting is not my forte. How does sab pass the names etc. as arguments to the script? If I can work that our I think I can modify it how I need.
Thanks for any help,
Chris
Re: Rename movie to parent folder name (Now with a windows version too!)
Posted: December 5th, 2009, 8:40 pm
by rollingeyeball
Looks like this is a good script!
Sorry, I have nothing to add. I'm subscribing to the thread.