misc refactors and docstrings addition

This commit is contained in:
geoffrey45
2022-03-24 00:25:00 +03:00
parent bab2228a28
commit 67c3be7d40
25 changed files with 198 additions and 186 deletions
+14 -3
View File
@@ -1,17 +1,25 @@
"""
This library contains all the functions related to tracks.
"""
import os
from typing import List
from app import models, instances
from app.lib import albumslib
from app.helpers import remove_duplicates
from app import api
from app import api, helpers
from progress.bar import Bar
def create_all_tracks() -> List[models.Track]:
"""
Gets all songs under the ~/ directory.
"""
print("Getting all songs...")
tracks: list[models.Track] = []
timer = helpers.Timer()
_bar = Bar("Creating tracks", max=len(api.DB_TRACKS))
for track in api.DB_TRACKS:
try:
os.chmod(track["filepath"], 0o755)
@@ -23,9 +31,12 @@ def create_all_tracks() -> List[models.Track]:
track["image"] = album.image
tracks.append(models.Track(track))
_bar.next()
api.TRACKS.clear()
api.TRACKS.extend(tracks)
_bar.finish()
print(f"Created all songs in {timer.stop()}")
def get_album_tracks(albumname, artist):
@@ -43,4 +54,4 @@ def get_track_by_id(trackid: str) -> models.Track:
"""Returns api track matching an id"""
for track in api.TRACKS:
if track.id == trackid:
return track
return track