mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GwR revisions apple driver 0.5
This commit is contained in:
parent
e78d1dafc1
commit
7a67294ae7
@ -114,6 +114,7 @@ class ITUNES(DevicePlugin):
|
||||
# Properties
|
||||
cached_books = {}
|
||||
cache_dir = os.path.join(config_dir, 'caches', 'itunes')
|
||||
description_prefix = "added by calibre"
|
||||
ejected = False
|
||||
iTunes= None
|
||||
iTunes_media = None
|
||||
@ -620,6 +621,7 @@ class ITUNES(DevicePlugin):
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES.remove_books_from_metadata()")
|
||||
for path in paths:
|
||||
self._dump_cached_book(self.cached_books[path])
|
||||
if self.cached_books[path]['lib_book']:
|
||||
# Remove from the booklist
|
||||
for i,book in enumerate(booklists[0]):
|
||||
@ -881,6 +883,7 @@ class ITUNES(DevicePlugin):
|
||||
'author': metadata[i].author[0],
|
||||
'lib_book': lb_added,
|
||||
'dev_book': db_added }
|
||||
self._dump_cached_books(header="after upload_books()")
|
||||
|
||||
# Report progress
|
||||
if self.report_progress is not None:
|
||||
@ -928,7 +931,7 @@ class ITUNES(DevicePlugin):
|
||||
def _add_device_book(self,fpath, metadata):
|
||||
'''
|
||||
'''
|
||||
self.log.info("ITUNES._add_device_book()")
|
||||
self.log.info(" ITUNES._add_device_book()")
|
||||
if isosx:
|
||||
if 'iPod' in self.sources:
|
||||
connected_device = self.sources['iPod']
|
||||
@ -1015,11 +1018,11 @@ class ITUNES(DevicePlugin):
|
||||
|
||||
def _add_library_book(self,file, metadata):
|
||||
'''
|
||||
assumes pythoncom wrapper
|
||||
windows assumes pythoncom wrapper
|
||||
'''
|
||||
self.log.info("ITUNES._add_library_book()")
|
||||
self.log.info(" ITUNES._add_library_book()")
|
||||
if isosx:
|
||||
print "to be implemented"
|
||||
added = self.iTunes.add(appscript.mactypes.File(file))
|
||||
|
||||
elif iswindows:
|
||||
lib = self.iTunes.LibraryPlaylist
|
||||
@ -1068,7 +1071,7 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._add_new_copy()")
|
||||
self.log.info(" ITUNES._add_new_copy()")
|
||||
|
||||
db_added = None
|
||||
lb_added = None
|
||||
@ -1092,9 +1095,31 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
assumes pythoncom wrapper for db_added
|
||||
'''
|
||||
self.log.info("ITUNES._cover_to_thumb()")
|
||||
self.log.info(" ITUNES._cover_to_thumb()")
|
||||
thumb = None
|
||||
if metadata.cover:
|
||||
if isosx:
|
||||
cover_data = open(metadata.cover,'rb')
|
||||
if lb_added:
|
||||
lb_added.artworks[1].data_.set(cover_data.read())
|
||||
|
||||
if db_added:
|
||||
# The following command generates an error, but the artwork does in fact
|
||||
# get sent to the device. Seems like a bug in Apple's automation interface
|
||||
try:
|
||||
db_added.artworks[1].data_.set(cover_data.read())
|
||||
except:
|
||||
if DEBUG:
|
||||
self.log.warning(" iTunes automation interface generated an error"
|
||||
" when adding artwork to '%s'" % metadata.title)
|
||||
#import traceback
|
||||
#traceback.print_exc()
|
||||
#from calibre import ipython
|
||||
#ipython(user_ns=locals())
|
||||
pass
|
||||
|
||||
|
||||
elif iswindows:
|
||||
if lb_added:
|
||||
if lb_added.Artwork.Count:
|
||||
lb_added.Artwork.Item(1).SetArtworkFromFile(metadata.cover)
|
||||
@ -1135,7 +1160,7 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._create_new_book()")
|
||||
self.log.info(" ITUNES._create_new_book()")
|
||||
|
||||
this_book = Book(metadata.title, metadata.author[0])
|
||||
|
||||
@ -1183,7 +1208,7 @@ class ITUNES(DevicePlugin):
|
||||
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._discover_manual_sync_mode()")
|
||||
self.log.info(" ITUNES._discover_manual_sync_mode()")
|
||||
if isosx:
|
||||
connected_device = self.sources['iPod']
|
||||
dev_books = None
|
||||
@ -1246,6 +1271,31 @@ class ITUNES(DevicePlugin):
|
||||
self.log.info("%-40.40s %-30.30s" %
|
||||
(book.title, book.author))
|
||||
|
||||
def _dump_cached_book(self, cached_book, header=None):
|
||||
'''
|
||||
'''
|
||||
if header:
|
||||
msg = '%s' % header
|
||||
self.log.info(msg)
|
||||
self.log.info( "%s" % ('-' * len(msg)))
|
||||
if isosx:
|
||||
self.log.info("%-40.40s %-30.30s %-10.10s %-10.10s" %
|
||||
('title',
|
||||
'author',
|
||||
'lib_book',
|
||||
'dev_book'))
|
||||
self.log.info("%-40.40s %-30.30s %-10.10s %-10.10s" %
|
||||
(cached_book['title'],
|
||||
cached_book['author'],
|
||||
str(cached_book['lib_book'])[-9:],
|
||||
str(cached_book['dev_book'])[-9:]))
|
||||
elif iswindows:
|
||||
self.log.info("%-40.40s %-30.30s" %
|
||||
(cached_book['title'],
|
||||
cached_book['author']))
|
||||
|
||||
self.log.info()
|
||||
|
||||
def _dump_cached_books(self, header=None):
|
||||
'''
|
||||
'''
|
||||
@ -1254,6 +1304,11 @@ class ITUNES(DevicePlugin):
|
||||
self.log.info(msg)
|
||||
self.log.info( "%s" % ('-' * len(msg)))
|
||||
if isosx:
|
||||
self.log.info("%-40.40s %-30.30s %-10.10s %-10.10s" %
|
||||
('title',
|
||||
'author',
|
||||
'lib_book',
|
||||
'dev_book'))
|
||||
for cb in self.cached_books.keys():
|
||||
self.log.info("%-40.40s %-30.30s %-10.10s %-10.10s" %
|
||||
(self.cached_books[cb]['title'],
|
||||
@ -1318,7 +1373,7 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
if iswindows:
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._find_device_book()")
|
||||
self.log.info(" ITUNES._find_device_book()")
|
||||
self.log.info(" looking for '%s' by %s" % (cached_book['title'], cached_book['author']))
|
||||
|
||||
dev_books = self._get_device_books_playlist()
|
||||
@ -1347,7 +1402,7 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
if iswindows:
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._find_library_book()")
|
||||
self.log.info(" ITUNES._find_library_book()")
|
||||
self.log.info(" looking for '%s' by %s" % (cached_book['title'], cached_book['author']))
|
||||
|
||||
for source in self.iTunes.sources:
|
||||
@ -1411,6 +1466,7 @@ class ITUNES(DevicePlugin):
|
||||
else:
|
||||
return thumb_data
|
||||
|
||||
self.log.info(" ITUNES._generate_thumbnail()")
|
||||
if isosx:
|
||||
try:
|
||||
# Resize the cover
|
||||
@ -1424,18 +1480,16 @@ class ITUNES(DevicePlugin):
|
||||
|
||||
# Cache the tagged thumb
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._generate_thumbnail(): generated thumb for '%s', caching" % book.name())
|
||||
self.log.info(" generated thumb for '%s', caching" % book.name())
|
||||
zfw.writestr(thumb_path, thumb.getvalue())
|
||||
zfw.close()
|
||||
return thumb.getvalue()
|
||||
except:
|
||||
self.log.error("ITUNES._generate_thumbnail(): error generating thumb for '%s'" % book.name())
|
||||
self.log.error(" error generating thumb for '%s'" % book.name())
|
||||
return None
|
||||
|
||||
elif iswindows:
|
||||
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._generate_thumbnail()")
|
||||
if not book.Artwork.Count:
|
||||
if DEBUG:
|
||||
self.log.info(" no artwork available")
|
||||
@ -1473,7 +1527,7 @@ class ITUNES(DevicePlugin):
|
||||
for file in myZipList:
|
||||
exploded_file_size += file.file_size
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._get_device_book_size()")
|
||||
self.log.info(" ITUNES._get_device_book_size()")
|
||||
self.log.info(" %d items in archive" % len(myZipList))
|
||||
self.log.info(" compressed: %d exploded: %d" % (compressed_size, exploded_file_size))
|
||||
return exploded_file_size
|
||||
@ -1483,7 +1537,7 @@ class ITUNES(DevicePlugin):
|
||||
Assumes pythoncom wrapper for Windows
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("\nITUNES._get_device_books()")
|
||||
self.log.info("\n ITUNES._get_device_books()")
|
||||
|
||||
device_books = []
|
||||
if isosx:
|
||||
@ -1547,6 +1601,8 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
assumes pythoncom wrapper
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info(" ITUNES._get_device_books_playlist()")
|
||||
if iswindows:
|
||||
if 'iPod' in self.sources:
|
||||
pl = None
|
||||
@ -1570,7 +1626,7 @@ class ITUNES(DevicePlugin):
|
||||
calibre exits.
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._get_fpath()")
|
||||
self.log.info(" ITUNES._get_fpath()")
|
||||
|
||||
fpath = file
|
||||
if not getattr(fpath, 'deleted_after_upload', False):
|
||||
@ -1588,7 +1644,7 @@ class ITUNES(DevicePlugin):
|
||||
Populate a dict of paths from iTunes Library|Books
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("\nITUNES._get_library_books()")
|
||||
self.log.info("\n ITUNES._get_library_books()")
|
||||
|
||||
library_books = {}
|
||||
lib = None
|
||||
@ -1623,13 +1679,21 @@ class ITUNES(DevicePlugin):
|
||||
if DEBUG:
|
||||
self.log.info(" ignoring '%s' of type '%s'" % (book.name(), book.kind()))
|
||||
else:
|
||||
# Remove calibre orphans
|
||||
if str(book.description()).startswith(self.description_prefix):
|
||||
if book.location() == appscript.k.missing_value:
|
||||
if DEBUG:
|
||||
self.log.info(" adding %-30.30s [%s]" % (book.name(), book.kind()))
|
||||
self.log.info(" deleting calibre orphan '%s' from Library|Books" % book.name())
|
||||
book.delete()
|
||||
continue
|
||||
|
||||
path = self.path_template % (book.name(), book.artist())
|
||||
library_books[path] = book
|
||||
if DEBUG:
|
||||
self.log.info(" adding %-30.30s [%s]" % (book.name(), book.kind()))
|
||||
else:
|
||||
if DEBUG:
|
||||
self.log.info('No Library playlists')
|
||||
self.log.info(' no Library playlists')
|
||||
else:
|
||||
if DEBUG:
|
||||
self.log.info(' no Library found')
|
||||
@ -1671,10 +1735,18 @@ class ITUNES(DevicePlugin):
|
||||
if DEBUG:
|
||||
self.log.info(" ignoring %-30.30s of type '%s'" % (book.Name, book.KindAsString))
|
||||
else:
|
||||
# Remove calibre orphans
|
||||
if book.Description.startswith(self.description_prefix):
|
||||
if not book.Location:
|
||||
if DEBUG:
|
||||
self.log.info(" adding %-30.30s [%s]" % (book.Name, book.KindAsString))
|
||||
self.log.info(" deleting calibre orphan '%s' from Library|Books" % book.Name)
|
||||
book.Delete()
|
||||
continue
|
||||
|
||||
path = self.path_template % (book.Name, book.Artist)
|
||||
library_books[path] = book
|
||||
if DEBUG:
|
||||
self.log.info(" adding %-30.30s [%s]" % (book.Name, book.KindAsString))
|
||||
except:
|
||||
if DEBUG:
|
||||
self.log.info(" no books in library")
|
||||
@ -1730,7 +1802,7 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES:_launch_iTunes():\n Instantiating iTunes")
|
||||
self.log.info(" ITUNES:_launch_iTunes():\n Instantiating iTunes")
|
||||
|
||||
if isosx:
|
||||
'''
|
||||
@ -1788,7 +1860,7 @@ class ITUNES(DevicePlugin):
|
||||
self.log.error(" '%s' not found" % media_dir)
|
||||
|
||||
if DEBUG:
|
||||
self.log.info( " [%s - %s (%s), driver version %d.%d.%d]" %
|
||||
self.log.info(" [%s - %s (%s), driver version %d.%d.%d]" %
|
||||
(self.iTunes.Windows[0].name, self.iTunes.Version, initial_status,
|
||||
self.version[0],self.version[1],self.version[2]))
|
||||
self.log.info(" iTunes_media: %s" % self.iTunes_media)
|
||||
@ -1797,7 +1869,7 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._remove_existing_copies()")
|
||||
self.log.info(" ITUNES._remove_existing_copies()")
|
||||
|
||||
if self.manual_sync_mode:
|
||||
# Delete existing from Device|Books, add to self.update_list
|
||||
@ -1830,12 +1902,11 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
Windows assumes pythoncom wrapper
|
||||
'''
|
||||
self.log.info("ITUNES._remove_from_device()")
|
||||
self.log.info(" ITUNES._remove_from_device()")
|
||||
if isosx:
|
||||
if DEBUG:
|
||||
self.log.info(" deleting %s" % cached_book['dev_book'])
|
||||
result = cached_book['dev_book'].delete()
|
||||
print "result: %s" % result
|
||||
|
||||
elif iswindows:
|
||||
dev_pl = self._get_device_books_playlist()
|
||||
@ -1856,12 +1927,14 @@ class ITUNES(DevicePlugin):
|
||||
We only want to delete stored copies if the file is stored in iTunes
|
||||
We don't want to delete files stored outside of iTunes
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info(" ITUNES._remove_from_iTunes():")
|
||||
|
||||
if isosx:
|
||||
storage_path = os.path.split(cached_book['lib_book'].location().path)
|
||||
if cached_book['lib_book'].location().path.startswith(self.iTunes_media):
|
||||
title_storage_path = storage_path[0]
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._remove_from_iTunes():")
|
||||
self.log.info(" removing title_storage_path: %s" % title_storage_path)
|
||||
try:
|
||||
shutil.rmtree(title_storage_path)
|
||||
@ -1892,15 +1965,13 @@ class ITUNES(DevicePlugin):
|
||||
Assume we're wrapped in a pythoncom
|
||||
Windows stores the book under a common author directory, so we just delete the .epub
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._remove_from_iTunes():\n '%s'" % cached_book['title'])
|
||||
|
||||
book = self._find_library_book(cached_book)
|
||||
if book:
|
||||
path = book.Location
|
||||
storage_path = os.path.split(book.Location)
|
||||
if book.Location.startswith(self.iTunes_media):
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._remove_from_iTunes():")
|
||||
self.log.info(" removing '%s' at %s" %
|
||||
(cached_book['title'], path))
|
||||
try:
|
||||
@ -1927,7 +1998,7 @@ class ITUNES(DevicePlugin):
|
||||
Trigger a sync, wait for completion
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES:_update_device():\n %s" % msg)
|
||||
self.log.info(" ITUNES:_update_device():\n %s" % msg)
|
||||
|
||||
if isosx:
|
||||
self.iTunes.update()
|
||||
@ -1973,7 +2044,7 @@ class ITUNES(DevicePlugin):
|
||||
'''
|
||||
'''
|
||||
if DEBUG:
|
||||
self.log.info("ITUNES._update_iTunes_metadata()")
|
||||
self.log.info(" ITUNES._update_iTunes_metadata()")
|
||||
|
||||
strip_tags = re.compile(r'<[^<]*?/?>')
|
||||
|
||||
@ -1995,13 +2066,13 @@ class ITUNES(DevicePlugin):
|
||||
pass
|
||||
|
||||
if lb_added:
|
||||
lb_added.description.set("added by calibre %s" % strftime('%Y-%m-%d %H:%M:%S'))
|
||||
lb_added.description.set("%s %s" % (self.description_prefix,strftime('%Y-%m-%d %H:%M:%S')))
|
||||
lb_added.enabled.set(True)
|
||||
lb_added.sort_artist.set(metadata.author_sort.title())
|
||||
lb_added.sort_name.set(this_book.title_sorter)
|
||||
|
||||
if db_added:
|
||||
db_added.description.set("added by calibre %s" % strftime('%Y-%m-%d %H:%M:%S'))
|
||||
db_added.description.set("%s %s" % (self.description_prefix,strftime('%Y-%m-%d %H:%M:%S')))
|
||||
db_added.enabled.set(True)
|
||||
db_added.sort_artist.set(metadata.author_sort.title())
|
||||
db_added.sort_name.set(this_book.title_sorter)
|
||||
@ -2036,14 +2107,13 @@ class ITUNES(DevicePlugin):
|
||||
pass
|
||||
|
||||
if lb_added:
|
||||
lb_added.Description = ("added by calibre %s" % strftime('%Y-%m-%d %H:%M:%S'))
|
||||
lb_added.Description = ("%s %s" % (self.description_prefix,strftime('%Y-%m-%d %H:%M:%S')))
|
||||
lb_added.Enabled = True
|
||||
lb_added.SortArtist = (metadata.author_sort.title())
|
||||
lb_added.SortName = (this_book.title_sorter)
|
||||
|
||||
if db_added:
|
||||
db_added.Description = ("added by calibre %s" % strftime('%Y-%m-%d %H:%M:%S'))
|
||||
db_added.Enabled = True
|
||||
db_added.Description = ("%s %s" % (self.description_prefix,strftime('%Y-%m-%d %H:%M:%S')))
|
||||
db_added.SortArtist = (metadata.author_sort.title())
|
||||
db_added.SortName = (this_book.title_sorter)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user