mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
break down the api blueprint into smaller blueprints
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
from flask import Blueprint
|
||||
import urllib
|
||||
|
||||
from app import instances
|
||||
from app import helpers
|
||||
|
||||
artist_bp = Blueprint("artist", __name__, url_prefix="/")
|
||||
from app import cache
|
||||
|
||||
|
||||
@artist_bp.route("/artist/<artist>")
|
||||
@cache.cached()
|
||||
def get_artist_data(artist: str):
|
||||
"""Returns the artist's data, tracks and albums"""
|
||||
artist = urllib.parse.unquote(artist)
|
||||
artist_obj = instances.artist_instance.get_artists_by_name(artist)
|
||||
|
||||
def get_artist_tracks():
|
||||
songs = instances.songs_instance.find_songs_by_artist(artist)
|
||||
|
||||
return songs
|
||||
|
||||
artist_songs = get_artist_tracks()
|
||||
songs = helpers.remove_duplicates(artist_songs)
|
||||
|
||||
def get_artist_albums():
|
||||
artist_albums = []
|
||||
albums_with_count = []
|
||||
|
||||
albums = instances.songs_instance.find_songs_by_albumartist(artist)
|
||||
|
||||
for song in albums:
|
||||
if song["album"] not in artist_albums:
|
||||
artist_albums.append(song["album"])
|
||||
|
||||
for album in artist_albums:
|
||||
count = 0
|
||||
length = 0
|
||||
|
||||
for song in artist_songs:
|
||||
if song["album"] == album:
|
||||
count = count + 1
|
||||
length = length + song["length"]
|
||||
|
||||
album_ = {"title": album, "count": count, "length": length}
|
||||
|
||||
albums_with_count.append(album_)
|
||||
|
||||
return albums_with_count
|
||||
|
||||
return {"artist": artist_obj, "songs": songs, "albums": get_artist_albums()}
|
||||
Reference in New Issue
Block a user