mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added test for no existing playlists in response to lp:1141078. Driver is unable to add books to iTunes if Books playlist doesn't already exist.
This commit is contained in:
parent
9fa3a1b558
commit
88c150fd2e
@ -20,8 +20,7 @@ from calibre.utils.config import config_dir, dynamic, prefs
|
|||||||
from calibre.utils.date import now, parse_date
|
from calibre.utils.date import now, parse_date
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = CALIBRE_DEBUG
|
||||||
#DEBUG = CALIBRE_DEBUG
|
|
||||||
|
|
||||||
def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None):
|
def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None):
|
||||||
|
|
||||||
@ -862,7 +861,6 @@ class ITUNES(DriverBase):
|
|||||||
Note that most of the initialization is necessarily performed in can_handle(), as
|
Note that most of the initialization is necessarily performed in can_handle(), as
|
||||||
we need to talk to iTunes to discover if there's a connected iPod
|
we need to talk to iTunes to discover if there's a connected iPod
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if self.iTunes is None:
|
if self.iTunes is None:
|
||||||
raise OpenFeedback(self.ITUNES_SANDBOX_LOCKOUT_MESSAGE)
|
raise OpenFeedback(self.ITUNES_SANDBOX_LOCKOUT_MESSAGE)
|
||||||
|
|
||||||
@ -2157,27 +2155,28 @@ class ITUNES(DriverBase):
|
|||||||
if 'iPod' in self.sources:
|
if 'iPod' in self.sources:
|
||||||
connected_device = self.sources['iPod']
|
connected_device = self.sources['iPod']
|
||||||
device = self.iTunes.sources[connected_device]
|
device = self.iTunes.sources[connected_device]
|
||||||
dev_books = None
|
if device.playlists() is not None:
|
||||||
for pl in device.playlists():
|
dev_books = None
|
||||||
if pl.special_kind() == appscript.k.Books:
|
for pl in device.playlists():
|
||||||
if DEBUG:
|
if pl.special_kind() == appscript.k.Books:
|
||||||
logger().info(" Book playlist: '%s'" % (pl.name()))
|
if DEBUG:
|
||||||
dev_books = pl.file_tracks()
|
logger().info(" Book playlist: '%s'" % (pl.name()))
|
||||||
break
|
dev_books = pl.file_tracks()
|
||||||
else:
|
break
|
||||||
logger().error(" book_playlist not found")
|
|
||||||
|
|
||||||
for book in dev_books:
|
|
||||||
if book.kind() in self.Audiobooks:
|
|
||||||
if DEBUG:
|
|
||||||
logger().info(" ignoring '%s' of type '%s'" % (book.name(), book.kind()))
|
|
||||||
else:
|
else:
|
||||||
if DEBUG:
|
logger().error(" book_playlist not found")
|
||||||
logger().info(" %-40.40s %-30.30s %-40.40s [%s]" %
|
|
||||||
(book.name(), book.artist(), book.composer(), book.kind()))
|
for book in dev_books:
|
||||||
device_books.append(book)
|
if book.kind() in self.Audiobooks:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info()
|
logger().info(" ignoring '%s' of type '%s'" % (book.name(), book.kind()))
|
||||||
|
else:
|
||||||
|
if DEBUG:
|
||||||
|
logger().info(" %-40.40s %-30.30s %-40.40s [%s]" %
|
||||||
|
(book.name(), book.artist(), book.composer(), book.kind()))
|
||||||
|
device_books.append(book)
|
||||||
|
if DEBUG:
|
||||||
|
logger().info()
|
||||||
|
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
import pythoncom
|
import pythoncom
|
||||||
@ -2187,29 +2186,29 @@ class ITUNES(DriverBase):
|
|||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
connected_device = self.sources['iPod']
|
connected_device = self.sources['iPod']
|
||||||
device = self.iTunes.sources.ItemByName(connected_device)
|
device = self.iTunes.sources.ItemByName(connected_device)
|
||||||
|
if device.Playlists is not None:
|
||||||
dev_books = None
|
dev_books = None
|
||||||
for pl in device.Playlists:
|
for pl in device.Playlists:
|
||||||
if pl.Kind == self.PlaylistKind.index('User') and \
|
if pl.Kind == self.PlaylistKind.index('User') and \
|
||||||
pl.SpecialKind == self.PlaylistSpecialKind.index('Books'):
|
pl.SpecialKind == self.PlaylistSpecialKind.index('Books'):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info(" Books playlist: '%s'" % (pl.Name))
|
logger().info(" Books playlist: '%s'" % (pl.Name))
|
||||||
dev_books = pl.Tracks
|
dev_books = pl.Tracks
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
if DEBUG:
|
|
||||||
logger().info(" no Books playlist found")
|
|
||||||
|
|
||||||
for book in dev_books:
|
|
||||||
if book.KindAsString in self.Audiobooks:
|
|
||||||
if DEBUG:
|
|
||||||
logger().info(" ignoring '%s' of type '%s'" % (book.Name, book.KindAsString))
|
|
||||||
else:
|
else:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
logger().info(" %-40.40s %-30.30s %-40.40s [%s]" % (book.Name, book.Artist, book.Composer, book.KindAsString))
|
logger().info(" no Books playlist found")
|
||||||
device_books.append(book)
|
|
||||||
if DEBUG:
|
for book in dev_books:
|
||||||
logger().info()
|
if book.KindAsString in self.Audiobooks:
|
||||||
|
if DEBUG:
|
||||||
|
logger().info(" ignoring '%s' of type '%s'" % (book.Name, book.KindAsString))
|
||||||
|
else:
|
||||||
|
if DEBUG:
|
||||||
|
logger().info(" %-40.40s %-30.30s %-40.40s [%s]" % (book.Name, book.Artist, book.Composer, book.KindAsString))
|
||||||
|
device_books.append(book)
|
||||||
|
if DEBUG:
|
||||||
|
logger().info()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
pythoncom.CoUninitialize()
|
pythoncom.CoUninitialize()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user