Rename Files/Folders based upon database entries

Comments on existing version & Suggestions for future versions. If you want a new feature suggest it here. Discussions about beta versions also come in this section.
Post Reply
Donald24
Posts: 7
Joined: 2009-03-04 15:50:59

Rename Files/Folders based upon database entries

Post by Donald24 »

Hi there,

I am using AMC for about a year now, and my movie-db grew to more than 600 movies. It's great to have that URL field pointing to the files, so I can use AMC or even ANTviewer to directly play my selection.

I recently restructured my folder-strategy, and what annoyed me there is that cryptic name, the releases have when coming out of the download-pipe.

Those cryptic filenames/paths like \Escape.2.2008.1080p.BluRay.AC3.DL.x264.dxva-HDC\Escape.2.2008.1080p.BluRay.AC3.DL.x264.dxva-HDC.mkv
could be elegantly renamed to its values in the datebase.
So scripting a rename of the paths and files to a much shorter an uniforming look like for example \Escape.2\Escape.2.2008.mkv (and of course updating the URL-field) would be a great feature. It would save me countless hours doing that by hand.

I saw on the site a tool named antrenamer, and I wished it would do that... You just need to merge that into AMC ;)

Greeting and thanks for that program,

Don
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Hi,
Actually using AMC's scripting engine, you can already do it.
There is a "MoveFile" function that allows to rename/move a file.
So all what you have to do is to build a new path & name, call MoveFile, and if it succeeds also update the "URL" field with the new path & name.
If you can't write the script yourself, maybe I (or someone else who pass here before) can do it if you can say exactly what you want (i.e. how should the files be renamed).
Donald24
Posts: 7
Joined: 2009-03-04 15:50:59

Post by Donald24 »

Hey,

that would be amazing, if somebody could to this for me. I am yet new to programming scripts and would end up stuck, I think.

I have my movies in some separate paths like

d:\storage\movies-a
d:\storage\movies-b
d:\storage\movies-animation
d:\storage\movies-classics

and in this structure are movies each in a separate folder, like:

d:\storage\movies-b\The.Escape.2.2008.1080p.BluRay.AC3.DL.x264.dxva-HDC\Escape.2.2008.1080p.BluRay.AC3.DL.x264.dxva-HDC.mkv

What I would like, is a rename of the last directory to:
%name_translated%_%year% (with removed prefixes)
And the file in it, should read:
%name_org%_%languages%.extension (with removed prefixes)

and update the URLfield with:

d:\storage\movies-b\Flucht_2_2008\Escape_2_Ger_Eng.mkv

Thanks for any hint in the right direction!

Don
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I was going to say that I do not have time now, but if I do not do it now I'll never do it :D
And it could probably be useful for other people, for similar cases:

Code: Select all

program NewScript;
var
  url, newurl, root, folder, newfolder: string;
begin
  url := GetField(fieldUrl);
  folder := ExtractFilePath(url);
  root := ExtractFilePath(Copy(folder, 1, Length(folder) - 1));
  newurl := folder + GetField(fieldOriginalTitle) + '_' + GetField(fieldLanguages) + ExtractFileExt(url);
  if MoveFile(url, newurl) then
  begin
    SetField(fieldUrl, newurl);
    url := newurl;
    newfolder := root + GetField(fieldTranslatedTitle) + '_' + GetField(fieldYear);
    if MoveFile(Copy(folder, 1, Length(folder) - 1), newfolder) then
    begin
      newurl := newfolder + '\' + ExtractFileName(url);
      SetField(fieldUrl, newurl);
    end;
  end;
end.
Be careful when testing :D
This will fail if there are invalid characters in titles (like "?" etc.)
To make things clean, the StringReplace function should be used to handle these cases.
Normally it updates the URL field only when file was renamed, but I may have missed something, so do the test on few movies first.
About the prefix removed, extract code has to be added to handle that, either write it or correct by hand later :D
(again with StringReplace it should be easy)
Donald24
Posts: 7
Joined: 2009-03-04 15:50:59

Post by Donald24 »

Awesome!! :grinking:

Where can I find a listing of variables and functions from that scripting?

I tried this out, it does actually rename the files, but does not change the parents path.

So this:

D:\HS_downloads\Choke.Der.Simulant.2008.German.DL.DTS.1080p.BluRay.x264-R0CKED\Choke.Der.Simulant.2008.German.DL.DTS.1080p.BluRay.x264-R0CKED.mkv

becomes:

D:\HS_downloads\Choke.Der.Simulant.2008.German.DL.DTS.1080p.BluRay.x264-R0CKED\Choke_German, English.mkv

It does update the URLfield so that it still links correct!

Thank you, Antoine, for taking your time - you should do paypal or such, so I could buy you a beer or do you prefer wine? :wink:

Don
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Hmm normally it should update the folder too.
Maybe there was an invalid character in title field?
Did you try on more than one movie?
You can also set a breakpoint by clicking in the margin of the script editor, and advance line by line, checking contents of each variable to see if it is correct.
You can find more info on script in the help file, in "technical info" section.
But some of the functions used are are standard Delphi functions so I did not include these in the help file.
Donald24
Posts: 7
Joined: 2009-03-04 15:50:59

Post by Donald24 »

Hey,

I've just troubleshooted that directory error. It seems that delphi-code to rename directories does not work on Win7 (x64) (but DOES work on filenames :mad:)
It does rename everything under WinXP x86 correctly.

Thank you!!
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

hmm weird, as it just uses the MoveFile function from Win32 API. I wonder what we are supposed to use to rename folders then :??:
Donald24
Posts: 7
Joined: 2009-03-04 15:50:59

Post by Donald24 »

Sorted it out - it had nothing to do with the OS

:ha:

I was, ehm, focussing that folder in my file-explorer , that I wanted to rename. So it did just rename the file.

Embarrassed I am...

Beginners' fault ;)

Don
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

:lol: I could have think to that, though ;)
Post Reply