Skip to content

Instantly share code, notes, and snippets.

@MetehanYurtseven
Last active April 1, 2025 21:35
Show Gist options
  • Save MetehanYurtseven/b551d13b76a75441e88c20bbb9003a25 to your computer and use it in GitHub Desktop.
Save MetehanYurtseven/b551d13b76a75441e88c20bbb9003a25 to your computer and use it in GitHub Desktop.
Easy Audible Chapter Scraper - JavaScript Console
// This simple js script collects chapter titles of an audiobook from audible and
// is used to apply it to an .m4b audiobook.
// Following steps are required to create an .m4b audiobook with chapters:
//
// 0. (optional) use following tool to concat multiple mp3 to single m4b: https://gist.github.com/butuzov/fa7d456ebc3ec0493c0a10b73800bf42?permalink_comment_id=2830778#gistcomment-2830778
// 1. Export metadata of .m4b using "ffmpeg -i book.m4b -f ffmetadata metadata.txt"
// 2. Login to Audible and open a specific audiobook
// 3. Open console panel (Control+Shift+J) and run this script inside the JS Console
// 4. Paste returned content at the end of the metadata or replace existing chapters and save the file
// 5. Apply new metadata using to new .m4b using "ffmpeg -i book.m4b -i metadata.txt -map_metadata 1 -map_chapters 1 -codec copy book_with_chapters.m4b"
(() => {
let asin = $('[name="asin"]')[0].value; // It can be any ID
fetch(`https://www.audible.de/audible-api/1.0/content/${asin}/licenserequest`, {
"body": "{\"response_groups\":\"chapter_info,content_reference,last_position_heard\",\"chapter_titles_type\":\"Flat\",\"supported_drm_types\":[\"Mpeg\",\"HlsCmaf\",\"FairPlay\"],\"use_adaptive_bit_rate\":true,\"consumption_type\":\"Streaming\"}",
"cache": "default",
"credentials": "include",
"headers": {
"Accept": "application/json",
"Client-ID": "WebPlayerApplication",
"Content-Type": "application/json"
},
"method": "POST"
}).then(res => res.json()).then(a => {
with (a.content_license.content_metadata.chapter_info.chapters) {
let data = "";
forEach(c => {
data += `[CHAPTER]\nTIMEBASE=1/1000\nSTART=${c.start_offset_ms}\nEND=${c.start_offset_ms + c.length_ms}\ntitle=${c.title}\n`;
})
console.log(data)
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment