View Single Post
Old 02-02-2010, 06:43 AM   #19
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,499
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
A workaround for 'last,first' author/author_sort problems

Introduction: I prefer to use 'lastname, firstname' for my authors. I suppose that I am too visually challenged to have my eyes bounce around the page looking for a lastname, even if the list is sorted correctly. What I have been doing is setting the author field as I want. Unfortunately, this produces an author_sort value that is totally wrong, so I copy by hand the author field to the author_sort field. This process was marginally acceptable until I needed to import several hundred books with the author already set the way I want. I would have been required to change 100s of books manually. Not fun.

Fix: I fixed the problem by making a small change to calibre. This change, submitted to Kovid & co. for consideration as a supported calibre feature (don't know if it will be accepted), changes the author -> author_sort processing to do no name munging at all. The author field is copied directly to author_sort field without modification. This makes my import much easier, and in fact makes calibre noticeably easier to use (for me). Of course I still need to deal with the occasional honorific (de, de la, van, von, etc), but that is OK.

I am happy to share my change with those who want it. I will continue to maintain it until the change or something equivalent is incorporated into calibre.

Installing the change is fairly easy. It requires adding one file into the calibre program folders, and setting one environment variable. Nothing will change in calibre's behavior until both of these things are done.

To add the file:
  1. Download the one file. To get it, go to http://charles.the-haleys.org/calibre.
  2. Look for a folder with a name containing your version of calibre. If you don't see your version, you shouldn't try to use this feature. Currently only calibre version 0.6.37 is supported. Folder names of n.n.n--m.m.m indicate that the file in that folder is good for all versions between the numbers, inclusive.
  3. Click on the folder for your version.
  4. Download the file __init__.py, putting it somewhere on your computer that will easy to find. For windows, your desktop is a good choice. Alternatively, you can download it directly into the folder described below. Note: if you have Windows set up to hide extensions (the default), the file name might appear to be __init__. You won't see the ".py". This is OK.
  5. On your computer, navigate to the calibre installation folder. On windows, this is probably \Program Files\Calibre2, but it could be anywhere. If you can't find it, check the properties of the shortcut you use to start calibre for where calibre.exe is placed.
  6. Starting from the calibre folder found above, navigate to the subfolder "Lib\site-packages\calibre\ebooks\metadata".
  7. Move (or copy) the file you downloaded (__init__.py) to this folder. Note that there will be a file already in the folder named __init__.pyo (__init__ if you hide extensions). This is OK.

Now test to be sure that calibre still runs. It might not if you put the above file in the wrong folder. Note that the new feature won't work yet.

To enable the new feature, you must set the environment variable CALIBRE_AUTHOR_SORT_METHOD=none. The page http://support.tabs3.com/main/R10463.htm describes how to set environment variables on windows. The variable name is CALIBRE_AUTHOR_SORT_METHOD and the variable value is "none" (without the quotes).

Now test the new feature. Be sure you stop and restart the calibre GUI, then pick some convenient book and edit its metadata. Put something odd into the author_sort box, then click the button that copies the author field to the author sort field. The author_sort box should now be equal to the author box. If it is not, then you have either put the __init__.py file into the wrong folder or not correctly set the environment variable.

To uninstall the feature, remove the __init__.py file you copied earlier. To turn it off temporarily, change the value of the environment variable to anything but "none".

Note that if you update calibre, you might be required to copy and install a new version of the __init__.py file. As new versions of calibre come out, I will prepare a new __init__.py (if necessary). You might want to check if I have prepared a file for the new version before you upgrade calibre.

WARNING: if you upgrade calibre but do not either remove or upgrade the __init__.py file, calibre may stop working or not work as expected.

Best of luck,
Charles
chaley is offline   Reply With Quote