示例#1
0
文件: ihate.py 项目: nanux/beets
 def do_i_hate_this(cls, task, action_patterns):
     """Process group of patterns (warn or skip) and returns True if
     task is hated and not whitelisted.
     """
     if action_patterns:
         for query_string in action_patterns:
             query = None
             if task.is_album:
                 (query, _) = get_query_sort(query_string, Album)
             else:
                 (query, _) = get_query_sort(query_string, Item)
             if any(query.match(item) for item in task.imported_items()):
                 return True
     return False
示例#2
0
 def do_i_hate_this(cls, task, action_patterns):
     """Process group of patterns (warn or skip) and returns True if
     task is hated and not whitelisted.
     """
     if action_patterns:
         for query_string in action_patterns:
             query = None
             if task.is_album:
                 (query, _) = get_query_sort(query_string, Album)
             else:
                 (query, _) = get_query_sort(query_string, Item)
             if any(query.match(item) for item in task.imported_items()):
                 return True
     return False
示例#3
0
def _items_for_query(lib, playlist, album=False):
    """Get the matching items for a playlist's configured queries.
    `album` indicates whether to process the item-level query or the
    album-level query (if any).
    """
    key = 'album_query' if album else 'query'
    if key not in playlist:
        return []

    # Parse quer(ies). If it's a list, join the queries with OR.
    query_strings = playlist[key]
    if not isinstance(query_strings, (list, tuple)):
        query_strings = [query_strings]
    model = library.Album if album else library.Item
    query = dbcore.OrQuery(
        [library.get_query_sort(q, model)[0] for q in query_strings]
    )

    # Execute query, depending on type.
    if album:
        result = []
        for album in lib.albums(query):
            result.extend(album.items())
        return result
    else:
        return lib.items(query)