#1 2007-05-10 19:32

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

track n of N tracks for audio books, way to get N?

I am always looking at my little mp3 player screen not only to see what track I am on, but am I on track 3 of 4, or track 3 of 18 tracks.  "nn-NN Audio_Book_Title.mp3"

Serializer sets track "nn", but right now I have to change a rule to set the total number of tracks "NN" for each book.  No big deal but I have over 400 books.

I have looked, can't find a way (or meta tag) for a rule to get/determine mp3 file count for the book/folder.  Could this be possible in the Pascal rule?

Sorry if my question is vague, so many all nighters, my eye's are crossing.

Fathom

PS.
ReNamer is wonderful.  I love the power and friendly too, rare to have both to such degree!

Offline

#2 2007-05-10 21:32

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: track n of N tracks for audio books, way to get N?

Hi Fathom!

Can you explain "get/determine mp3 file count for the book/folder"? What do you mean by that "mp3 file count"? Is it something that is stored in the filename, or in the ID3 tags of your MP3's? If so, you can probably access them via ReNamer's ID3_* meta tags, for example: ID3_TrackNo. More details/examples would be helpful...

Offline

#3 2007-05-10 23:01

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

Re: track n of N tracks for audio books, way to get N?

I was afraid I was being vague.

I have audio books in folders of 8 to 30 tracks each.  What I am trying to do is rename files for each book in the same manner pages of a document can be named;  page 1 of 12, page 2 of 12, page 3 of 12, ...

For example, from:
Shelters of Stone-Part 1.mp3
Shelters of Stone-Part 2.mp3
Shelters of Stone-Part 3.mp3
...
Shelters of Stone-Part 12.mp3

To:
01-12 Shelters of Stone.mp3
02-12 Shelters of Stone.mp3
03-12 Shelters of Stone.mp3
...
12-12 Shelters of Stone.mp3

I have a rule set to do all this for files in any given audio book folder except for determining the total number of tracks for that book, in this case "12" the total number of tracks for that book, which I have to set manually for each book. 

ID3_TrackNo provides the specific track, but there is no tag for "total number of tracks" or "number of last track".  I use "Serialize" so I can pad.

I have been looking into Pascal tutorials.  The only programming I have done since I retired 1992 are macro scripts.  Before that was 25+ years of ASM and state machine design.  So I'm feeling stupid.

Thanks for the response and sorry for the confusion,
Scott

ps.
this is what I have to generically handle most circumstances:
Snap1.jpg

Last edited by Fathom (2007-05-10 23:02)

Offline

#4 2007-05-10 23:50

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: track n of N tracks for audio books, way to get N?

Ahh.. Ok, now I see the problem smile

You said that you have your audio books in folders, right? Does that mean that in each folder there is always only 1 audio book? So, the amount of mp3's in each folder would be the same as a number of track in the book? If so - PascalScript can do it! We can scan the folder of each file for amount of mp3's in it, and use that as a total number of tracks. Will that work for you?

Yee, there is quiet a difference between Pascal and ASM big_smile

Offline

#5 2007-05-11 00:10

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

Re: track n of N tracks for audio books, way to get N?

Yes, yes, and yes.  You have the idea even better than I explained it, since there are none mp3 files I don't want to count (such as folder.jpg).

I been trying to crash course pascal, I have used it before on a novice level many, many years ago, but I'm slow.

Your Pascal tools in ReNamer (prefab scripts, help, try to compile) seem to be a great resource.  I thought I would study your prefab scripts in ReNamer as an initial tutorial.

Fathom

Offline

#6 2007-05-11 00:26

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: track n of N tracks for audio books, way to get N?

This will insert as prefix the number of mp3's from folder, here is the code:

var
  Folder: WideString;
  Files: TStringsArray;

begin
  SetLength(Files, 0);
  Folder := WideExtractFileDir(FilePath);
  WideScanDirForFiles(Folder, Files,
    False, False, False, '*.mp3');
  FileName := IntToStr(Length(Files)) + FileName;
end.

P.S. There is only one problem - for each file there will be a scan of a folder. Even tho Windows caches these types of repeated requests, it might get a bit slow when processing 100's of files.

Last edited by den4b (2007-05-11 00:32)

Offline

#7 2007-05-11 00:40

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

Re: track n of N tracks for audio books, way to get N?

I put your script to where I had my second rule (pictured above) and It works perfect.

Thanks so much.  I will study it, and the other scripts in this forum.  I have hundreds of book folders to process so this is a real help!!!  I just started using ReNamer, I really like well written powerful intuitive programs like this!  It is a gem.

I am still discovering great little tools and tricks with it.

Thanks again for your time and patience,
Fathom

Offline

#8 2007-05-11 00:51

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: track n of N tracks for audio books, way to get N?

Glad to be of help! Happy renaming big_smile

Offline

#9 2007-05-25 03:44

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

Re: track n of N tracks for audio books, way to get N?

Thanks den4b,
You got me started,

The goal was to standardize audio track names, and to prefix them with [current track]-[total tracks], without renaming text and image files within same folder, and to work recursively.  One mistake serializing audio book tracks would be a nightmare.

To be honest I don't know squat.  All I know of compiled languages I picked up in this forum past couple of days.  den4b got me started with first script and I hacked the hell out of "serialize duplicates" until things started to make sense and something worked.   I thought the forum could use one more example since I couldn't find any tutorials in PascalScript.

Goals and Problems Resolved:
1.   determine total number of tracks in audio book folder (that also contain text and image files) -thanks den4b
2.   correctly serialize tagless mp3 tracks in folders and sub folders (that also contain text and image files)
3.   rename mp3 files only, correctly prefixed with [CURRENT TRACK]--[TOTAL TRACKS]
4.   cleanup and normalize various naming schemes, especially for small MP3 player screen viewing
5.   rename these files from tree level in one pass (recursive)
6.   be able to re-process the same tree without effecting files already renamed
X.  The only complication is if ReNamer column sort is reverse natural order, that would reverse serial track order.  Use "Name Digit" column for sorting.  (select via context menu on column name)

An audio book with tracks out of sequence is a nightmare.

Tested with a directory tree four folders deep, four folders wide at base, each folder unique, containing various naming schemes (10 folders, 130 files).

Books have any number of title schemes that I would like to standardize:
        original                                               renamed
The Quiet Night track 1.mp3       01-12 Quiet Night.mp3
Silver Quest-Part3.mp3             03-42 Silver Quest.mp3
01 The Longest Day.mp3           01-18 Longest Day.mp3
track002 - Day and Night.mp3      03-09 Day and Night.mp3
Dog Days 1.mp3                   01-07 Dog Days.mp3
Dog Days 2.mp3                   02-07 Dog Days.mp3
...                              ...
Dog Days 07.mp3                   07-07 Dog Days.mp3

The numbers represent:  [CURRENT TRACK OF BOOK]---[TOTAL TRACKS IN BOOK].  Track numbers are prefixed so to always be visible on small mp3 player screens.

n_of_N_tracks.jpg

Total number of tracks in audio book:

//--------  TOTAL TRACKS     <mp3>  -------//

const
  AudioExt = '.mp3';

var
  AudioFiles: TStringsArray;
  AudioTrack, CurrentFolder: WideString;

begin
  AudioTrack := WideChangeFileExt(FilePath, AudioExt);
  if WideFileExists(AudioTrack) then
  begin
      SetLength(AudioFiles, 0);
      CurrentFolder := WideExtractFileDir(FilePath);
      WideScanDirForFiles(CurrentFolder, AudioFiles, False, False, False, '*.mp3');
      if Length(AudioFiles) < 10 then
      FileName := '0' + IntToStr(Length(AudioFiles)) + ' ' + FileName
      else FileName := IntToStr(Length(AudioFiles)) + ' ' + FileName;
  end;
end.

Current Track in audio book:

//---  CURRENT TRACK   <mp3>  ---//

{      CREATE ARRAY       }
var
  Files: TStringsArray;

procedure Add(const S: WideString);
begin
  SetLength(Files, Length(Files)+1);
  Files[Length(Files)-1] := S;
end;

{   PASS THRU MATCHING FILE NAMES   }
var
  I: Integer;

function Exists(const S: WideString): Boolean;
begin
  Result := False;
  for I:=0 to Length(Files)-1 do
    if WideSameText(Files[i], S) then
      begin
        Result := True;
        Break;         {I'm not sure this needs to be here}
      end;
end;

{        PAD PREP         }
function PadNum(const Num, NewLength: Integer): string;
begin
  Result := IntToStr(Num);
  while Length(Result) < NewLength do
    Result := '0'+Result;
end;

{   SERIALIZE   <mp3>     }
var
  NewFileName: WideString;
  Counter: Integer;
begin
  Counter := 1;
  NewFileName := FileName;
  if WideExtractFileExt(FileName) = '.mp3' then
  NewFileName :=  PadNum(Counter,2) + '-' + WideExtractBaseName(FileName) + WideExtractFileExt(FileName);
  while Exists(NewFileName) do
    begin
      NewFileName :=  PadNum(Counter,2) + '-' + WideExtractBaseName(FileName) + WideExtractFileExt(FileName);
      Counter := Counter + 1;
    end;
  FileName := NewFileName;
  Add(FileName);
end.

I may eventually create script to add author prefix to audio book folders, using pascal to read authors name from synopsis text file within the folder, but I have already renamed all folders manually.
Audio book folders are named by author such:  (Huxley) Doors of Perception

Fathom

Last edited by Fathom (2007-05-25 11:27)

Offline

#10 2007-05-26 09:12

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: track n of N tracks for audio books, way to get N?

It's good to see people "take off" on PascalScript like that! big_smile

You "TOTAL TRACKS" script looks fine, but there are few things about "CURRENT TRACK" script that you should know:

1) "var I: Integer;" is declared globally, that means anything can access/change that variable.
You should put it in the local declaration for the function that uses it, like that:

function Exists(const S: WideString): Boolean;
var I: Integer;
begin ...

2) "Break;" - it is there for optimization. Once you found an item in the list, you don't have to continue searching until you reach the end of the list, you can break the loop straight after you find the string/filename - and that's exactly what "Break" does.

3) "if WideExtractFileExt(FileName) = '.mp3' then" - two problems with it. First, extension ".MP3" not equals to ".mp3", because comparison is done in a case sensative manner. the proper way to do it will be: "if WideSameText('.mp3', WideExtractFileExt(FileName)) then". The second problem is the fact that if/else statement for only for the immediately following line of code. If you want the code to get executed ONLY for MP3's, you have to put everything after the "IF" statement into the "begin ... end", otherwise that if statement will not make any sense. Example:

 if WideSameText('.mp3', WideExtractFileExt(FileName)) then
  begin
    NewFileName :=  PadNum(Counter,2) + '-' + WideExtractBaseName(FileName) + WideExtractFileExt(FileName);
    while Exists(NewFileName) do
      begin
        NewFileName :=  PadNum(Counter,2) + '-' + WideExtractBaseName(FileName) + WideExtractFileExt(FileName);
        Counter := Counter + 1;
      end;
    FileName := NewFileName;
    Add(FileName);
  end;

Also, "WideExtractBaseName(FileName) + WideExtractFileExt(FileName)" is probably the same as "FileName" on its own. By the way, what exactly are you trying to do with the "CURRENT TRACK" script? Serialize duplicated new names in the list? Or add a current track number?? Because if it a second one - it is really a bad way of doing it, because you could simply use Serialize rule.

PascalScript is eventually a Delphi/Pascal programming language, so if you are looking for sample examples or tutorials - type in Google: Delphi OR Pascal.

Last edited by den4b (2007-05-26 09:19)

Offline

Board footer

Powered by FluxBB