This repository contains two bookmarklets that help you download MP3 files from Libby audiobooks. These tools allow you to:
- Extract MP3 file URLs from a Libby audiobook
- Process cURL commands to generate download scripts
Note: These bookmarklets were generated using AI code generation.
To install these bookmarklets:
- Create two new bookmarks in your browser
- Name them something recognizable like "Libby Extract URLs" and "cURL Processor"
- For each bookmark, paste the corresponding JavaScript code below into the URL/location field
javascript:(function(){ try { const playButton = document.querySelector('button[aria-label="Play audiobook"].mini-player-playback-toggle'); if (playButton) { playButton.click(); } function triggerAdvance() { try { const jumpBtn = document.querySelector('button[aria-label="Advance 15 seconds"].mini-player-jump-ahead'); if (jumpBtn) { jumpBtn.click(); jumpBtn.dispatchEvent(new MouseEvent('mousedown', {bubbles: true})); jumpBtn.dispatchEvent(new MouseEvent('mouseup', {bubbles: true})); jumpBtn.dispatchEvent(new MouseEvent('click', {bubbles: true})); } } catch(e) { console.error(e); } } const advanceInterval = setInterval(triggerAdvance, 100); document.addEventListener('keydown', function escapeHandler(e) { if (e.key === 'Escape') { clearInterval(advanceInterval); document.removeEventListener('keydown', escapeHandler); } }); } catch(e) { console.error(e); }})();This bookmarklet helps process multiple cURL commands copied from Chrome's "Copy as cURL" feature. It performs the following operations:
- Extracts book title from the page title (from "Libby - Open: [Book Title]")
- Creates a directory based on the book title (with proper sanitization to lowercase with underscores)
- Removes duplicate URLs (keeping only the first instance of each unique URL)
- Removes all
-H 'range: bytes=*-' \lines - Adds sequential output filenames (
-o file-01.mp3,-o file-02.mp3, etc.) - Adds the
--locationargument to each curl invocation to follow redirects - Adds an mp3wrap command at the end to concatenate all downloaded files
- Adds a command to open the concatenated file in QuickTime Player
- Returns the processed commands in a text box for easy copying
javascript:(function(){const e=document.createElement("div");e.style.cssText="position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, 0.7);display: flex;justify-content: center;align-items: center;z-index: 10000;font-family: Arial, sans-serif;";const t=document.createElement("div");t.style.cssText="background-color: white;padding: 20px;border-radius: 5px;width: 80%;max-width: 800px;max-height: 90%;display: flex;flex-direction: column;overflow: hidden;";const n=document.createElement("h2");n.textContent="cURL Command Processor",n.style.cssText="margin-top: 0;color: #333;";const o=document.createElement("p");o.textContent='Paste cURL commands below and click "Process"',o.style.cssText="margin-bottom: 15px;color: #555;";const r=document.createElement("textarea");r.style.cssText="width: 100%;height: 200px;margin-bottom: 15px;padding: 10px;border: 1px solid #ccc;border-radius: 4px;resize: vertical;font-family: monospace;font-size: 14px;",r.placeholder="Paste cURL commands here...";const a=document.createElement("button");a.textContent="Process",a.style.cssText="background-color: #4CAF50;color: white;padding: 10px 15px;border: none;border-radius: 4px;cursor: pointer;font-size: 16px;align-self: center;margin-bottom: 15px;";const l=document.createElement("textarea");l.style.cssText="width: 100%;height: 200px;margin-bottom: 15px;padding: 10px;border: 1px solid #ccc;border-radius: 4px;resize: vertical;font-family: monospace;font-size: 14px;",l.placeholder="Processed commands will appear here...",l.readOnly=!0;const c=document.createElement("button");function i(){const e=r.value;if(!e.trim())return void(l.value="No input provided.");try{let t="";const n=document.querySelector("title");if(n){const e=n.textContent;if(console.log("Page title:",e),e.includes("Libby - Open:")){t=e.split("Libby - Open:")[1].trim(),console.log("Extracted book title:",t)}}let o="";t?(o=t.replace(/[^a-zA-Z0-9]/g,"_").toLowerCase(),o=o.replace(/_+/g,"_"),o=o.replace(/^_|_$/g,""),console.log("Directory name:",o)):o="audiobook_download";const a=e.match(/curl\s+'[^']+'/g)||[],c=new Set,s=[];a.forEach((e=>{const t=e.match(/curl\s+'([^']+)'/);t&&t[1]&&(c.has(t[1])||(c.add(t[1]),s.push(t[1])))}));let d="",u=1;if(s.forEach((t=>{const n=new RegExp(`curl\\s+'${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}'[\\s\\S]+?(?=curl\\s+'|$)`,"g"),o=e.match(n);if(o&&o[0]){let e=o[0];e=e.replace(/-H\s+'range:\s+bytes=.*?'\s+\\\n/g,"");const t=String(u).padStart(2,"0");e=e.replace(/curl\s+'/,"curl '");const n=e.indexOf("' \\");-1!==n&&(e=e.substring(0,n+3)+`\n--location \\\n-o file-${t}.mp3 \\`+e.substring(n+3)),d+=e,u++}})),u>1){const e="01",n=String(u-1).padStart(2,"0");let r="";o&&(r=`# Create and enter directory for "${t}"\nmkdir -p "${o}"\ncd "${o}"\n\n`),d=r+d,d+=`\n\n# Concatenate all downloaded MP3 files\nmp3wrap output.mp3 file-{${e}..${n}}.mp3\n\n# Open the concatenated file in QuickTime Player\nopen -a "QuickTime Player" output_MP3WRAP.mp3\n`}l.value=d,l.select()}catch(e){l.value=`Error processing commands: ${e.message}`}}c.textContent="Close",c.style.cssText="background-color: #f44336;color: white;padding: 10px 15px;border: none;border-radius: 4px;cursor: pointer;font-size: 16px;align-self: center;",a.addEventListener("click",i),c.addEventListener("click",(()=>{document.body.removeChild(e)})),t.appendChild(n),t.appendChild(o),t.appendChild(r),t.appendChild(a),t.appendChild(l),t.appendChild(c),e.appendChild(t),document.body.appendChild(e),r.focus()})();- Visit https://libbyapp.com/shelf/loans
- Click on the book you would like to download
- Right-click on the player page and choose the "Inspect" menu option
- Click on the "Network" tab
- Click on the funnel icon and enter
status-code:206in the filter text box - Click on your "Libby Extract URLs" bookmarklet
- This will begin playing and fast-forwarding the audiobook simultaneously
- The browser will download all constituent MP3 files
- To stop the process at any time, press the Escape key
- Once the full audiobook has played through, right-click on one of the filenames in the "Name" list on the bottom left
- Select "Copy > Copy all as cURL (bash)"
- Open any web page (or a blank tab)
- Click on your "cURL Processor" bookmarklet
- Paste the list of cURL commands copied in Step 1 into the textarea
- Click the "Process" button
- Copy the processed commands from the result box
- Run the commands in your terminal to download and concatenate the MP3 files
The bookmarklets:
- Extract URLs by automatically playing through the audiobook
- Process cURL commands to create organized download scripts
- Create directories based on book titles
- Remove duplicates and add proper filenames
- Generate commands to concatenate files and open them in QuickTime Player
- All processing happens locally in your browser
All processing happens locally in your browser. No data is sent to any server.
This tool is provided for personal use only. Please respect copyright laws and terms of service for the content you download.