You are not logged in.
Pages: 1
Script to change TV show names:
* 123 1x23 [1x23] => s01e23
* 1234 12x34 [12x34] => s12e34
var
NazwaTemp: WideString;
Dlugosc, i, k: Integer;
StaryCiag, NowyCiag: String;
function CzyLiczba (const S: WideString): Integer;
begin
case S of
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
begin
Result := 1;
end;
else
begin
Result := 0;
end;
end; //case
end;
begin
NazwaTemp:=FileName;
Dlugosc:=Length(NazwaTemp)-3;
for i:=1 to Dlugosc do
begin
k:=CzyLiczba(NazwaTemp[i]);
if k = 1 then
begin
k:=CzyLiczba(NazwaTemp[i+1]);
if k = 1 then
begin
k:=CzyLiczba(NazwaTemp[i+2]);
if k = 1 then
begin
k:=CzyLiczba(NazwaTemp[i+3]);
if k = 1 then
begin
StaryCiag:=NazwaTemp[i]+NazwaTemp[i+1]+NazwaTemp[i+2]+NazwaTemp[i+3];
NowyCiag:='s'+NazwaTemp[i]+NazwaTemp[i+1]+'e'+NazwaTemp[i+2]+NazwaTemp[i+3];
FileName := WideReplaceStr(FileName, StaryCiag, NowyCiag);
Break;
end
else
if NazwaTemp[i-1]='x' then
if NazwaTemp[i-1]='X' then
else
begin
StaryCiag:=NazwaTemp[i]+NazwaTemp[i+1]+NazwaTemp[i+2];
NowyCiag:='s0'+NazwaTemp[i]+'e'+NazwaTemp[i+1]+NazwaTemp[i+2];
FileName := WideReplaceStr(FileName, StaryCiag, NowyCiag);
Break;
end
else
begin
StaryCiag:=NazwaTemp[i]+NazwaTemp[i+1]+NazwaTemp[i+2];
NowyCiag:='s0'+NazwaTemp[i]+'e'+NazwaTemp[i+1]+NazwaTemp[i+2];
FileName := WideReplaceStr(FileName, StaryCiag, NowyCiag);
Break;
end;
end
else;
end
else;
end
else;//1st if
end;//for
Dlugosc:=Length(NazwaTemp)-2;
for i:=3 to Dlugosc do
begin
if NazwaTemp[i]='x' then
begin
k:=CzyLiczba(NazwaTemp[i-1]);
if k=1 then
begin
k:=CzyLiczba(NazwaTemp[i-2]);
if k=1 then
begin
k:=CzyLiczba(NazwaTemp[i+1]);
if k=1 then
begin
k:=CzyLiczba(NazwaTemp[i+2]);
if k=1 then
begin
StaryCiag:=NazwaTemp[i-2]+NazwaTemp[i-1]+'x'+NazwaTemp[i+1]+NazwaTemp[i+2];
NowyCiag:='s'+NazwaTemp[i-2]+NazwaTemp[i-1]+'e'+NazwaTemp[i+1]+NazwaTemp[i+2];
FileName := WideReplaceStr(FileName, StaryCiag, NowyCiag);
StaryCiag:='['+NowyCiag+']';
FileName := WideReplaceStr(FileName, StaryCiag, NowyCiag);
Break;
end
else;
end
else;
end
else
begin
k:=CzyLiczba(NazwaTemp[i+1]);
if k=1 then
begin
k:=CzyLiczba(NazwaTemp[i+2]);
if k=1 then
begin
StaryCiag:=NazwaTemp[i-1]+'x'+NazwaTemp[i+1]+NazwaTemp[i+2];
NowyCiag:='s0'+NazwaTemp[i-1]+'e'+NazwaTemp[i+1]+NazwaTemp[i+2];
FileName := WideReplaceStr(FileName, StaryCiag, NowyCiag);
StaryCiag:='['+NowyCiag+']';
FileName := WideReplaceStr(FileName, StaryCiag, NowyCiag);
Break;
end
else;
end
else;
end;
end
else;
end
else;
end;//for
end.
EDIT: fixed missing BEGIN at the start of the last FOR LOOP.
Last edited by den4b (2014-02-13 12:39)
Offline
Good work!
Just a note, that script can occasionally get out of range errors because there is absolutely no range checking. It also has a an assumption that every file has an extension exactly 3 characters long, which might not always be true.
It might be better (and safer) to you simpler Regular Expressions which achieve the same result:
1) Replace expression \b(\d)x?(\d\d)\b with s0$1e$2 (this rule converts 123 1x23 [1x23] => s01e23)
2) Replace expression \b(\d\d)x?(\d\d)\b with s$1e$2 (this rule converts 1234 12x34 [12x34] => s12e34)
Offline
hello
Maybe add This too
Replace expression (\d\d)(\d\d)(\d\d) With S$1E$2E$3
because sometimes your are 2 episodes in 1 videos
Like This:
123435 >> S12E34E35
Offline
@den4b your regex work fine except for when there's a date in the file name. e.g. castle.2009.801.hdtv-lol.mp4
how do I get around this? (meaning, keeping the year, whole filename but get regex to replace 801 to s08e01)
also, how would I regex heroes.reborn.10102.hdtv-lol.mp4 into heroes.reborn.s01e01.s01e02.hdtv-lol.mp4?
lastly, there is no option (or planned) to have ReNamer monitor folders to do its tasks automatically?
Cheers
Offline
your regex work fine except for when there's a date in the file name. e.g. castle.2009.801.hdtv-lol.mp4
how do I get around this? (meaning, keeping the year, whole filename but get regex to replace 801 to s08e01)
also, how would I regex heroes.reborn.10102.hdtv-lol.mp4 into heroes.reborn.s01e01.s01e02.hdtv-lol.mp4?
lastly, there is no option (or planned) to have ReNamer monitor folders to do its tasks automatically?
Can you provide complete examples of input and output filenames?
P.S. Please do not resurrect topics which are years old. Start a new thread and link to relevant thread for reference when needed.
Offline
Pages: 1