Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 07-17-2011, 05:17 PM   #1
siebert
Developer
siebert has a complete set of Star Wars action figures.siebert has a complete set of Star Wars action figures.siebert has a complete set of Star Wars action figures.
 
Posts: 137
Karma: 280
Join Date: Nov 2010
Device: Kindle 3 (Keyboard) 3G / iPad 3 WiFi / Nexus 4 (Android)
Patch: Use real ASIN instead of UUID in mobi files to show correct cover in KindleApp

Hi,

with the following patch against calibre 0.8.8, converted or saved mobi files will contain a real ASIN value instead of a generated UUID if an identifier named 'asin' is available in the book metadata.

The amazon metadata plugin is patched to automatically set the necessary 'asin' identifier.

With this change the Kindle App will display the correct book cover, which is not available when using an UUID.

Ciao,
Steffen

Code:
diff --git a/src/calibre/ebooks/metadata/mobi.py b/src/calibre/ebooks/metadata/mobi.py
index 74db3b3..fe4950c 100644
--- a/src/calibre/ebooks/metadata/mobi.py
+++ b/src/calibre/ebooks/metadata/mobi.py
@@ -374,11 +374,15 @@ class MetadataUpdater(object):
         if self.thumbnail_record is not None:
             update_exth_record((202, pack('>I', self.thumbnail_rindex)))
         # Add a 113 record if not present to allow Amazon syncing
-        if (113 not in self.original_exth_records and
-                self.original_exth_records.get(501, None) == 'EBOK' and
-                not added_501):
-            from uuid import uuid4
-            update_exth_record((113, str(uuid4())))
+        if not added_501:
+            if mi.has_identifier('asin'):
+                asin = mi.get_identifiers()['asin']
+                update_exth_record((113, asin.encode(self.codec, 'replace')))
+            elif 113 not in self.original_exth_records:
+                from uuid import uuid4
+                update_exth_record((113, str(uuid4())))
+            if self.original_exth_records.get(501, None) != 'EBOK':
+                update_exth_record((501, 'EBOK'.encode(self.codec, 'replace')))
         if 503 in self.original_exth_records:
             update_exth_record((503, mi.title.encode(self.codec, 'replace')))
 
diff --git a/src/calibre/ebooks/metadata/sources/amazon.py b/src/calibre/ebooks/metadata/sources/amazon.py
index 6220f29..898cb86 100644
--- a/src/calibre/ebooks/metadata/sources/amazon.py
+++ b/src/calibre/ebooks/metadata/sources/amazon.py
@@ -202,6 +202,7 @@ class Worker(Thread): # Get details {{{
         mi = Metadata(title, authors)
         idtype = 'amazon' if self.domain == 'com' else 'amazon_'+self.domain
         mi.set_identifier(idtype, asin)
+        mi.set_identifier('asin', asin)
         self.amazon_id = asin
 
         try:
diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py
index bf9de37..bfe6315 100644
--- a/src/calibre/ebooks/mobi/writer.py
+++ b/src/calibre/ebooks/mobi/writer.py
@@ -1552,10 +1552,15 @@ class MobiWriter(object):
         uuid = None
         from calibre.ebooks.oeb.base import OPF
         for x in oeb.metadata['identifier']:
-            if x.get(OPF('scheme'), None).lower() == 'uuid' or unicode(x).startswith('urn:uuid:'):
+            if x.get(OPF('scheme'), None).lower() == 'asin':
                 uuid = unicode(x).split(':')[-1]
                 break
         if uuid is None:
+            for x in oeb.metadata['identifier']:
+                if x.get(OPF('scheme'), None).lower() == 'uuid' or unicode(x).startswith('urn:uuid:'):
+                    uuid = unicode(x).split(':')[-1]
+                    break
+        if uuid is None:
             from uuid import uuid4
             uuid = str(uuid4())
 
diff --git a/src/calibre/ebooks/oeb/transforms/metadata.py b/src/calibre/ebooks/oeb/transforms/metadata.py
index f719ee3..3980c21 100644
--- a/src/calibre/ebooks/oeb/transforms/metadata.py
+++ b/src/calibre/ebooks/oeb/transforms/metadata.py
@@ -12,6 +12,9 @@ from calibre import guess_type
 
 def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
     from calibre.ebooks.oeb.base import OPF
+    user_identifiers = mi.get_identifiers()
+    for x in user_identifiers:
+        m.add('identifier', user_identifiers[x], scheme=x.upper())
     if not mi.is_null('title'):
         m.clear('title')
         m.add('title', mi.title)
siebert is offline   Reply With Quote
Old 02-23-2012, 10:44 PM   #2
apacheman
Junior Member
apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.
 
Posts: 6
Karma: 487442
Join Date: Feb 2012
Device: kindle4Android
Quote:
Originally Posted by siebert View Post
Hi,

with the following patch against calibre 0.8.8, converted or saved mobi files will contain a real ASIN value instead of a generated UUID if an identifier named 'asin' is available in the book metadata.

The amazon metadata plugin is patched to automatically set the necessary 'asin' identifier.

With this change the Kindle App will display the correct book cover, which is not available when using an UUID.

Ciao,
Steffen

Code:
diff --git a/src/calibre/ebooks/metadata/mobi.py b/src/calibre/ebooks/metadata/mobi.py
index 74db3b3..fe4950c 100644
--- a/src/calibre/ebooks/metadata/mobi.py
+++ b/src/calibre/ebooks/metadata/mobi.py
@@ -374,11 +374,15 @@ class MetadataUpdater(object):
         if self.thumbnail_record is not None:
             update_exth_record((202, pack('>I', self.thumbnail_rindex)))
         # Add a 113 record if not present to allow Amazon syncing
