Skip to content

Instantly share code, notes, and snippets.

@black-dragon74
Created March 8, 2025 10:51
Show Gist options
  • Save black-dragon74/6f4dfe1124d848a7a3ac46d1eaa05d1b to your computer and use it in GitHub Desktop.
Save black-dragon74/6f4dfe1124d848a7a3ac46d1eaa05d1b to your computer and use it in GitHub Desktop.
Convert Apple Books or iTunes Books to general EPUB format
#!/usr/bin/env bash
for f in *.epub; do
if [ -d "$f" ]; then
echo "Converting: $f"
cd "$f"
find . -name "iTunesMetadata*.plist" -delete 2>/dev/null
zip -0X "../tmp.epub" mimetype >/dev/null
zip -rDX9 "../tmp.epub" * -x "*.DS_Store" -x mimetype >/dev/null
cd ..
rm -rf "$f"
mv tmp.epub "$f"
elif [[ $(unzip -l "$f" 2>/dev/null | grep iTunesMetadata) == "" ]]; then
echo "Already clean: $f"
else
echo "Unexpected file: $f"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment