Well, that's that coded, also added a list-only option that outputs information about all the chapters, or just those chapters you've specified.
Meanwhile, just re-watching the last episode of #AmericanGods for season 2.
Roll on season 3.
Battle plans versus first contact with the enemy springs to mindΒ‘;* #AudioBreak
Love it when you write some code to do something, then when using it you realise that it would be really handy if it could do it slightly differently. Just realised it might be nice if you could get just a specific chapter, or parhaps set of chapters from an audiobook, rather than having to grab them all at once #AudioBreak
Coded some additional stuff, you can now turn debug on and off; and choose an output directory (which will be created if it doesn't already exist) both via command line options. Oh and if you're rude enough to want to interrupt the script it'll exit cleanly.
Thinking aloud...
Wondering how easy it would be to create a reverse #AudioBreak that takes a load of mp3 files and pumps out a properly formatted m4b file.
It would need to use ffprobe to get the various bits of info from each mp3 file needed to recreate the chapter list and then ffmpeg to concat them all together, plus the chapter metadata, plus optional cover image.
Something to think about, once I have AudioBreak coded a little more intelligently.
Some #audiobook files have an embedded cover image so I get #ffmpeg to ignore that using '-vn' bit, and also tell it to ignore the chapter metadata using the '-map_chapters -1' bit.
#audiobreak #audiobook #ffmpeg
Incidentally...
1. Getting chapter info:
ffprobe -i <filename.m4b> -print_format json -show_chapters -v quiet -hide_banner
The output of which I direct into a tempfile.
2. Read in the tempfile, get the chapter ids, start_time, and end_time. Then use:
ffmpeg -ss <start_time> -to <end_time> -i <filename.m4b> -v quiet -hide_banner -vn -map_chapters -1 ./temp/<chap_id>.mp3
In a loop, to gradually grab each slice of audio into a separate mp3 file.
What I should really do is modularise them some more, so that the 'user is an idiot' stuff is shared between the two projects, so I only need to add to that in one place to have it covered in both.
That'll be for another time, when I'm sufficiently bored enough to mess with it again (:*
#python #audiobreak #movietest
I cheated just a little, since I reused code from my #MovieTest python script. Filed some of the serial numbers off, changed or removed code here and there (:*
I like some of the error and 'user is an idiot' stuff I've added to movie-test, and thought using that as a basis for #AudioBreak was better than going back to coding as if the user would never try to use it wrongly.