Fight for the Internet 1!

Showing posts with label ebooks. Show all posts
Showing posts with label ebooks. Show all posts

Friday, August 19, 2016

Fix Misaligned ePub Cover

Recently I had some ePub files that had misaligned tiny cover images. I wanted to correct this. Here's a really simple fix for many cases.

I use Calibre as my eBook reader, and it has an option to "Edit book", which will take you to the digital book file editor.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhaa_X5ByG53I-sFNmtx8NP3pfPgj9_ZmIbe9XgOPw1UatfcqveSoWGie4uOIlHkzSHPr3vDua_aJ5TOwi8cksYbTGio1LXp0tIRpGIh34fcYHIBIPeS2W4A9FIlRj1HKLbiHHmo0LC9Vi/s1600/edit_book_opening_window.png

Notice the panel on the left upper area, labeled File Browser. Usually the first file in this list is the Cover html page file. Also in the middle of the left column, an area labeled Images.

Automatically Recreating the Cover
If you have a copy of the book cover (which is trivially easy thanks to Google), I suggest you just delete the first titlepage.html cover file (or whatever it is called), and the related image file under the image section.

Then go to Menu: Tools --> Add cover.

Then import the cover image, and check the option to preserve the aspect ratio.


Manually Editing the Image Alignment
Double click to open it. You may see something similar to this:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta content="ABBYY FineReader 11" name="generator" />
  <link href="Court_of_all_Shamens_files/Court_of_all_Shamens.css" rel="stylesheet" type="text/css" />

  <title></title>
</head>

<body>
  <p><img alt="9785567648623" src="../Images/9785567648623.jpg" /><br />
</body>
</html>

The problem here is the image is just dropped into the document without any helpful formatting to make it full-sized. With a few tweaks in the code, you can make it much more aesthetically pleasing.

In the <head> section, add the <style> section:

<head>
...
    <style type="text/css">
@page {padding: 0pt; margin:0pt}
                        body { text-align: center; padding:0pt; margin: 0pt; }
    </style>
...
</head>


In the <body> section, just drop in this code snippet, but replace the src="" contents with the image file in your file. Example:

<body>
  <div>
    <svg xmlns="http://www.w3.org/2000/svg" height="100%" version="1.1" viewBox="0 0 316 532" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink">
    <image height="532" width="316" xlink:href="../Images/9785567648623.jpg"></image>
    </svg>
  </div>
</body>

This should center and enlarge your cover image properly.

Thursday, May 5, 2016

Calibre Author and Title Sorting

So I quite like the eBook management program called Calibre. But it has a few bad defaults. It outputs titles in a weird name format saving to disk (and sometimes author names). And it sorts authors by default with last name first (even storing them as such). This is wrong.

To fix the author sorting (and author name output when saving to disk):

1) Start calibre
1) Go to Preferences -> Advanced -> Tweaks.
2) Use the search option to find: "Author sort name algorithm"
3) There will be a few panels, including an area with text you can input or edit. In this area, find the line which starts with: author_sort_copy_method. If it doesn't exist, then skip to step 5 and just add it.
4) Here you can change the author sorting algorithm. Above this text input area is a brief description of the accepted options. But changes are you want to use the word copy.
5) Set the line: author_sort_copy_method = 'copy'
6) Click the button to "Apply changes to this tweak"
7) Restart calibre. It will probably ask you to anyway.

Now the work begins. I hope you don't have a lot of authors.

8) Back in the main view of the program, there is a column with your authors listed by name. Right-click on an author. Choose 'Manage Authors'.
9) There will be a column simply named "Authors".
10) Go through the entire list and change every author to be in order you want. (You can do it bit by bit or all at once. It doesn't matter to press OK occasionally and repeat these steps.) To make an entry editable, double click it. You press enter when you are finished editing.
11) As you change the values in the "Authors" column, the value names in the column labeled "Author sort" will change.

Correct any of the author_sort values that are wrong in your mind. Calibre will sort by the value in that box, so it must make sense to you.

12) When you are done press OK. Calibre will resort all of your changes. This might take a while.

The authors displayed in the tag view and in the library pane should all change.

13) Repeat 8-12 until all authors are changed and all author_sort values are correct.
13) Lastly, select all your books in your library.
14) Press 'e' to open the bulk metadata edit dialog.
15) Check the box 'automatically set author sort'. DO NOT check/change any other box.
16) Press OK. Wait until done.


I'm just passing these instructions along for my own notes and reference. Credit for these originally goes to Chaley: http://www.mobileread.com/forums/showpost.php?p=1104427&postcount=3

Monday, June 9, 2014

How to move files for Moon+ Reader while preserving metadata (bookmarks, highlights) or recover lost metadata

Overview of Problem
This is about using the Android electronic book reader app "Moon+ Reader" to move your files around successfully without losing the metadata (bookmarks, notes, highlights, progress, etc.). This technique can also be used to recover those if you lost them.

Problem
My books were stored in "/sdcard/Books/Changeling: The Dreaming" (for this example). I needed to move these PDFs and CBZs to a different location. Using a File Manager I moved the files to "/storage/extSdCard/Changeling The Dreaming". (I had to remove the ':' in the name because of the Fat32 filesystem format on the SDCard. Curse you, Microsoft.)