-        if (113 not in self.original_exth_records and
-                self.original_exth_records.get(501, None) == 'EBOK' and
-                not added_501):
-            from uuid import uuid4
-            update_exth_record((113, str(uuid4())))
+        if not added_501:
+            if mi.has_identifier('asin'):
+                asin = mi.get_identifiers()['asin']
+                update_exth_record((113, asin.encode(self.codec, 'replace')))
+            elif 113 not in self.original_exth_records:
+                from uuid import uuid4
+                update_exth_record((113, str(uuid4())))
+            if self.original_exth_records.get(501, None) != 'EBOK':
+                update_exth_record((501, 'EBOK'.encode(self.codec, 'replace')))
         if 503 in self.original_exth_records:
             update_exth_record((503, mi.title.encode(self.codec, 'replace')))
 
diff --git a/src/calibre/ebooks/metadata/sources/amazon.py b/src/calibre/ebooks/metadata/sources/amazon.py
index 6220f29..898cb86 100644
--- a/src/calibre/ebooks/metadata/sources/amazon.py
+++ b/src/calibre/ebooks/metadata/sources/amazon.py
@@ -202,6 +202,7 @@ class Worker(Thread): # Get details {{{
         mi = Metadata(title, authors)
         idtype = 'amazon' if self.domain == 'com' else 'amazon_'+self.domain
         mi.set_identifier(idtype, asin)
+        mi.set_identifier('asin', asin)
         self.amazon_id = asin
 
         try:
diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py
index bf9de37..bfe6315 100644
--- a/src/calibre/ebooks/mobi/writer.py
+++ b/src/calibre/ebooks/mobi/writer.py
@@ -1552,10 +1552,15 @@ class MobiWriter(object):
         uuid = None
         from calibre.ebooks.oeb.base import OPF
         for x in oeb.metadata['identifier']:
-            if x.get(OPF('scheme'), None).lower() == 'uuid' or unicode(x).startswith('urn:uuid:'):
+            if x.get(OPF('scheme'), None).lower() == 'asin':
                 uuid = unicode(x).split(':')[-1]
                 break
         if uuid is None:
+            for x in oeb.metadata['identifier']:
+                if x.get(OPF('scheme'), None).lower() == 'uuid' or unicode(x).startswith('urn:uuid:'):
+                    uuid = unicode(x).split(':')[-1]
+                    break
+        if uuid is None:
             from uuid import uuid4
             uuid = str(uuid4())
 
diff --git a/src/calibre/ebooks/oeb/transforms/metadata.py b/src/calibre/ebooks/oeb/transforms/metadata.py
index f719ee3..3980c21 100644
--- a/src/calibre/ebooks/oeb/transforms/metadata.py
+++ b/src/calibre/ebooks/oeb/transforms/metadata.py
@@ -12,6 +12,9 @@ from calibre import guess_type
 
 def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
     from calibre.ebooks.oeb.base import OPF
+    user_identifiers = mi.get_identifiers()
+    for x in user_identifiers:
+        m.add('identifier', user_identifiers[x], scheme=x.upper())
     if not mi.is_null('title'):
         m.clear('title')
         m.add('title', mi.title)
I'm newbie here. How to patch this in calibre?
apacheman is offline   Reply With Quote
 
Advertisement
Old 02-23-2012, 11:10 PM   #3
apacheman
Junior Member
apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.
 
Posts: 6
Karma: 487442
Join Date: Feb 2012
Device: kindle4Android
OK. I have to download calibre source package, edit it and rebuild?
apacheman is offline   Reply With Quote
Old 02-24-2012, 07:17 AM   #4
itimpi
Wizard
itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.
 
Posts: 4,112
Karma: 780247
Join Date: Nov 2008
Device: Sony PRS-950, iphone/ipad (Marvin/iBooks/QuickReader)
That is a very old post as it is referes to calibre 0.8.8 and we are now up to 0.8.40 (32 revisions later). Have you checked to see if this feature has been incorporated into the standard calibre build since then (I do not know)?

However in pricniple you are right as to what you need to do to incorporate a patch. However it is a little easier than the steps you describe as Calibre uses Python as its programming language which supports "Just in Time" compilation so simply patching the source will pick up the change if you are set to run from source.
itimpi is offline   Reply With Quote
Old 02-24-2012, 09:13 AM   #5
apacheman
Junior Member
apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.apacheman ought to be getting tired of karma fortunes by now.
 
Posts: 6
Karma: 487442
Join Date: Feb 2012
Device: kindle4Android
Thank you for the reply. I have version 0.8.8 binary downloaded from ubuntu repository. While I checked the latest source files, and this patch is not included in them.
Not a programmer, but I find it irritating, when kindle for android displaying cover images very small, even though I modified it in calibre. But the books downloaded from amazon is working fine.

One question, what does 'index f719ee3..3980c21 100644' means in the patch.
apacheman is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What happens when MOBI matches actual ASIN in Amazon's database? Zero9 Conversion 0 05-29-2011 11:20 AM
How can I remove ASIN from a mobi book? julius90 Calibre 4 05-02-2011 11:08 AM
PRS-650 AAC files don't show cover or author lexxi Sony Reader 4 04-25-2011 02:30 PM
Update all mobi books so they have an ASIN? protoghost Library Management 4 02-13-2011 07:25 AM
Mobi to Kindle with correct metadata? rex0810 Calibre 3 09-25-2009 06:36 PM


All times are GMT -4. The time now is 10:29 PM.


MobileRead.com is a privately owned, operated and funded community.