Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding most popular matching track when no track matches duration is a bad idea... #20

Open
lorenzolamasse opened this issue Oct 31, 2024 · 2 comments

Comments

@lorenzolamasse
Copy link

lorenzolamasse commented Oct 31, 2024

Hi,

Made a slight modif in my local base to avoid adding a random matching track when there is no track matching the exact duration. It's mostly the case with remixes and extended versions that are not (yet) available on Spotify. I personally prefer skipping these tracks instead of adding a random version of them:

def best_of_multiple_matches(source_track, found_tracks):
    counter = 1
    duration_matches = [
        0,
    ]
    for track in found_tracks:
        print("\t\t\t[+] Match {}: {}".format(counter, track["id"]))
        if do_durations_match(source_track["duration_ms"], track["duration_ms"]):
            duration_matches[0] += 1
            duration_matches.append(track)
        counter += 1
    if duration_matches[0] == 1:
        best_track = duration_matches.pop()["id"]
        print(
            "\t\t\t[+] Only one exact match with matching duration, going with that one: {}".format(
                best_track
            )
        )
        return best_track
    else:
        if duration_matches[0] == 0:
            print("No track with matching duration, ignoring track !")
        else:
            
            # TODO: Popularity does not always yield the correct result
            best_track = most_popular_track(found_tracks)
            print(
                "\t\t\t[+] Multiple exact matches with matching durations, going with the most popular one: {}".format(
                best_track
                )
                )
            return best_track
@lorenzolamasse
Copy link
Author

lorenzolamasse commented Oct 31, 2024

Modified a slight bit as well the duration matching as it happens quite often to have around 1 seconds of duration difference between platforms:

def do_durations_match(source_track_duration, found_track_duration):
    if abs(source_track_duration - found_track_duration) < 1000:
        print("\t\t\t\t[+] Durations match")
        return True
    else:
        print("\t\t\t\t[!] Durations do not match")
        return False

@mclopes
Copy link

mclopes commented Dec 26, 2024

I changed the code to just return the first match if there is no exact match. I was running into the issue where usually the first match was correct but it was skipping it because spotify didnt have an extended version or the time was different by more than one second. This has yielded the best results for me.

`def best_of_multiple_matches(source_track, found_tracks):
    counter = 1
    duration_matches = [0, ]
    for track in found_tracks:
        print("\t\t\t[+] Match {}: {}".format(counter, track["id"]))
        if do_durations_match(source_track["duration_ms"], track["duration_ms"]):
            duration_matches[0] += 1
            duration_matches.append(track)
        counter += 1
    if duration_matches[0] == 1:
        best_track = duration_matches.pop()["id"]
        print("\t\t\t[+] Only one exact match with matching duration, going with that one: {}".format(best_track))
        return best_track

    # Modified: Return the first match instead of the most popular
    best_track = found_tracks[0]["id"]
    print("\t\t\t[+] No exact match with duration, going with the first match: {}".format(best_track))
    return best_track`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants