mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
Save complete tracks and albums to the db for faster startup
- refactor function locations - add logger - check for new tracks instead of re-processing all files
This commit is contained in:
@@ -13,13 +13,13 @@ from app.lib import folderslib
|
||||
from app.lib import playlistlib
|
||||
|
||||
|
||||
PRE_TRACKS = instances.songs_instance.get_all_songs()
|
||||
DB_TRACKS = instances.tracks_instance.get_all_tracks()
|
||||
VALID_FOLDERS: Set[str] = set()
|
||||
|
||||
ALBUMS: List[models.Album] = []
|
||||
TRACKS: List[models.Track] = []
|
||||
PLAYLISTS: List[models.Playlist] = []
|
||||
FOLDERS: List[models.Folder] = []
|
||||
FOLDERS: Set[models.Folder] = set()
|
||||
|
||||
|
||||
@helpers.background
|
||||
|
||||
@@ -23,7 +23,7 @@ def get_albums():
|
||||
"""returns all the albums"""
|
||||
albums = []
|
||||
|
||||
for song in api.PRE_TRACKS:
|
||||
for song in api.DB_TRACKS:
|
||||
al_obj = {"name": song["album"], "artist": song["artists"]}
|
||||
|
||||
if al_obj not in albums:
|
||||
@@ -41,7 +41,8 @@ def get_album_tracks():
|
||||
artist = data["artist"]
|
||||
|
||||
songs = trackslib.get_album_tracks(album, artist)
|
||||
album = albumslib.find_album(album, artist)
|
||||
index = albumslib.find_album(album, artist)
|
||||
album = api.ALBUMS[index]
|
||||
|
||||
return {"songs": songs, "info": album}
|
||||
|
||||
@@ -50,9 +51,8 @@ def get_album_tracks():
|
||||
def get_album_bio():
|
||||
"""Returns the album bio for the given album."""
|
||||
data = request.get_json()
|
||||
print(data)
|
||||
|
||||
bio = functions.get_album_bio(data["album"], data["albumartist"])
|
||||
bio = functions.fetch_album_bio(data["album"], data["albumartist"])
|
||||
|
||||
if bio is not None:
|
||||
return {"bio": bio}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import os
|
||||
import urllib
|
||||
from typing import List
|
||||
from flask import request, send_file
|
||||
|
||||
from app import functions, instances, helpers, cache, db, prep
|
||||
from app import api
|
||||
|
||||
|
||||
home_dir = helpers.home_dir
|
||||
|
||||
# @api.bp.route("/populate")
|
||||
# def find_tracks():
|
||||
# """call the populate function"""
|
||||
# functions.populate()
|
||||
# return "🎸"
|
||||
|
||||
|
||||
# @api.bp.route("/populate/images")
|
||||
# def populate_images():
|
||||
# """
|
||||
# Populates the artist images.
|
||||
# """
|
||||
# functions.populate_images()
|
||||
# return "Done"
|
||||
@@ -21,7 +21,7 @@ def get_artist_data(artist: str):
|
||||
artist_obj = instances.artist_instance.get_artists_by_name(artist)
|
||||
|
||||
def get_artist_tracks():
|
||||
songs = instances.songs_instance.find_songs_by_artist(artist)
|
||||
songs = instances.tracks_instance.find_songs_by_artist(artist)
|
||||
|
||||
return songs
|
||||
|
||||
@@ -32,7 +32,7 @@ def get_artist_data(artist: str):
|
||||
artist_albums = []
|
||||
albums_with_count = []
|
||||
|
||||
albums = instances.songs_instance.find_songs_by_albumartist(artist)
|
||||
albums = instances.tracks_instance.find_songs_by_albumartist(artist)
|
||||
|
||||
for song in albums:
|
||||
if song["album"] not in artist_albums:
|
||||
|
||||
@@ -16,7 +16,7 @@ def send_track_file(trackid):
|
||||
"""
|
||||
try:
|
||||
filepath = [
|
||||
file["filepath"] for file in api.PRE_TRACKS
|
||||
file["filepath"] for file in api.DB_TRACKS
|
||||
if file["_id"]["$oid"] == trackid
|
||||
][0]
|
||||
except (FileNotFoundError, IndexError) as e:
|
||||
@@ -31,5 +31,5 @@ def get_sample_track():
|
||||
Returns a sample track object.
|
||||
"""
|
||||
|
||||
return instances.songs_instance.get_song_by_album("Legends Never Die",
|
||||
return instances.tracks_instance.get_song_by_album("Legends Never Die",
|
||||
"Juice WRLD")
|
||||
|
||||
Reference in New Issue
Block a user