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)