On iPadOS 16 Apple's "Books" app is a somewhat... suboptimal?... experience.
I have decided to get all of my books out of it, which of couse means I wasn't keen to drag-'n-drop more than a thousand times. So I have taken
pdurrant's Apple script and extracted the commands into the following Shell Script, which I called
ePubFolder2File and saved into my path:
Code:
#!/usr/bin/env bash
main_loop()
{
opts=':';
while getopts ${opts} opt; do
case "${opt}" in
[?]|*)
echo "usage: $(basename "$0") EPUB_FOLDER" >&2
exit 1;
;;
esac
done
shift $((OPTIND - 1));
while [[ "$1" != "" ]]; do
build_epub "${1}"
shift;
done
}
build_epub ()
{
local source_folder="$1"
local dest_file
local current_dir=$(pwd)
dest_file="$(basename "${source_folder%.epub}").epub"
if [[ $(dirname "${source_folder}") == "." ]] && [[ "${source_folder}" != "${source_folder%.epub}" ]]; then
source_folder="${source_folder%.epub}"
mv "${source_folder}.epub" "${source_folder}"
fi
cd "${source_folder}" || exit 1
zip --quiet -X0 "${current_dir}/${dest_file}" mimetype
zip --quiet -rDX9 "${current_dir}/${dest_file}" * -x "*.DS_Store" -x mimetype
}
main_loop "$@"
I used it like follows from my shell to get all of my ePubs into a sane format:
Code:
$ find "/Users/eroux/Library/Mobile Documents/iCloud~com~apple~iBooks/Documents" -type d -name \*.epub |
while read epubdir; do
if [[ ! -f $(basename "$epubdir") ]]; then
echo "Processing $(basename $epubdir)";
ePubFolder2File "$epubdir";
fi;
done
It took a couple of minutes, but now I can move them to a new reader.