mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
major refactors
This commit is contained in:
@@ -30,7 +30,14 @@ def get_all_playlists():
|
||||
@playlist_bp.route("/playlist/new", methods=["POST"])
|
||||
def create_playlist():
|
||||
data = request.get_json()
|
||||
playlist = {"name": data["name"], "description": [], "tracks": []}
|
||||
|
||||
playlist = {
|
||||
"name": data["name"],
|
||||
"description": [],
|
||||
"tracks": [],
|
||||
"count": 0,
|
||||
"lastUpdated": 0,
|
||||
}
|
||||
|
||||
try:
|
||||
p_in_db = instances.playlist_instance.get_playlist_by_name(playlist["name"])
|
||||
|
||||
@@ -21,7 +21,7 @@ class AllSongs(db.Mongo):
|
||||
# def drop_db(self):
|
||||
# self.collection.drop()
|
||||
|
||||
def insert_song(self, song_obj: dict) -> None:
|
||||
def insert_song(self, song_obj: dict) -> str:
|
||||
"""
|
||||
Inserts a new track object into the database.
|
||||
"""
|
||||
|
||||
@@ -69,11 +69,12 @@ def populate():
|
||||
for file in files:
|
||||
tags = get_tags(file)
|
||||
|
||||
if tags not in api.PRE_TRACKS:
|
||||
api.PRE_TRACKS.append(tags)
|
||||
|
||||
if tags is not None:
|
||||
instances.songs_instance.insert_song(tags)
|
||||
upsert_id = instances.songs_instance.insert_song(tags)
|
||||
|
||||
if upsert_id is not None:
|
||||
tags["_id"] = {"$oid": upsert_id}
|
||||
api.PRE_TRACKS.append(tags)
|
||||
|
||||
_bar.next()
|
||||
_bar.finish()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
This library contains all the functions related to albums.
|
||||
"""
|
||||
|
||||
from pprint import pprint
|
||||
import urllib
|
||||
from typing import List
|
||||
from app import models, functions, helpers
|
||||
@@ -52,9 +53,12 @@ def get_album_tracks(album: str, artist: str) -> List:
|
||||
tracks = []
|
||||
|
||||
for track in api.PRE_TRACKS:
|
||||
if track["album"] == album and track["albumartist"] == artist:
|
||||
tracks.append(track)
|
||||
|
||||
try:
|
||||
if track["album"] == album and track["albumartist"] == artist:
|
||||
tracks.append(track)
|
||||
except TypeError:
|
||||
pprint(track, indent=4)
|
||||
print(album, artist)
|
||||
return tracks
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ Contains all the models for objects generation and typing.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import date
|
||||
from typing import List
|
||||
from app import api
|
||||
from app import settings
|
||||
@@ -95,6 +96,8 @@ class Playlist:
|
||||
description: str
|
||||
image: str
|
||||
tracks: List[Track]
|
||||
count: int
|
||||
lastUpdated: int
|
||||
"""A list of track objects in the playlist"""
|
||||
|
||||
def __init__(self, data):
|
||||
@@ -103,6 +106,9 @@ class Playlist:
|
||||
self.description = data["description"]
|
||||
self.image = ""
|
||||
self.tracks = create_playlist_tracks(data["tracks"])
|
||||
self.count = len(data["tracks"])
|
||||
self.lastUpdated = data["lastUpdated"]
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user