Potential fix for lp:1268058, waiting for metadata to become writeable on iDevice.

This commit is contained in:
Gregory Riker 2014-01-11 06:41:32 -07:00
parent 0a84e0c56f
commit e287cd6fc1

View File

@ -640,9 +640,11 @@ class ITUNES(DriverBase):
self.ejected = True
return False
except:
# iTunes connection failed, probably not running anymore
logger().error("%s.can_handle_windows():\n lost connection to iTunes" % self.__class__.__name__)
# iTunes connection failed
if self.verbose:
logger().info("ERROR: %s.can_handle_windows():\n no connection to iTunes" % self.__class__.__name__)
#import traceback
#traceback.print_exc()
return False
finally:
pythoncom.CoUninitialize()
@ -2434,10 +2436,10 @@ class ITUNES(DriverBase):
break
else:
if self.verbose:
logger().error(" no Library|Books playlist found")
logger().info(" ERROR: no Library|Books playlist found")
else:
if self.verbose:
logger().error(" no Library playlists found")
logger().info(" ERROR: no Library playlists found")
try:
for book in lib_books:
@ -2501,8 +2503,12 @@ class ITUNES(DriverBase):
elif iswindows:
# Assumes a pythoncom wrapper
it_sources = ['Unknown', 'Library', 'iPod', 'AudioCD', 'MP3CD', 'Device', 'RadioTuner', 'SharedLibrary']
try:
names = [s.name for s in self.iTunes.sources]
kinds = [it_sources[s.kind] for s in self.iTunes.sources]
except:
logger().info(" %s._launch_iTunes():ERROR reading iTunes.sources" % self.__class__.__name__)
raise
# If more than one connected iDevice, remove all from list to prevent driver initialization
if kinds.count('iPod') > 1:
@ -3132,9 +3138,14 @@ class ITUNES(DriverBase):
lb_added.Year = metadata_x.pubdate.year
if db_added:
# Wait for db_added to become writeable
if self.verbose:
logger().info(" waiting for db_added to become writable ")
time.sleep(1.0)
logger().info(" waiting for metadata to become writeable on iDevice")
WAIT_TIME = 0.50
ATTEMPTS = attempts = 9
while attempts:
try:
db_added.Name = metadata_x.title
db_added.Album = metadata_x.title
db_added.Artist = authors_to_string(metadata_x.authors)
@ -3144,6 +3155,17 @@ class ITUNES(DriverBase):
db_added.SortArtist = icu_title(metadata_x.author_sort)
db_added.SortName = metadata_x.title_sort
db_added.Year = metadata_x.pubdate.year
break
except:
time.sleep(WAIT_TIME)
attempts -= 1
if self.verbose:
logger().info(" waiting %.1f seconds for iDevice metadata to become writable (attempt #%d)" %
(WAIT_TIME, (ATTEMPTS - attempts + 1)))
if not attempts:
logger().info(" ERROR: Unable to set metadata in book")
raise
if metadata_x.comments:
if lb_added:
@ -3213,13 +3235,13 @@ class ITUNES(DriverBase):
db_added.TrackNumber = metadata_x.series_index
except:
if self.verbose:
logger().warning(" iTunes automation interface reported an error"
logger().info(" iTunes automation interface reported an error"
" setting TrackNumber on iDevice")
try:
db_added.EpisodeNumber = metadata_x.series_index
except:
if self.verbose:
logger().warning(" iTunes automation interface reported an error"
logger().info(" iTunes automation interface reported an error"
" setting EpisodeNumber on iDevice")
# If no plugboard transform applied to tags, change the Genre/Category to Series