Restyle Integrate topbar and refactor playlists page (#31)

This commit is contained in:
restyled-io[bot]
2022-04-14 11:39:26 +03:00
committed by GitHub
parent 85c59b4cba
commit a6e46dcde2
8 changed files with 66 additions and 35 deletions
+5 -4
View File
@@ -21,7 +21,8 @@ TrackExistsInPlaylist = exceptions.TrackExistsInPlaylist
@playlist_bp.route("/playlists", methods=["GET"]) @playlist_bp.route("/playlists", methods=["GET"])
def get_all_playlists(): def get_all_playlists():
playlists = [ playlists = [
serializer.Playlist(p, construct_last_updated=False) for p in api.PLAYLISTS serializer.Playlist(p, construct_last_updated=False)
for p in api.PLAYLISTS
] ]
playlists.sort( playlists.sort(
key=lambda p: datetime.strptime(p.lastUpdated, "%Y-%m-%d %H:%M:%S"), key=lambda p: datetime.strptime(p.lastUpdated, "%Y-%m-%d %H:%M:%S"),
@@ -40,7 +41,7 @@ def create_playlist():
"pre_tracks": [], "pre_tracks": [],
"lastUpdated": data["lastUpdated"], "lastUpdated": data["lastUpdated"],
"image": "", "image": "",
"thumb": "" "thumb": "",
} }
try: try:
@@ -101,7 +102,7 @@ def update_playlist(playlistid: str):
"description": str(data.get("description").strip()), "description": str(data.get("description").strip()),
"lastUpdated": str(data.get("lastUpdated")), "lastUpdated": str(data.get("lastUpdated")),
"image": None, "image": None,
"thumb": None "thumb": None,
} }
for p in api.PLAYLISTS: for p in api.PLAYLISTS:
@@ -114,7 +115,7 @@ def update_playlist(playlistid: str):
else: else:
playlist["image"] = p.image.split("/")[-1] playlist["image"] = p.image.split("/")[-1]
playlist['thumb'] = p.thumb.split("/")[-1] playlist["thumb"] = p.thumb.split("/")[-1]
p.update_playlist(playlist) p.update_playlist(playlist)
instances.playlist_instance.update_playlist(playlistid, playlist) instances.playlist_instance.update_playlist(playlistid, playlist)
+7 -3
View File
@@ -2,7 +2,6 @@
This file contains the Album class for interacting with This file contains the Album class for interacting with
album documents in MongoDB. album documents in MongoDB.
""" """
from app import db from app import db
from bson import ObjectId from bson import ObjectId
@@ -24,8 +23,13 @@ class Albums(db.Mongo):
Inserts a new album object into the database. Inserts a new album object into the database.
""" """
return self.collection.update_one( return self.collection.update_one(
{"album": album["album"], "artist": album["artist"]}, {
{"$set": album}, "album": album["album"],
"artist": album["artist"]
},
{
"$set": album
},
upsert=True, upsert=True,
).upserted_id ).upserted_id
+4 -4
View File
@@ -1,7 +1,6 @@
""" """
This file contains the Artists class for interacting with artist documents in MongoDB. This file contains the Artists class for interacting with artist documents in MongoDB.
""" """
from app import db from app import db
from bson import ObjectId from bson import ObjectId
@@ -19,9 +18,10 @@ class Artists(db.Mongo):
""" """
Inserts an artist into the database. Inserts an artist into the database.
""" """
self.collection.update_one( self.collection.update_one(artist_obj, {
artist_obj, {"$set": artist_obj}, upsert=True "$set": artist_obj
).upserted_id },
upsert=True).upserted_id
def get_all_artists(self) -> list: def get_all_artists(self) -> list:
""" """
+6 -3
View File
@@ -1,7 +1,6 @@
""" """
This file contains the TrackColors class for interacting with Track colors documents in MongoDB. This file contains the TrackColors class for interacting with Track colors documents in MongoDB.
""" """
from app import db from app import db
@@ -19,8 +18,12 @@ class TrackColors(db.Mongo):
Inserts a new track object into the database. Inserts a new track object into the database.
""" """
return self.collection.update_one( return self.collection.update_one(
{"filepath": track_color["filepath"]}, {
{"$set": track_color}, "filepath": track_color["filepath"]
},
{
"$set": track_color
},
upsert=True, upsert=True,
).upserted_id ).upserted_id
+28 -10
View File
@@ -1,7 +1,6 @@
""" """
This file contains the AllSongs class for interacting with track documents in MongoDB. This file contains the AllSongs class for interacting with track documents in MongoDB.
""" """
from app import db from app import db
from bson import ObjectId from bson import ObjectId
@@ -25,9 +24,12 @@ class AllSongs(db.Mongo):
""" """
Inserts a new track object into the database. Inserts a new track object into the database.
""" """
return self.collection.update_one( return self.collection.update_one({
{"filepath": song_obj["filepath"]}, {"$set": song_obj}, upsert=True "filepath": song_obj["filepath"]
).upserted_id }, {
"$set": song_obj
},
upsert=True).upserted_id
def get_all_songs(self) -> list: def get_all_songs(self) -> list:
""" """
@@ -53,21 +55,33 @@ class AllSongs(db.Mongo):
""" """
Returns all the songs matching the albums in the query params (using regex). Returns all the songs matching the albums in the query params (using regex).
""" """
songs = self.collection.find({"album": {"$regex": query, "$options": "i"}}) songs = self.collection.find(
{"album": {
"$regex": query,
"$options": "i"
}})
return convert_many(songs) return convert_many(songs)
def search_songs_by_artist(self, query: str) -> list: def search_songs_by_artist(self, query: str) -> list:
""" """
Returns all the songs matching the artists in the query params. Returns all the songs matching the artists in the query params.
""" """
songs = self.collection.find({"artists": {"$regex": query, "$options": "i"}}) songs = self.collection.find(
{"artists": {
"$regex": query,
"$options": "i"
}})
return convert_many(songs) return convert_many(songs)
def find_song_by_title(self, query: str) -> list: def find_song_by_title(self, query: str) -> list:
""" """
Finds all the tracks matching the title in the query params. Finds all the tracks matching the title in the query params.
""" """
song = self.collection.find({"title": {"$regex": query, "$options": "i"}}) song = self.collection.find(
{"title": {
"$regex": query,
"$options": "i"
}})
return convert_many(song) return convert_many(song)
def find_songs_by_album(self, name: str, artist: str) -> list: def find_songs_by_album(self, name: str, artist: str) -> list:
@@ -81,7 +95,9 @@ class AllSongs(db.Mongo):
""" """
Returns a sorted list of all the tracks exactly matching the folder in the query params Returns a sorted list of all the tracks exactly matching the folder in the query params
""" """
songs = self.collection.find({"folder": query}).sort("title", db.pymongo.ASCENDING) songs = self.collection.find({
"folder": query
}).sort("title", db.pymongo.ASCENDING)
return convert_many(songs) return convert_many(songs)
def find_songs_by_folder_og(self, query: str) -> list: def find_songs_by_folder_og(self, query: str) -> list:
@@ -103,8 +119,10 @@ class AllSongs(db.Mongo):
Returns a list of all the tracks containing the albumartist in the query params. Returns a list of all the tracks containing the albumartist in the query params.
""" """
songs = self.collection.find( songs = self.collection.find(
{"albumartist": {"$regex": query, "$options": "i"}} {"albumartist": {
) "$regex": query,
"$options": "i"
}})
return convert_many(songs) return convert_many(songs)
def get_song_by_path(self, path: str) -> dict: def get_song_by_path(self, path: str) -> dict:
+4 -1
View File
@@ -1,6 +1,9 @@
import time import time
from typing import List from typing import List
from app import api, helpers, models
from app import api
from app import helpers
from app import models
from progress.bar import Bar from progress.bar import Bar
+8 -4
View File
@@ -35,7 +35,8 @@ def add_track(playlistid: str, trackid: str):
try: try:
playlist.add_track(track) playlist.add_track(track)
instances.playlist_instance.add_track_to_playlist(playlistid, track) instances.playlist_instance.add_track_to_playlist(
playlistid, track)
return return
except TrackExistsInPlaylist as error: except TrackExistsInPlaylist as error:
raise error raise error
@@ -68,7 +69,8 @@ def create_thumbnail(image: any, img_path: str) -> str:
Creates a 250 x 250 thumbnail from a playlist image Creates a 250 x 250 thumbnail from a playlist image
""" """
thumb_path = "thumb_" + img_path thumb_path = "thumb_" + img_path
full_thumb_path = os.path.join(settings.APP_DIR, "images", "playlists", thumb_path) full_thumb_path = os.path.join(settings.APP_DIR, "images", "playlists",
thumb_path)
aspect_ratio = image.width / image.height aspect_ratio = image.width / image.height
@@ -86,11 +88,13 @@ def save_p_image(file: datastructures.FileStorage, pid: str):
""" """
img = Image.open(file) img = Image.open(file)
random_str = "".join(random.choices(string.ascii_letters + string.digits, k=5)) random_str = "".join(
random.choices(string.ascii_letters + string.digits, k=5))
img_path = pid + str(random_str) + ".webp" img_path = pid + str(random_str) + ".webp"
full_img_path = os.path.join(settings.APP_DIR, "images", "playlists", img_path) full_img_path = os.path.join(settings.APP_DIR, "images", "playlists",
img_path)
if file.content_type == "image/gif": if file.content_type == "image/gif":
frames = [] frames = []
+2 -4
View File
@@ -73,11 +73,9 @@ class Album:
def get_p_track(ptrack): def get_p_track(ptrack):
for track in api.TRACKS: for track in api.TRACKS:
if ( if (track.title == ptrack["title"]
track.title == ptrack["title"]
and track.artists == ptrack["artists"] and track.artists == ptrack["artists"]
and ptrack["album"] == track.album and ptrack["album"] == track.album):
):
return track return track