This commit is contained in:
Kovid Goyal 2012-01-05 22:48:00 +05:30
commit 78a80efdf1

View File

@ -208,6 +208,10 @@ class ITUNES(DriverBase):
BACKLOADING_ERROR_MESSAGE = _( BACKLOADING_ERROR_MESSAGE = _(
"Cannot copy books directly from iDevice. " "Cannot copy books directly from iDevice. "
"Drag from iTunes Library to desktop, then add to calibre's Library window.") "Drag from iTunes Library to desktop, then add to calibre's Library window.")
UNSUPPORTED_DIRECT_CONNECT_MODE_MESSAGE = _(
"Unsupported direct connect mode. "
"See http://www.mobileread.com/forums/showthread.php?t=118559 "
"for instructions on using 'Connect to iTunes'")
# Product IDs: # Product IDs:
# 0x1291 iPod Touch # 0x1291 iPod Touch
@ -834,7 +838,7 @@ class ITUNES(DriverBase):
raise AppleOpenFeedback(self) raise AppleOpenFeedback(self)
else: else:
if DEBUG: if DEBUG:
self.log.info(" advanced user mode, directly connecting to iDevice") self.log.warning(" %s" % self.UNSUPPORTED_DIRECT_CONNECT_MODE_MESSAGE)
# Confirm/create thumbs archive # Confirm/create thumbs archive
if not os.path.exists(self.cache_dir): if not os.path.exists(self.cache_dir):
@ -1163,6 +1167,8 @@ class ITUNES(DriverBase):
added = pl.add(appscript.mactypes.File(fpath),to=pl) added = pl.add(appscript.mactypes.File(fpath),to=pl)
if False: if False:
self.log.info(" '%s' added to Device|Books" % metadata.title) self.log.info(" '%s' added to Device|Books" % metadata.title)
self._wait_for_writable_metadata(added)
return added return added
elif iswindows: elif iswindows:
@ -1324,7 +1330,6 @@ class ITUNES(DriverBase):
''' '''
Unsupported direct-connect mode. Unsupported direct-connect mode.
''' '''
self.log.warning(" unsupported direct connect mode")
db_added = self._add_device_book(fpath, metadata) db_added = self._add_device_book(fpath, metadata)
lb_added = self._add_library_book(fpath, metadata) lb_added = self._add_library_book(fpath, metadata)
if not lb_added and DEBUG: if not lb_added and DEBUG:
@ -1392,16 +1397,17 @@ class ITUNES(DriverBase):
except: except:
if DEBUG: if DEBUG:
self.log.warning(" iTunes automation interface reported an error" self.log.warning(" iTunes automation interface reported an error"
" when adding artwork to '%s' in the iTunes Library" % metadata.title) " adding artwork to '%s' in the iTunes Library" % metadata.title)
pass pass
if db_added: if db_added:
try: try:
db_added.artworks[1].data_.set(cover_data) db_added.artworks[1].data_.set(cover_data)
self.log.info(" writing '%s' cover to iDevice" % metadata.title)
except: except:
if DEBUG: if DEBUG:
self.log.warning(" iTunes automation interface reported an error" self.log.warning(" iTunes automation interface reported an error"
" when adding artwork to '%s' on the iDevice" % metadata.title) " adding artwork to '%s' on the iDevice" % metadata.title)
#import traceback #import traceback
#traceback.print_exc() #traceback.print_exc()
#from calibre import ipython #from calibre import ipython
@ -2761,10 +2767,6 @@ class ITUNES(DriverBase):
STRIP_TAGS = re.compile(r'<[^<]*?/?>') STRIP_TAGS = re.compile(r'<[^<]*?/?>')
# Confirm writable metadata if directly connected to device
if db_added:
self._wait_for_writable_metadata(db_added)
# Update metadata from plugboard # Update metadata from plugboard
# If self.plugboard is None (no transforms), original metadata is returned intact # If self.plugboard is None (no transforms), original metadata is returned intact
metadata_x = self._xform_metadata_via_plugboard(metadata, this_book.format) metadata_x = self._xform_metadata_via_plugboard(metadata, this_book.format)
@ -2990,12 +2992,13 @@ class ITUNES(DriverBase):
db_added.Genre = tag db_added.Genre = tag
break break
def _wait_for_writable_metadata(self, db_added, delay=0.5): def _wait_for_writable_metadata(self, db_added, delay=2.0):
''' '''
Ensure device metadata is writable Ensure iDevice metadata is writable. Direct connect mode only
''' '''
if DEBUG: if DEBUG:
self.log.info(" ITUNES._wait_for_writable_metadata()") self.log.info(" ITUNES._wait_for_writable_metadata()")
self.log.warning(" %s" % self.UNSUPPORTED_DIRECT_CONNECT_MODE_MESSAGE)
attempts = 9 attempts = 9
while attempts: while attempts:
@ -3009,8 +3012,8 @@ class ITUNES(DriverBase):
attempts -= 1 attempts -= 1
time.sleep(delay) time.sleep(delay)
if DEBUG: if DEBUG:
self.log.warning(" waiting for iDevice metadata to become writable, attempt #%d" % self.log.warning(" waiting %.1f seconds for iDevice metadata to become writable (attempt #%d)" %
(10 - attempts)) (delay, (10 - attempts)))
else: else:
if DEBUG: if DEBUG:
self.log.error(" failed to write device metadata") self.log.error(" failed to write device metadata")