Then I re-imported the books into Moon+ Reader. The app removed the previous item entries and imported the new ones, but it failed to recognize they were the same PDF and CBZ files. It did not transfer the metadata. When I say metadata I refer to the bookmarks, the highlights, the notes, the reading progress, or even the names I manually assigned to the books, etc. (Some of the PDFs needed better names.)
This bug breaks lot of features every time there is moving or renaming files/folders. I love being able to highlight my books, but Moon Reader needs to be able to handle if I move my files around.

Solution 1 -- If you have not yet lost your metadata

0) In case it needs to be said, always make a backup of your book files and your information. Moon+ Reader lets you store backups of your metadata easily through its menus. Do this before proceeding.
1) In Moon+ Reader, go to My Files. (Not "My Shelf". You need to go to My Files specifically.)
2) Using Moon+ Reader, Select and then Move any existing items.

Note that Moon+ Reader may not be able to actually move the files. The reason for this is in Android version 4.4.2, Google revoked the privilege for any apps to modify files on external SD cards. (Some limited Google specific apps can use your SD card though.)

My files were on my external SD, so Moon+ Reader could not actually move them. If your files are only on the internal SD card, it seems to be able to move them just fine.

(WARNING: Because of the warped hybrid of external SD and internal SD storage, Moon+ Reader actually deleted any duplicate files at the target move location, so watch out! Your experience may be different, but always have a backup.)
3) Remove the selected item entries from within Moon+ Reader itself.
4) Now in your file manager, move the actual file object itself to new target location.
5) Back in Moon+ Reader, now do a normal Import Books.

Your metadata should have been transferred when you re-import the new files.


Solution 2 -- If you have lost your metadata 
This is when you have moved your files, and re-imported them, and your metadata didn't show up. Here is how to fix the problem.

0) In case it needs to be said, always make a backup of your book files and your information. Moon+ Reader lets you store backups of your metadata easily through its menus. Do this before proceeding.
1) In Moon+ Reader, remove any of the new items you just imported.

In my case, I had moved files /sdcard/Books/Changeling: The Dreaming (for this example) to a different location at "/storage/extSdCard/Changeling The Dreaming". I went back through Moon+ Reader and removed the files now at "/storage/extSdCard/Changeling The Dreaming".

2) Now Moon+ Reader should have none of the botched entries stored in it.
3) In your file manager, move the files back to where they were before Moon+ Reader lost the metadata. (If your files are stored on an external SD card, remember that Android 4.4.2 doesn't allow most apps to modify external SD contents, so may need to remove the SD card and do the file management on your desktop.)
4) In Moon+ Reader, re-import the old files from their old location.
5) Now Moon+ Reader should restore all your old metadata (bookmarks, notes, highlights, etc.)

Now you are ready to migrate your files in the special way to preserve your metadata.

6) In Moon+ Reader, go to My Files. (Not "My Shelf". You need to go to My Files specifically.)
7) Using Moon+ Reader, Select and then Move any existing items. Note Moon+ Reader will not actually move the files. (WARNING: My setup with Moon+ Reader actually deleted any duplicate files at the target move location, so watch out! Your experience may be different, but always have a backup. )
8) Remove the selected item entries from within Moon+ Reader itself.
9) Now in your file manager, move the actual file object itself to new target location.
10) Back in Moon+ Reader, now do a normal Import Books.

Troubleshooting
If you get "import: 0", then you did not remove the entries before trying to import. Be sure to check if you double imported them, because they might have nasty duplicates at the new import location where you were trying that do not have the transferred meta data.

Hack Editing the Backup Files Directly
Be careful when editing the Backup files yourself. You'll probably need some really basic knowledge of how SQL commands work, but not much.

About Moon+ Reader's Backup Files
Moon+ Reader's backup files have the file extension .mrpro (on the Pro version anyway). This is actually a Zip file. If you extract it, inside is a folder called "com.flyersoft.moonreaderp". Inside that is a bunch of files. In my case, there is typically about 60 files, most of them numbered files from 1.tag to 57.tag files. The important one you want is one of the high numbers. Look at the file size also to help you. One of them is actually the SQLite3 database. Mine was about 1.1 MB, while the rest were tiny, which tipped me off it was the real contents.

SQL Editing
I used an SQL editing program to view the SQLite3 database file. If I remember, I used "Sqliteman" which was simple enough for my needs. Using some simple find and replace string commands in SQL, I edited the existing entries with my meta data (highlights, notes, bookmarks, etc) changing them from the old filepaths to point to the working ones.

Finishing -- Zipping and Re-Importing and Restoring
After editing the appropriate .tag file (which is the SQLite3 database file actually), I zipped the entire folder back up, and gave it a name with a newer date, then imported that through Moon+ Reader, restoring from there. This fixed my paths.

Though now I just prefer to root my devices which allow me to give admin privileges to certain apps to move files around.
 

Addendum: Proposed Solution
I sent an email to the developer of Moon+ Reader about a proposed solution to fix this. I suggested he use file checksums (such as sha128 or md5sum) on each item that is imported. This way he could match files that move or are duplicates.
Moon+ Reader uses SQLite version 3 underneath and all the highlighting, bookmarks, notes, etc. are stored in these. You can even gain direct access to these by having the program use the "Backup" and "Restore" features. So if you want you can edit the SQLite database manually. I have actually hacked my Moon+ Reader SQLite files quite a bit at this point to clean up some bad stored book-entries.
While the developer did kindly respond, he never said that he would do this or not. I hope he does. But he did give me a hint on how to what had happened.