'assumes pythoncom wrapper for windows'

def _add_device_book(self, fpath, metadata):

    if self.verbose:
        logger().info(('    %s._add_device_book()' % self.__class__.__name__))
    if isosx:
        import appscript
        if ('iPod' in self.sources):
            connected_device = self.sources['iPod']
            device = self.iTunes.sources[connected_device]
            for pl in device.playlists():
                if (pl.special_kind() == appscript.k.Books):
                    break
            else:
                if self.verbose:
                    logger().error('        Device|Books    playlist    not    found')
            attempts = 2
            delay = 1.0
            while attempts:
                try:
                    added = pl.add(appscript.mactypes.File(fpath), to=pl)
                    if False:
                        logger().info(("        '%s'    added    to    Device|Books" % metadata.title))
                    break
                except:
                    attempts -= 1
                    if self.verbose:
                        logger().warning(('        failed    to    add    book,    waiting    %.1f    seconds    to    try    again    (attempt    #%d)' % (delay, (3 - attempts))))
                    time.sleep(delay)
            else:
                if self.verbose:
                    logger().error(("    failed    to    add    '%s'    to    Device|Books" % metadata.title))
                raise UserFeedback(("Unable    to    add    '%s'    in    direct    connect    mode" % metadata.title), details=None, level=UserFeedback.ERROR)
            return added
    elif iswindows:
        if ('iPod' in self.sources):
            connected_device = self.sources['iPod']
            device = self.iTunes.sources.ItemByName(connected_device)
            db_added = None
            for pl in device.Playlists:
                if ((pl.Kind == self.PlaylistKind.index('User')) and (pl.SpecialKind == self.PlaylistSpecialKind.index('Books'))):
                    break
            else:
                if self.verbose:
                    logger().info('        no    Books    playlist    found')
            if pl:
                file_s = ctypes.c_char_p(fpath)
                FileArray = (ctypes.c_char_p * 1)
                fa = FileArray(file_s)
                op_status = pl.AddFiles(fa)
                if self.verbose:
                    sys.stdout.write(("        uploading    '%s'    to    Device|Books    ..." % metadata.title))
                    sys.stdout.flush()
                while op_status.InProgress:
                    time.sleep(0.5)
                    if self.verbose:
                        sys.stdout.write('.')
                        sys.stdout.flush()
                if self.verbose:
                    sys.stdout.write('\n')
                    sys.stdout.flush()
                if False:
                    '\n                                                                                                Preferred\n                                                                                                Disabled    because    op_status.Tracks    never    returns    a    value    after    adding    file\n                                                                                                This    would    be    the    preferred    approach    (as    under    OSX)\n                                                                                                It    works    in    _add_library_book()\n                                                                                                '
                    if self.verbose:
                        sys.stdout.write(("        waiting    for    handle    to    added    '%s'    ..." % metadata.title))
                        sys.stdout.flush()
                    while (not op_status.Tracks):
                        time.sleep(0.5)
                        if self.verbose:
                            sys.stdout.write('.')
                            sys.stdout.flush()
                    if self.verbose:
                        print
                    added = op_status.Tracks[0]
                else:
                    '\n                                                                                                Hackish\n                                                                                                Search    Library|Books    for    the    book    we    just    added\n                                                                                                PDF    file    name    is    added    title    -    need    to    search    for    base    filename    w/o    extension\n                                                                                                '
                    format = fpath.rpartition('.')[2].lower()
                    base_fn = fpath.rpartition(os.sep)[2]
                    base_fn = base_fn.rpartition('.')[0]
                    db_added = self._find_device_book({'title': (base_fn if (format == 'pdf') else metadata.title), 'author': authors_to_string(metadata.authors), 'uuid': metadata.uuid, 'format': format})
                return db_added
