plistsync.core.matchingΒΆ

Track matching algorithms.

This module provides various algorithms and utilities for matching music tracks based on their metadata. It includes functions for fuzzy matching, calculating similarity scores, and handling different types of metadata such as strings and lists.

OverviewΒΆ

ClassesΒΆ

Matches

Represents the result of a track matching operation.

FunctionΒΆ

fuzzy_match(a, b)

Calculate the similarity between two track infos.

distance(a, b)

Calculate the distance between two values.

yield_matched_keys(a, b)

Iterate over the keys of two dict objects.

Module ContentsΒΆ

class plistsync.core.matching.MatchesΒΆ

Bases: Generic[T]

Represents the result of a track matching operation.

property similarity: SimilarityΒΆ

Highest similarity value, corresponding to the best match.

1.0 -> perfect match, found has len 1 0.0 -> no match, found has len 0 else -> multiple matches

property best_match: T | NoneΒΆ

Get the best matching track, or None if no matches found.

plistsync.core.matching.fuzzy_match(a: plistsync.core.track.TrackInfo, b: plistsync.core.track.TrackInfo) SimilarityΒΆ

Calculate the similarity between two track infos.

Interpreting the results: - 1.0: All found metadata is equal. (All does not include undefined metadata, including empty strings and None values.) - 0.0: No metadata is the same.

Return:ΒΆ

float

The similarity metric between the two tracks.

plistsync.core.matching.distance(a: str | list[str], b: str | list[str]) float | NoneΒΆ

Calculate the distance between two values.

Lists are permutation invariant.

Returns:

The distance between the two values. Normalized to a ratio between 0 and 1, where 0 is no match and 1 is a perfect match. Returns None when invalid objects are passed or empty strings (or empty lists) are compared.

Return type:

float or None

plistsync.core.matching.yield_matched_keys(a: collections.abc.Mapping[str, V], b: collections.abc.Mapping[str, V]) collections.abc.Iterable[tuple[str, V, V]]ΒΆ

Iterate over the keys of two dict objects.

Iterate over the keys of two dict objects and yield the key and the values of both objects if they are present in both.