matching¶
Classes and methods to easily compare the compatibility of a result with a song being matched. Uses fuzzy string comparison with the RapidFuzz package.
Matching is done individually on song name, title, primary artist, other artists, album name, and length - artist matches are calculated down to a single score value (scores go from 0 to 100). If the fields in one of the Song objects being compared are null, the corresponding match score will also be null.
The sum (i.e. total match score) is scaled based on how many match scores are null, so that it always falls on a range of 0 to 100.
| MODULE | DESCRIPTION |
|---|---|
utils |
Utility functions for the |
| CLASS | DESCRIPTION |
|---|---|
MatchQuality |
Thresholds to consider when getting the quality of a match. Values are based on the sum of all matches - if |
MatchResult |
Holds match results and provides convenient property methods to get/calculate quality and match score. |
MatchQuality
¶
Bases: Enum
Thresholds to consider when getting the quality of a match. Values are based on the sum of all matches - if all are perfect, equals to 100.
GREAT
class-attribute
instance-attribute
¶
GREAT = 90
Extremely likely songs are the same. Different platforms usually have small discrepancies in the matching value.
GOOD
class-attribute
instance-attribute
¶
GOOD = 80
Likely a different version of the same song, like a live version for example.
MEDIOCRE
class-attribute
instance-attribute
¶
MEDIOCRE = 60
Probably a cover from another artist or something else from the same artist.
MatchResult
dataclass
¶
MatchResult(
method: str,
name_match: float | None,
title_match: float | None,
artists_match: list[Tuple[Artist, float]] | None,
result_artists_matches: (
list[Tuple[Artist, float]] | None
),
album_match: float | None,
length_match: float | None,
)
Holds match results and provides convenient property methods to get/calculate quality and match score.
| ATTRIBUTE | DESCRIPTION |
|---|---|
method |
Comparison method used, such as
TYPE:
|
name_match |
Score for similarity in the song's names.
TYPE:
|
title_match |
Score for similarity in the song's titles, taken from the
TYPE:
|
artists_match |
Score for similarity in the original song's artists, compared against the result song's.
TYPE:
|
result_artists_matches |
Score for similarity in the result song's artists, compared against the original song's.
TYPE:
|
album_match |
Score for similarity in the song's albums.
TYPE:
|
length_match |
Score for similarity in the song's lengths. Score is scaled according to the equation \(y=1-(f*x^2)\), where \(f\) is an arbitrary "falloff" value.
TYPE:
|
result_artists_matches
instance-attribute
¶
result_artists_matches: list[Tuple[Artist, float]] | None
quality
property
¶
quality: MatchQuality
Returns the match quality from the enum MatchQuality based on the sum of points.
artists_match_avg
property
¶
artists_match_avg: float | None
Averages the match score of the list of artists. Returns zero if list is empty.
sum
property
¶
sum: float
Sums all matches (uses average artist match value). Result will be scaled to fall under 0 to 100.
all_above_threshold
¶
all_above_threshold(threshold: float) -> bool
Checks if all the scores are above the threshold value given.
| PARAMETER | DESCRIPTION |
|---|---|
|
Tha value that will be compared to all the values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if every match score is higher than the threshold, false otherwise. |
Source code in src/downmixer/matching/__init__.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
match
¶
match(
original_song: Song, result_song: Song
) -> MatchResult
Returns match values using RapidFuzz comparing the two given song objects.
| PARAMETER | DESCRIPTION |
|---|---|
|
Song to be compared to. Should be slugified for better results.
TYPE:
|
|
Song being compared. Should be slugified for better results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MatchResult
|
Match scores of the comparison between original and result song.
TYPE:
|
Source code in src/downmixer/matching/__init__.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |