Exemplo n.º 1
0
    def test_exclude_items_single_match(self):
        included_any = list(
            exclude_items(TEST_MAPPING_ITEMS_1, any_all=any, title=['Take']))
        included_all = list(
            exclude_items(TEST_MAPPING_ITEMS_1, any_all=all, title=['Take']))
        expected = [TEST_MAPPING_ITEMS_1[1]]

        assert included_any == included_all == expected
Exemplo n.º 2
0
    def test_exclude_items_single_no_match(self):
        included_any = list(
            exclude_items(TEST_MAPPING_ITEMS_1, any_all=any,
                          artist=['Modest']))
        included_all = list(
            exclude_items(TEST_MAPPING_ITEMS_1, any_all=any,
                          artist=['Modest']))
        expected = TEST_MAPPING_ITEMS_1

        assert included_any == included_all == expected
Exemplo n.º 3
0
    def test_exclude_items_all_mutliple_no_match(self):
        included = list(
            exclude_items(TEST_MAPPING_ITEMS_1,
                          any_all=all,
                          artist=['Modest'],
                          title=['Everything']))
        expected = TEST_MAPPING_ITEMS_1

        assert included == expected
Exemplo n.º 4
0
    def test_exclude_items_all_multiple_match(self):
        included = list(
            exclude_items(TEST_MAPPING_ITEMS_1,
                          any_all=all,
                          artist=['Muse'],
                          title=['Take']))
        expected = [TEST_MAPPING_ITEMS_1[1]]

        assert included == expected
Exemplo n.º 5
0
def filter_metadata(songs, filters):
	if filters:
		logger.success("Filtering songs")

		matched_songs = []

		for filter_ in filters:
			include_filters = defaultdict(list)
			exclude_filters = defaultdict(list)

			for condition in filter_:
				if condition.oper == '+':
					include_filters[condition.field].append(condition.pattern)
				elif condition.oper == '-':
					exclude_filters[condition.field].append(condition.pattern)

			matched = songs

			# Use all if multiple conditions for inclusion.
			i_use_all = (
				(len(include_filters) > 1)
				or any(
					len(v) > 1
					for v in include_filters.values()
				)
			)
			i_any_all = all if i_use_all else any
			matched = gm_utils.include_items(
				matched, any_all=i_any_all, ignore_case=True, **include_filters
			)

			# Use any if multiple conditions for exclusion.
			e_use_all = not (
				(len(exclude_filters) > 1)
				or any(
					len(v) > 1
					for v in exclude_filters.values()
				)
			)
			e_any_all = all if e_use_all else any
			matched = gm_utils.exclude_items(
				matched, any_all=e_any_all, ignore_case=True, **exclude_filters
			)

			for song in matched:
				if song not in matched_songs:
					matched_songs.append(song)
	else:
		matched_songs = songs

	return matched_songs
Exemplo n.º 6
0
    def test_exclude_items_no_filters(self):
        included_any = list(exclude_items(TEST_MAPPING_ITEMS_1, any_all=any))
        included_all = list(exclude_items(TEST_MAPPING_ITEMS_1, any_all=all))
        expected = TEST_MAPPING_ITEMS_1

        assert included_any == included_all == expected