Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save neofright/3294e3b09bb06643ea75c395f10a56cf to your computer and use it in GitHub Desktop.
Save neofright/3294e3b09bb06643ea75c395f10a56cf 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 generate a cue sheet for an .m4b audiobook.
// The following steps are required to create the cue sheet with chapters:
//
// 0. Use Libation or a similar tool to get your .m4b saved to disk.
// 1. Login to Audible and open a specific audiobook.
// 2. Open the console panel (Control+Shift+J) and run this script inside the JS Console.
// 3. Copy and paste the returned content into a .cue file.
// 4. Add a '"FILE "name_of_audio_book_file.m4b" MP3' entry to the top of the cue sheet (without single quotes).
(() => {
const urlParams = new URLSearchParams(window.location.search);
const asin = urlParams.get('asin');
fetch(`https://${window.location.hostname}/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 = "";
i=1;
forEach(c => {
minutes = Math.floor(c.start_offset_sec / 60);
seconds = c.start_offset_sec % 60;
timeString = minutes.toString().padStart(2, '0') + ':' + seconds.toString().padStart(2, '0') + ':00';
data += `TRACK ${i} AUDIO\n TITLE "${c.title}"\n INDEX 01 ${timeString}\n`;
i++;
})
console.log(data)
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment