Last active
March 20, 2021 01:13
-
-
Save jbueza/fe931d0db6b2ba533d5d0574e8b58efe to your computer and use it in GitHub Desktop.
Export your iBooks (epub) on Mac OS X. Useful if you're moving your book collection away from Books.app (Mac OS X) to Calibre (open source and works on all major operating systems).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const plist = require('simple-plist'); | |
const slug = require('slug'); | |
const homedir = require('os').homedir(); | |
const {execSync} = require('child_process'); | |
const SCRIPT_NAME = 'ibooks export'; | |
console.time(SCRIPT_NAME); | |
try { | |
const iBooksPlist = plist.readFileSync(`${homedir}/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books/Books.plist`, 'utf8'); | |
if (iBooksPlist.Books.length === 0) { | |
throw Error('You do not have any books to export.'); | |
console.timeEnd(SCRIPT_NAME); | |
} | |
iBooksPlist.Books.forEach(({path, artistName, itemName}) => { | |
const source = path; | |
const parts = path.split('.'); | |
const fileExtension = parts[parts.length - 1]; | |
const fileName = slug(`${artistName} - ${itemName}`); | |
const filePath = `${homedir}/Downloads/${fileName}.${fileExtension}`; | |
// ???? | |
if (source.match('/Containers')) { | |
console.log('Unable to copy ', source); | |
return; | |
} | |
console.log(`Exporting ${fileName} ...`); | |
execSync(`cp -R "${source}" "${filePath}"`); // .epub is really a folder | |
}); | |
console.timeEnd(SCRIPT_NAME); | |
} catch (err) { | |
console.error(`ERROR > ${err.message}`); | |
console.timeEnd(SCRIPT_NAME); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment