'Windows-only method to get a handle to a library book in the current pythoncom session'

def _find_library_book(self, search):

    if iswindows:
        if self.verbose:
            logger().info(('    %s._find_library_book()' % self.__class__.__name__))
            '\n                                                                if    \'uuid\'    in    search:\n                                                                                logger().info("        looking    for    \'%s\'    by    %s    (%s)"    %\n                                                                                                                                (search[\'title\'],    search[\'author\'],    search[\'uuid\']))\n                                                                else:\n                                                                                logger().info("        looking    for    \'%s\'    by    %s"    %\n                                                                                                                                (search[\'title\'],    search[\'author\']))\n                                                                '
        for source in self.iTunes.sources:
            if (source.Kind == self.Sources.index('Library')):
                lib = source
                if self.verbose:
                    logger().info(("        Library    source:    '%s'        kind:    %s" % (lib.Name, self.Sources[lib.Kind])))
                break
        else:
            if self.verbose:
                logger().info('        Library    source    not    found')
        if (lib is not None):
            lib_books = None
            for pl in lib.Playlists:
                if ((pl.Kind == self.PlaylistKind.index('User')) and (pl.SpecialKind == self.PlaylistSpecialKind.index('Books'))):
                    if self.verbose:
                        logger().info(("        Books    playlist:    '%s'" % pl.Name))
                    lib_books = pl
                    break
            else:
                if self.verbose:
                    logger().error('        no    Books    playlist    found')
        attempts = 9
        while attempts:
            if (('uuid' in search) and search['uuid']):
                if self.verbose:
                    logger().info(("            searching    by    uuid    '%s'    ..." % search['uuid']))
                hits = lib_books.Search(search['uuid'], self.SearchField.index('All'))
                if hits:
                    hit = hits[0]
                    if self.verbose:
                        logger().info(("            found    '%s'    by    %s    (%s)" % (hit.Name, hit.Artist, hit.Composer)))
                    return hit
            if search['author']:
                if self.verbose:
                    logger().info(("            searching    by    author    '%s'    ..." % search['author']))
                hits = lib_books.Search(search['author'], self.SearchField.index('Artists'))
                if hits:
                    for hit in hits:
                        if (hit.Name == search['title']):
                            if self.verbose:
                                logger().info(("            found    '%s'    by    %s    (%s)" % (hit.Name, hit.Artist, hit.Composer)))
                            return hit
            if self.verbose:
                logger().info(("            searching    by    title    '%s'    ..." % search['title']))
            hits = lib_books.Search(search['title'], self.SearchField.index('All'))
            if hits:
                for hit in hits:
                    if (hit.Name == search['title']):
                        if self.verbose:
                            logger().info(("            found    '%s'" % hit.Name))
                        return hit
            if (search['format'] == 'pdf'):
                title = re.sub('[^0-9a-zA-Z    ]', '_', search['title'])
                author = re.sub('[^0-9a-zA-Z    ]', '_', search['author'])
                if self.verbose:
                    logger().info(('            searching    by    name:    %s    -    %s' % (title, author)))
                hits = lib_books.Search(('%s    -    %s' % (title, author)), self.SearchField.index('All'))
                if hits:
                    hit = hits[0]
                    logger().info(("            found    '%s'    by    %s    (%s)" % (hit.Name, hit.Artist, hit.Composer)))
                    return hit
                elif self.verbose:
                    logger().info('            no    PDF    hits')
            attempts -= 1
            time.sleep(0.5)
            if self.verbose:
                logger().info(('            attempt    #%d' % (10 - attempts)))
        if self.verbose:
            logger().info(("        search    for    '%s'    yielded    no    hits" % search['title']))
        return None
