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

def _find_device_book(self, search, attempts=9):

    if iswindows:
        dev_books = self._get_device_books_playlist()
        if self.verbose:
            logger().info(('    %s._find_device_book()' % self.__class__.__name__))
            logger().info(("        searching    for    '%s'    by    '%s'    (%s)" % (search['title'], search['author'], search['uuid'])))
        while attempts:
            if (('uuid' in search) and search['uuid']):
                if self.verbose:
                    logger().info(("            searching    by    uuid    '%s'    ..." % search['uuid']))
                hits = dev_books.Search(search['uuid'], self.SearchField.index('All'))
                if hits:
                    hit = hits[0]
                    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 = dev_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 = dev_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 = dev_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 (attempts and self.verbose):
                logger().info(('        attempt    #%d' % (10 - attempts)))
        if self.verbose:
            logger().error('        no    hits')
        return None
