''

def _update_iTunes_metadata(self, metadata, db_added, lb_added, this_book):

    if self.verbose:
        logger().info(('    %s._update_iTunes_metadata()' % self.__class__.__name__))
    STRIP_TAGS = re.compile('<[^<]*?/?>')
    metadata_x = self._xform_metadata_via_plugboard(metadata, this_book.format)
    if isosx:
        if lb_added:
            lb_added.name.set(metadata_x.title)
            lb_added.album.set(metadata_x.title)
            lb_added.artist.set(authors_to_string(metadata_x.authors))
            lb_added.composer.set(metadata_x.uuid)
            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(icu_title(metadata_x.author_sort))
            lb_added.sort_name.set(metadata_x.title_sort)
            lb_added.year.set(metadata_x.pubdate.year)
        if db_added:
            db_added.name.set(metadata_x.title)
            db_added.album.set(metadata_x.title)
            db_added.artist.set(authors_to_string(metadata_x.authors))
            db_added.composer.set(metadata_x.uuid)
            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(icu_title(metadata_x.author_sort))
            db_added.sort_name.set(metadata_x.title_sort)
            db_added.year.set(metadata_x.pubdate.year)
        if metadata_x.comments:
            if lb_added:
                lb_added.comment.set(STRIP_TAGS.sub('', metadata_x.comments))
            if db_added:
                db_added.comment.set(STRIP_TAGS.sub('', metadata_x.comments))
        if metadata_x.rating:
            if lb_added:
                lb_added.rating.set((metadata_x.rating * 10))
            try:
                if db_added:
                    db_added.rating.set((metadata_x.rating * 10))
            except:
                pass
        if (metadata_x.series and self.settings().extra_customization[self.USE_SERIES_AS_CATEGORY]):
            if self.verbose:
                logger().info(('    %s._update_iTunes_metadata()' % self.__class__.__name__))
                logger().info(("            using    Series    name    '%s'    as    Genre" % metadata_x.series))
            index = metadata_x.series_index
            integer = int(index)
            fraction = (index - integer)
            series_index = ('%04d%s' % (integer, str(('%0.4f' % fraction)).lstrip('0')))
            if lb_added:
                if (metadata.title_sort == metadata_x.title_sort):
                    lb_added.sort_name.set(('%s    %s' % (self.title_sorter(metadata_x.series), series_index)))
                lb_added.episode_ID.set(metadata_x.series)
                lb_added.episode_number.set(metadata_x.series_index)
                if (metadata.tags == metadata_x.tags):
                    lb_added.genre.set(self.title_sorter(metadata_x.series))
                else:
                    for tag in metadata_x.tags:
                        if self._is_alpha(tag[0]):
                            lb_added.genre.set(tag)
                            break
            if db_added:
                if self.verbose:
                    logger().info('        waiting    for    db_added    to    become    writable    ')
                time.sleep(1.0)
                if (metadata.title_sort == metadata_x.title_sort):
                    db_added.sort_name.set(('%s    %s' % (self.title_sorter(metadata_x.series), series_index)))
                db_added.episode_ID.set(metadata_x.series)
                db_added.episode_number.set(metadata_x.series_index)
                if (metadata.tags == metadata_x.tags):
                    db_added.genre.set(self.title_sorter(metadata_x.series))
                else:
                    for tag in metadata_x.tags:
                        if self._is_alpha(tag[0]):
                            db_added.genre.set(tag)
                            break
        elif (metadata_x.tags is not None):
            if self.verbose:
                logger().info((('            %susing    Tag    as    Genre' % 'no    Series    name    available,    ') if self.settings().extra_customization[self.USE_SERIES_AS_CATEGORY] else ''))
            for tag in metadata_x.tags:
                if self._is_alpha(tag[0]):
                    if lb_added:
                        lb_added.genre.set(tag)
                    if db_added:
                        db_added.genre.set(tag)
                    break
    elif iswindows:
        if lb_added:
            lb_added.Name = metadata_x.title
            lb_added.Album = metadata_x.title
            lb_added.Artist = authors_to_string(metadata_x.authors)
            lb_added.Composer = metadata_x.uuid
            lb_added.Description = ('%s    %s' % (self.description_prefix, strftime('%Y-%m-%d    %H:%M:%S')))
            lb_added.Enabled = True
            lb_added.SortArtist = icu_title(metadata_x.author_sort)
            lb_added.SortName = metadata_x.title_sort
            lb_added.Year = metadata_x.pubdate.year
        if db_added:
            if self.verbose:
                logger().info('        waiting    for    metadata    to    become    writeable    on    iDevice')
            WAIT_TIME = 0.5
            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)
                    db_added.Composer = metadata_x.uuid
                    db_added.Description = ('%s    %s' % (self.description_prefix, strftime('%Y-%m-%d    %H:%M:%S')))
                    db_added.Enabled = True
                    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:
                lb_added.Comment = STRIP_TAGS.sub('', metadata_x.comments)
            if db_added:
                db_added.Comment = STRIP_TAGS.sub('', metadata_x.comments)
        if metadata_x.rating:
            if lb_added:
                lb_added.AlbumRating = (metadata_x.rating * 10)
            try:
                if db_added:
                    db_added.AlbumRating = (metadata_x.rating * 10)
            except:
                if self.verbose:
                    logger().info('        iTunes    automation    interface    reported    an    error    setting    AlbumRating    on    iDevice')
        if (metadata_x.series and self.settings().extra_customization[self.USE_SERIES_AS_CATEGORY]):
            if self.verbose:
                logger().info('            using    Series    name    as    Genre')
            index = metadata_x.series_index
            integer = int(index)
            fraction = (index - integer)
            series_index = ('%04d%s' % (integer, str(('%0.4f' % fraction)).lstrip('0')))
            if lb_added:
                if (metadata.title_sort == metadata_x.title_sort):
                    lb_added.SortName = ('%s    %s' % (self.title_sorter(metadata_x.series), series_index))
                lb_added.EpisodeID = metadata_x.series
                try:
                    lb_added.TrackNumber = metadata_x.series_index
                except:
                    if self.verbose:
                        logger().info('        iTunes    automation    interface    reported    an    error    setting    TrackNumber    in    iTunes')
                try:
                    lb_added.EpisodeNumber = metadata_x.series_index
                except:
                    if self.verbose:
                        logger().info('        iTunes    automation    interface    reported    an    error    setting    EpisodeNumber    in    iTunes')
                if (metadata.tags == metadata_x.tags):
                    lb_added.Genre = self.title_sorter(metadata_x.series)
                else:
                    for tag in metadata_x.tags:
                        if self._is_alpha(tag[0]):
                            lb_added.Genre = tag
                            break
            if db_added:
                if (metadata.title_sort == metadata_x.title_sort):
                    db_added.SortName = ('%s    %s' % (self.title_sorter(metadata_x.series), series_index))
                db_added.EpisodeID = metadata_x.series
                try:
                    db_added.TrackNumber = metadata_x.series_index
                except:
                    if self.verbose:
                        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().info('        iTunes    automation    interface    reported    an    error    setting    EpisodeNumber    on    iDevice')
                if (metadata.tags == metadata_x.tags):
                    db_added.Genre = self.title_sorter(metadata_x.series)
                else:
                    for tag in metadata_x.tags:
                        if self._is_alpha(tag[0]):
                            db_added.Genre = tag
                            break
        elif (metadata_x.tags is not None):
            if self.verbose:
                logger().info('            using    Tag    as    Genre')
            for tag in metadata_x.tags:
                if self._is_alpha(tag[0]):
                    if lb_added:
                        lb_added.Genre = tag
                    if db_added:
                        db_added.Genre = tag
                    break
