Skip to content

Instantly share code, notes, and snippets.

@danielb2
Forked from nfriedly/chirp-audiobooks-downloader-readme.md
Created August 29, 2023 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielb2/682238fcdab39d552ae6086c927aa9ec to your computer and use it in GitHub Desktop.
Save danielb2/682238fcdab39d552ae6086c927aa9ec to your computer and use it in GitHub Desktop.
Chirp Audiobook Download Script

Chirp AudioBook Download Script

This script eases the process of downloading the audio files from Chirp Audiobooks. It uses the browsers console to generate a list of URLs, and then provides a list of wget commands to download them.

Tested with Firefox on MacOS. Might need some small tweaks for Windows.

Instructions

  1. Find the book in your Chirp Library
    • If you've already listened to it, you may need to move it back from your Archive
  2. Click the book to open Chirp's web player
  3. Open the browser's Web Developer Tools
  4. Copy-paste the script.js contents into the console and press [enter]
  5. Initiate the script:
    • If the book is already at the start, click Play (▶)
    • If the book is on any other track, open the Chapters menu (top left) and select the first Track
  6. Wait while the script advances through each track; it's saving the URLs in the background.
  7. When it reaches the final track, the script will print a list of commands to the console.
    • Expand this list (if necessary) (▸)
    • Copy-paste it to a command line and press [enter] to execute it.

Once the commands finish, you should have a new folder with a cover image and each of the tracks as .m4a files.

Enjoy!

const $ = document.querySelector.bind(document);
const title = $('h1.book-title').textContent;
const credits = [].slice.call(document.querySelectorAll('.credit'))
.map(n => n.textContent)
.join(' - ');
const dirname = `${title} - ${credits}`;
const commands = [
`mkdir "${dirname}"`,
`cd "${dirname}"`,
`wget -O "cover.jpg" ${$('.cover-image').src }`
];
let count = 0;
function addUrl(url) {
count += 1;
let trackNum = count.toString().padStart(2, "0");
const chapter = $('div.chapter').textContent;
commands.push(`wget -O "${title} - ${trackNum} - ${chapter}.m4a" "${url}"`);
}
function next() {
const btn = $('button.next-chapter')
if (btn.disabled) {
console.log(commands.join('\n'))
} else {
btn.click();
}
}
const audio = $('audio');
Object.defineProperty(audio, "src", {
get() {
return '';
},
set(url) {
setTimeout(() => {
addUrl(url);
next();
}, 500);
},
enumerable: true,
configurable: true,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment