sandreas / m4b-tool

m4b-tool is a command line utility to merge, split and chapterize audiobook files such as mp3, ogg, flac, m4a or m4b
MIT License
1.15k stars 76 forks source link

Rename chapters when converting #216

Closed StefanDorschu closed 1 year ago

StefanDorschu commented 1 year ago

I would like to rename the chapters instead of using the original file names.

Simple as

Chapter 1 Chapter 2 Chapter 3

Is that possible?

sandreas commented 1 year ago

@HabelStefan Unfortunately this is not possible by a simple step or parameter... However, with tone you could write your own little JavaScript tagger, that should do what you like:

  1. Create a backup of the original file (before you change something you did not intend)

2 . Create a file reindexChapters.js:

// reindexChapters.js 
function reindexChapters(metadata, parameters) {
  var count = metadata.Chapters.Count;
  var newChapters = [];
  console.log("found " + count + " chapters to reindex");
  for(var i=0;i<count;i++) {
    metadata.Chapters[i].Title = "Chapter " + (i+1);
  }
}

tone.RegisterTagger("reindexChapters");
  1. Run the following command to check the results are to your liking

    tone tag "my-audiobook.m4b" --taggers="reindexChapters" --script="reindexChapters.js" --dry-run
  2. Run the command without --dry-run to actually perform the changes

    tone tag "my-audiobook.m4b" --taggers="reindexChapters" --script="reindexChapters.js"
StefanDorschu commented 1 year ago

Thank you, give it a try !

StefanDorschu commented 1 year ago

Works as expected. How can i run it for every file within a directory?

sandreas commented 1 year ago

Should work... just try with --dry-run to check if it works as expected:

tone tag "./my-audiobook-folder" --taggers="reindexChapters" --script="reindexChapters.js" --dry-run
sandreas commented 1 year ago

Closed due to no further feedback. Feel free to reopen.

StefanDorschu commented 1 year ago

I'm running into an issue which large audiobooks (do know if its the file size (all are bigger than 1GB) or the chapter number).

found 563 chapters to reindex
Error: Object reference not set to an instance of an object.

Any ideas?

Best regards,

Stefan