Mobileread
Guide: Removing iTunes metadata from ePub
#1  BlindBandit 07-16-2019, 05:53 AM
I recently came across a problem when adding my ebook collection to my iPhone via iTunes and thought the knowledge I gained finding a solution might be useful for others.

I used a program called calibre to edit an ePub's metadata (title and author) and then added it to iTunes to copy onto my iPhone. But when I did, iTunes was still using the old metadata with the old title and author, not the new ones.

After a lot of digging (and this useful post) I managed to figure out why. ePubs are an archive with a bunch of smaller files inside of it, including one file called content.opf that contains the metadata. When an ePub is added to iTunes, it doesn't read its metadata from content.opf; it reads it from another file, iTunesMetadata.plist. If the iTunesMetadata.plist file doesn't exist, iTunes will create one based off content.opf and put it inside the original ePub.

That means when you first add an ePub to iTunes, its metadata will match properly because iTunesMetadata.plist is being created for the first time using the up-to-date metadata... but if you ever change the ePub's metadata, you'll only be changing content.opf and iTunes will continue to use the old, unchanged metadata from iTunesMetadata.plist.

The solution is to use rar or zip or some other archive program to delete the iTunesMetadata.plist file inside the .epub file before adding the ePub to iTunes. If you do that, iTunes will be forced to create a new iTunesMetadata.plist file with the latest metadata.

But if you're like me and have a huge library, doing this manually for every file would take a long time. So I wrote a Windows batch script (included below) to quicken the process. I've gotten into the habit of running this script every time before I add new ebooks to iTunes and it has saved me a lot of headaches.

To run it, you'll need to download zip.exe (I got it from here, but there's plenty of other places to get it) and save it somewhere on your computer.

Then create a .bat batch file with this text inside:

Code
FOR /R "C:\Users\Jordan\Calibre Library" %%G IN (*.epub) DO "C:\CommandLineTools\zip.exe" -d "%%G" iTunesMetadata.plist
PAUSE
Note: If you're running this from the command line using the cmd.exe command prompt instead of running it from a .bat batch script, replace the %%G parts with %G.

"C:\Users\Jordan\Calibre Library" is the location of my ePub collection, and "C:\CommandLineTools\zip.exe" is the location of my zip.exe (as explained above). Change these path locations to match wherever your ePub collection and zip.exe are located.

Hope this helps someone
Reply 

#2  jhowell 07-16-2019, 08:13 AM
The Modify ePub plugin for calibre will also remove the iTunesMetadata.plist file from one or more books when the "Remove iTunes files" option is selected.
Reply 

#3  BlindBandit 07-16-2019, 12:21 PM
> The Modify ePub plugin for calibre will also remove the iTunesMetadata.plist file from one or more books when the "Remove iTunes files" option is selected.

... Ohh my God ...

I spent a few hours trying to figure out why it was happening, and then about an hour figuring out how to automate it.

And there's a plugin that does it in under a second.

Euuurrrrrggghh.

Thank you for telling me about this though

Do you know if there's a way to automatically run the Modify ePub plugin every time you save to disk?
Reply 

#4  odamizu 07-16-2019, 03:22 PM
Quote BlindBandit
... When an ePub is added to iTunes, it doesn't read its metadata from content.opf; it reads it from another file, iTunesMetadata.plist. If the iTunesMetadata.plist file doesn't exist, iTunes will create one based off content.opf and put it inside the original ePub. [emphasis added]
Omigod

I don't use iTunes or iBooks for reading ebooks, but I'm always curious about these things.

On iTunes 12.8.2.3, it won't accept ebooks/epubs (at least not in a way I could figure out). When I copied an epub over to iBooks 1.15, the original epub file did not appear to be altered.

Where is this iTunesMetadata.plist file? Is it an invisible/hidden file? When I unzipped the original epub after copying it over to iBooks, it was unchanged as far as I can tell.

Thanks for any enlightenment
Reply 

#5  BetterRed 07-16-2019, 07:22 PM
Quote BlindBandit
Do you know if there's a way to automatically run the Modify ePub plugin every time you save to disk?
Short Answer - there is no way.

Modify EPUB can be run from the command line - instructions are in first post, and you can save to disk with the calibredb export command.

Or almost everything in calibre can be given a keyboard shortcut. I use Alt+M for Modify, and S for Save to Disk (I think that the default shortcut) - so I would press Alt+M, Enter, S. If I wanted to further automate I'd do it with AHK on Windows, on a Mac you could probably do it with Automator.

BR
Reply 

#6  BlindBandit 07-18-2019, 10:56 AM
Quote odamizu
Where is this iTunesMetadata.plist file?
I don't know if you call it the root directory or parent directory or whatever. But it should just be in the top-level location when you open the ePub.

Quote odamizu
Is it an invisible/hidden file?
No.

Quote odamizu
When I unzipped the original epub after copying it over to iBooks, it was unchanged as far as I can tell.
Maybe iBooks doesn't add iTunesMetadata.plist, maybe only iTunes does it. I use iTunes version 12.7.1.14 and I'm able to add eBooks to my iPhone using iTunes just fine.
Reply 

#7  odamizu 07-19-2019, 01:16 AM
Thanks BlindBandit. As far as I can tell, iTunes 12.8 does not accept epubs and iBooks doesn't add the iTunesMetadata.plist to the original epub, but it does add it to the iBooks version.
Reply 

Today's Posts | Search this Thread | Login | Register