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 curl
or wget
commands to download them.
Tested with Firefox + Terminal on MacOS, and Firefox + PowerShell on Windows 10.
As an aside, I want to give a shout out to Libro.fm for providing a simple download button for each purchase. Then you don't need a script like this!
- Find the book in your Chirp Library.
- If you've already listened to it, you may need to move it back from your Archive.
- Click the book to open Chirp's web player.
- Open the browser's Web Developer Tools.
- Copy-paste the
script.js
contents into the console and press [enter]. - 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.
- Wait while the script advances through each track; it's saving the URLs in the background.
- It may say "There was an error loading your audiobook, please reload the page." under the Play button, ignore this.
- It may also show a number of URLs in red in the console, along with a warning after each one. Ignore these also.
- When it reaches the final track, the script will show a list of commands on the screen in a white box.
- Click once to highlight the complete list.
- Copy-paste it to a command line (Terminal, Power Shell, etc.) and press [enter] to execute it.
- Some command lines will begin executing immediately, however you still need to press [enter] to execute the final command.
- Once the commands finish, you should have a new folder with a cover image and each of the tracks as .m4a files.
- On macOS, type
open .
and press [enter] to view the files. - On Windows, type
explorer .
and press [enter] to view the files.
- On macOS, type
- Check the file size of each track:
- If any are 0 bytes, the download URL may have expired.
- In that case, go through the process again, but in step 7, first paste the commands into a text editor and delete everything except for the ones to download the 0-byte files.
- If any are 0 bytes, the download URL may have expired.
Enjoy!
Huh, apparently Chirp is a little inconsistent about their audio formats. I just checked 15 books from my library and 14 were indeed m4a's (AAC codec), but the last one was actually .mp3 (mislabeled as .m4a by this script.) Unfortunately, I'm not sure if there is a straightforward way to handle that, as we're setting the filename before the file is downloaded, but it has to be downloaded before we could do anything to determine the file type.
A renaming script for the ones that turn out to be mp3's would be a good idea, but probably not something I'm going to have done today.
@Bostwickenator I just took a look at your combining script - that's pretty cool! (I don't want to add the
cd ..
to the main script, because I think leaving the user in the book directory is a bit easier for new users, but of course you're welcome to add it to your fork :)I think what ultimately needs to happen is that someone needs to turn this into a browser extension that downloads all of the files to the user's Downloads folder, figures out the correct filename, and potentially even combines them to a single file with a wasm'd version of ffmpeg. I might do it eventually, but not today...