From 86a311a0da16d33e04f8c89cb609f601a0fd19d5 Mon Sep 17 00:00:00 2001 From: Benjamin_Loison Date: Mon, 20 Feb 2023 14:17:26 +0100 Subject: [PATCH] Add ``Computing `MAXIMAL_NUMBER_OF_RESULTS``` section --- Home.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Home.md b/Home.md index 9a21035..98812e2 100644 --- a/Home.md +++ b/Home.md @@ -55,4 +55,36 @@ for track in tracks: #break else: ids[id] = track +``` + +# Computing `MAXIMAL_NUMBER_OF_RESULTS` + +The updated algorithm initially published in 588b20409b5acc2e4412427ccd1d333847157400 is: + +```py +import os, json + +path = '/home/benjamin/Desktop/bens_folder/dev/yt/audio_library' + +os.chdir(path) + +with open('music.json') as json_file: + tracks = json.load(json_file) + +mostResults = 0 +mostResultsTitle = None + +for track in tracks: + title = track['title'] + results = 0 + for otherTrack in tracks: + # Doesn't used to have `replace` and `lower`, but it seems that it is what YouTube UI title search does. + title = title.replace('!', '') + if title.lower() in otherTrack['title'].lower(): + results += 1 + if results > mostResults: + mostResults = results + mostResultsTitle = title + +print(mostResults, mostResultsTitle) ``` \ No newline at end of file