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
+3
View File
@@ -0,0 +1,3 @@
"""
This module contains all the data processing and non-API libraries
"""
+4 -2
View File
@@ -1,3 +1,7 @@
"""
This library contains all the functions related to albums.
"""
import urllib
from typing import List
from app import models, functions, helpers
@@ -5,7 +9,6 @@ from app.lib import trackslib
from app import api
@helpers.background
def create_everything() -> List[models.Track]:
"""
Creates album objects for all albums and returns
@@ -18,7 +21,6 @@ def create_everything() -> List[models.Track]:
trackslib.create_all_tracks()
def get_album_duration(album: list) -> int:
"""
Gets the duration of an album.
+4 -2
View File
@@ -1,3 +1,7 @@
"""
This library contains all the functions related to playlists.
"""
from app import api, instances, models
from app.lib import trackslib
@@ -14,8 +18,6 @@ def add_track(playlistid: str, trackid: str):
instances.playlist_instance.add_track_to_playlist(playlistid, track)
def create_all_playlists():
"""
Gets all playlists from the database.
+4
View File
@@ -1,3 +1,7 @@
"""
This library contains all the functions related to the search functionality.
"""
from typing import List
from app import models, helpers
from app.lib import albumslib
+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