mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
fix removing duplicate tracks
- add uniq_hash prop to Track class
This commit is contained in:
@@ -2,11 +2,8 @@
|
||||
This library contains all the functions related to tracks.
|
||||
"""
|
||||
import os
|
||||
from pprint import pprint
|
||||
from typing import List
|
||||
|
||||
from app import api, instances, models
|
||||
from app.helpers import remove_duplicates
|
||||
from app import instances
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
@@ -23,51 +20,6 @@ def validate_tracks() -> None:
|
||||
instances.tracks_instance.remove_song_by_id(track["_id"]["$oid"])
|
||||
|
||||
|
||||
def get_album_tracks(albumname, artist):
|
||||
"""Returns api tracks matching an album"""
|
||||
_tracks: List[models.Track] = []
|
||||
|
||||
for track in api.TRACKS:
|
||||
if track.album == albumname and track.albumartist == artist:
|
||||
_tracks.append(track)
|
||||
|
||||
return remove_duplicates(_tracks)
|
||||
|
||||
|
||||
def get_track_by_id(trackid: str) -> models.Track:
|
||||
"""Returns api track matching an id"""
|
||||
for track in api.TRACKS:
|
||||
try:
|
||||
if track.trackid == trackid:
|
||||
return track
|
||||
except AttributeError:
|
||||
print("AttributeError")
|
||||
|
||||
|
||||
def find_track(tracks: list, hash: str) -> int | None:
|
||||
"""
|
||||
Finds an album by album title and artist.
|
||||
"""
|
||||
|
||||
left = 0
|
||||
right = len(tracks) - 1
|
||||
iter = 0
|
||||
|
||||
while left <= right:
|
||||
iter += 1
|
||||
mid = (left + right) // 2
|
||||
|
||||
if tracks[mid]["albumhash"] == hash:
|
||||
return mid
|
||||
|
||||
if tracks[mid]["albumhash"] < hash:
|
||||
left = mid + 1
|
||||
else:
|
||||
right = mid - 1
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_p_track(ptrack):
|
||||
return instances.tracks_instance.find_track_by_title_artists_album(
|
||||
ptrack["title"], ptrack["artists"], ptrack["album"]
|
||||
|
||||
Reference in New Issue
Block a user