#1 2014-03-07 23:48

medwatt
Member
Registered: 2013-08-09
Posts: 4

Rename episodes based on external list of names

Hello,
I know that the title is not very descriptive so here's what I am asking. I have a lot of video files for several TV serials labelled as such: S01E02, S02E07 and so on. I have a text file which has the name of every episode such as:
S01E02 - The Man from The Blue
S02E07 - The Woman in Red
etc . . .
What I want is a way to append those names in the list to their corresponding video files. So if video name is S01E02 then it should look in the text file for the title of that video and append it to the video name.

Thanks

Offline

#2 2014-03-08 01:20

medwatt
Member
Registered: 2013-08-09
Posts: 4

Re: Rename episodes based on external list of names

Sorry, I wrote a Pascal Script for my prior request. Here is it if anyone is interested :

1. First I had to adjust the file names so that they correspond to those in the txt files with RegEx. I am looking for a string like S02E04 or S1E4 or S003E004 etc within the file name.

Expression: .*(S[0-9]{1,3})E([0-9]{1,3}).*
Replace: S$1E$2

2. Now for the pascal script. My script might not be the most efficient in the world but it does the job. I learned PascalScript just a few minutes ago smile! Note the text file I'm reading from is written like this:
S02E04 - Bla Bla Bla
S04E12 - Ha Ha Ha

var
  i, txtLines: Integer;
  oldName, segName: WideString;
begin
	txtLines := FileCountLines('C:\Names.txt');
	oldName := WideExtractBaseName(FileName);
        Repeat
		segName := Copy(FileReadLine('C:\Names.txt', I),0,6);
		i := i+1;
	Until (segName = OldName) OR (i = txtLines);

	FileName := FileReadLine('C:\Names.txt', i-1) + WideExtractFileExt(FileName);
	i := 0;
end.

Last edited by medwatt (2014-03-08 01:28)

Offline

#3 2014-03-08 18:23

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Rename episodes based on external list of names

Your PascalScript is of course more generic and thus more powerful, but if you had files like say:

S01E01.mkv
S01E02.mkv
S01E03.mkv

and Names.txt had:

Name of Episode #1 of Season #1
Name of Episode #2 of Season #1
Name of Episode #3 of Season #1

i.e. a 1:1 correspondence between files and names, you could simply use the UserInput rule to pull the names in from the text file and apply them like so:

UserInput.png

Offline

#4 2014-03-09 03:05

medwatt
Member
Registered: 2013-08-09
Posts: 4

Re: Rename episodes based on external list of names

I tried what you're saying. The method you mentioned has a limitation such that the files you want to rename have to be in the same order as the names in the text file. I actually just copied the list of episodes from the internet into a text file. I had some episodes missing meaning that not all of the videos will be in the correct order thereby renaming incorrectly.

Offline

#5 2014-03-09 20:28

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Rename episodes based on external list of names

medwatt wrote:

I tried what you're saying. The method you mentioned has a limitation such that the files you want to rename have to be in the same order as the names in the text file.

Of course, that's why I specifically mentioned that you need to have "a 1:1 correspondence between files and names". smile

Offline

Board footer

Powered by FluxBB