#1 2009-08-22 10:12

rockerist
Member
Registered: 2009-08-22
Posts: 5

PascalScript and ID3 - building new folder structures

Hi,
I'm new to pascal so I need some help. Basically, I need to tag and rename a whole bunch of mp3s (100s of GB). I do the tagging part with MusicBrainz picard, and I found ReNamer to be the most intuitive file renaming program.

I found this script and modified it to rename album folders the way I want it. The thing is, I could only figure out how to rename the folder that contains audio files - and that's the problem.
The folder structure on my music disk should look like this:
Artist/[Year] Album/Artist - Track# - Title.mp3

Ok, i do the .mp3 renaming with musicbrains. I also use the script from above to get the album folder to look like '[Year] Album' (I inserted the brackets via insert rule not the pascal script). The problem is obviously the artist folder, since it has no .mp3 files itself, only subfolders.

This is an example of how it should be:

Velvet Revolver\[2004] Contraband\Velvet Revolver - 01 - Sucker Train Blues.mp3
Velvet Revolver\[2007] Libertad\Velvet Revolver - 01 - Let It Roll

There is another problem. The folders now are a bit chaotic:
C:\rename\velvet revolver\Contraband (2004)\Velvet Revolver - 01 - Sucker train Blues.mp3 (already did the tagging and mp3 file renaming)

but the other album is not within the velvet revolver root folder:
C:\rename\Velvet Revolver - Libertad [2007][CD+SkidVid_mpeg+Cov]192Kbps [skirgsk]

So, i drag 'C:\rename' to ReNamer. The folder structure varies, but in the end it should all be the way described above. Is this possible? smile

Many thanks

Offline

#2 2009-08-22 10:22

rockerist
Member
Registered: 2009-08-22
Posts: 5

Re: PascalScript and ID3 - building new folder structures

While reading my post again I realized a much simpler way to do this, but, i still need help doing it. big_smile
The album folder could initially be renamed into 'Artist [Year] Album' and then split into Artist\[Year] Album. How do I do this?

Offline

#3 2009-08-22 12:57

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: PascalScript and ID3 - building new folder structures

I guess you've got all tags nice and tidy.
If so, I would suggest filtering files to load only mp3 files into ReNamer (so you won't get "[] - " as a filename when no mp3 tag will be found) and using such set of rules:
1. Delete rule: (from position 1, till the end)
2. Insert rule: (as prefix, skip extention)
"C:\temp_folder\:ID3_Artist:\[:ID3_Year:] :ID3_Album:\:ID3_Artist: - :ID3_Title:"

You can choose anything instead of "C:\temp_folder\" but choose a new or empty folder.
WARNING: this is not the best solution if you have any .jpg or other files in the folder structure as you will have to move them manually.
If you need other then mp3 files to be processed as well, let us know. You will need a PascalScript for that.


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#4 2009-08-22 14:52

rockerist
Member
Registered: 2009-08-22
Posts: 5

Re: PascalScript and ID3 - building new folder structures

Thanks, this solves one of my problems, however, I have cover files and playlists I would like to move accordingly as well. I also think using pascal is a lot faster, since with your script i would be renaming (and moving) all the mp3 files, and 500GB is a lot of mp3 files (and ~ ten times less the albums).
That's why I think it's important to work with folders and subfolders, not the mp3s.

Offline

#5 2009-08-22 18:20

prologician
Member
Registered: 2009-01-30
Posts: 84

Re: PascalScript and ID3 - building new folder structures

Considering that there is album art to play with (I presume this already exists within the "[Year] Albumname" folder), it is a bit trickier to play with.

First, make sure that you have Renamer to treat folders as files, so that you can edit that stuff directly (Settings > Filters, and tick the right checkbox).

Once that's done, the big things that the script will need are to (1) look into this folder and pick out some MP3 within it using "WideScanDirForFiles()", and (2) calculate the artist metatag on that MP3 using the "CalculateMetaTag()" function. Since the latter asks for a file path as the first parameter, we can can pass it the full path gathered from the first function, and that should give you the info you wanna get. smile

Offline

#6 2009-08-22 21:56

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: PascalScript and ID3 - building new folder structures

OK, so let's do it your way.

You need to load only folders (with subfolders) into ReNamer (that's doable with filters as prologician pointed out).

And the script looks like this:

const
  MASK = '*.mp3';

 
var
  MasterFile: WideString;
  Artist, Album, Year : WideString;
 
function FindMasterFile(const Folder: WideString): WideString;
var
  Files: TStringsArray;
begin 
  Result := '';
  SetLength(Files, 0);
  WideScanDirForFiles(Folder, Files,
    False, False, False, MASK);
  if Length(Files) > 0 then
    Result := Files[0];
end;
 
begin
  if WideDirectoryExists(FilePath) then
  begin
    MasterFile := FindMasterFile(FilePath);
    if MasterFile <> '' then
    begin
      Artist:=CalculateMetaTag(MasterFile, 'ID3_Artist');
      Album:=CalculateMetaTag(MasterFile, 'ID3_Album');
      Year:=CalculateMetaTag(MasterFile, 'ID3_Year');
      FileName := 'C:\Temp_Folder\'+Artist+'\['+Year+'] '+Album;
    end;
  end;
end.

In the line:

      FileName := 'C:\Temp_Folder\'+Artist+'\['+Year+'] '+Album;

You need to choose appropriate C:\Temp_Folder.
The files should be moved together with the folders.
I would also suggest to sort files (folders) in the files table in leaf-to-root order (by sorting by Folder column).

Moving to the temp folder is quite important as we need explicit path to get predictable results. You don't have to use a temp folder only if your structure before renaming looks like this:
MP3\Album 1
MP3\Album 2 and so on...


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#7 2009-08-23 09:23

rockerist
Member
Registered: 2009-08-22
Posts: 5

Re: PascalScript and ID3 - building new folder structures

Thank you so much smile

One more thing - is there a list of tags renamer can access with pascal? Tags like original year and album artist? The first one indicates that the folder structure would represent the exact album publishing sequence, and the second one prevents soundtracks and other various artists releases to be scattered all over.

Offline

#8 2009-08-23 11:42

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: PascalScript and ID3 - building new folder structures

The list of tags you may find in the Insert rule. There is a tiny icon "Insert metatag".


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

Board footer

Powered by FluxBB