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:
|
||||
@ -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()")
|
||||
if isosx:
|
||||
print "to be implemented"
|
||||
added = self.iTunes.add(appscript.mactypes.File(file))
|
||||
|
||||
elif iswindows:
|
||||
lib = self.iTunes.LibraryPlaylist
|
||||
@ -1095,6 +1098,28 @@ class ITUNES(DevicePlugin):
|
||||
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)
|
||||
@ -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'],
|
||||
@ -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")
|
||||
@ -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
|
||||
@ -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")
|
||||
@ -1835,7 +1907,6 @@ class ITUNES(DevicePlugin):
|
||||
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:
|
||||
@ -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