rewrite search functions as classes

This commit is contained in:
geoffrey45
2022-05-18 18:04:01 +03:00
parent 8405efede0
commit 4040b99518
9 changed files with 170 additions and 32 deletions
+10 -3
View File
@@ -52,6 +52,10 @@ def create_everything() -> List[models.Track]:
def find_album(albums: List[models.Album], hash: str) -> int | None:
"""
Finds an album by album title and artist.
:param `albums`: List of album objects.
:param `hash`: Hash of album.
:return: Index of album in list.
"""
left = 0
@@ -62,8 +66,11 @@ def find_album(albums: List[models.Album], hash: str) -> int | None:
iter += 1
mid = (left + right) // 2
if albums[mid].hash == hash:
return mid
try:
if albums[mid].hash == hash:
return mid
except AttributeError:
print(albums)
if albums[mid].hash < hash:
left = mid + 1
@@ -151,7 +158,7 @@ def get_album_tracks(album: str, artist: str) -> List:
return GetAlbumTracks(album, artist).find_tracks()
def create_album(track: dict, tracklist: list) -> models.Album:
def create_album(track: dict, tracklist: list) -> dict:
"""
Generates and returns an album object from a track object.
"""