Add `Computing MAXIMAL_NUMBER_OF_RESULTS``` section

Benjamin Loison 2023-02-20 14:17:26 +01:00
parent 9a8493f397
commit 86a311a0da

32
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)
```