mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
some bug fixes
- watch route params instead of route object in folderview - move to script setup on album view - use album as a reactive object instead of refs - use axios instead of fetch to get album data - improve clickable areas on songItem - move album requests to POST
This commit is contained in:
+21
-14
@@ -1,9 +1,11 @@
|
||||
from crypt import methods
|
||||
import os
|
||||
from pprint import pprint
|
||||
import urllib
|
||||
from typing import List
|
||||
from flask import Blueprint, request, send_file
|
||||
from app import functions, instances, helpers, cache
|
||||
|
||||
from app import functions, instances, helpers, cache, models
|
||||
|
||||
bp = Blueprint("api", __name__, url_prefix="")
|
||||
|
||||
@@ -30,21 +32,21 @@ def say_hi():
|
||||
return "^ _ ^"
|
||||
|
||||
|
||||
def get_tracks(query: str) -> List:
|
||||
def get_tracks(query: str) -> List[models.Track]:
|
||||
"""
|
||||
Gets all songs with a given title.
|
||||
"""
|
||||
return [track for track in all_the_f_music if query.lower() in track.title.lower()]
|
||||
|
||||
|
||||
def get_search_albums(query: str) -> List:
|
||||
def get_search_albums(query: str) -> List[models.Track]:
|
||||
"""
|
||||
Gets all songs with a given album.
|
||||
"""
|
||||
return [track for track in all_the_f_music if query.lower() in track.album.lower()]
|
||||
|
||||
|
||||
def get_artists(artist: str) -> List:
|
||||
def get_artists(artist: str) -> List[models.Track]:
|
||||
"""
|
||||
Gets all songs with a given artist.
|
||||
"""
|
||||
@@ -151,12 +153,13 @@ def find_tracks():
|
||||
return "🎸"
|
||||
|
||||
|
||||
@bp.route("/album/<album>/<artist>/artists")
|
||||
@cache.cached()
|
||||
def get_albumartists(album, artist):
|
||||
@bp.route("/album/artists", methods=["POST"])
|
||||
def get_albumartists():
|
||||
"""Returns a list of artists featured in a given album."""
|
||||
album = album.replace("|", "/")
|
||||
artist = artist.replace("|", "/")
|
||||
data = request.get_json()
|
||||
|
||||
album = data["album"]
|
||||
artist = data["artist"]
|
||||
|
||||
tracks = []
|
||||
|
||||
@@ -292,20 +295,24 @@ def get_albums():
|
||||
return {"albums": albums}
|
||||
|
||||
|
||||
@bp.route("/album/<title>/<artist>/tracks")
|
||||
@cache.cached()
|
||||
def get_album_tracks(title: str, artist: str):
|
||||
@bp.route("/album/tracks", methods=["POST"])
|
||||
def get_album_tracks():
|
||||
"""Returns all the tracks in the given album."""
|
||||
data = request.get_json()
|
||||
|
||||
album = data["album"]
|
||||
artist = data["artist"]
|
||||
|
||||
songs = []
|
||||
|
||||
for track in all_the_f_music:
|
||||
if track.albumartist == artist and track.album == title:
|
||||
if track.albumartist == artist and track.album == album:
|
||||
songs.append(track)
|
||||
|
||||
songs = helpers.remove_duplicates(songs)
|
||||
|
||||
album_obj = {
|
||||
"name": title,
|
||||
"name": album,
|
||||
"count": len(songs),
|
||||
"duration": "56 Minutes",
|
||||
"image": songs[0].image,
|
||||
|
||||
+36
-20
@@ -7,6 +7,7 @@ import threading
|
||||
import time
|
||||
from typing import List
|
||||
import requests
|
||||
import colorgram
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
@@ -15,9 +16,10 @@ from PIL import Image
|
||||
from app import instances
|
||||
from app import functions
|
||||
from app import watchdoge
|
||||
from app import models
|
||||
|
||||
home_dir = os.path.expanduser('~') + '/'
|
||||
app_dir = os.path.join(home_dir, '.musicx')
|
||||
home_dir = os.path.expanduser("~") + "/"
|
||||
app_dir = os.path.join(home_dir, ".musicx")
|
||||
LAST_FM_API_KEY = "762db7a44a9e6fb5585661f5f2bdf23a"
|
||||
|
||||
|
||||
@@ -63,7 +65,7 @@ def run_fast_scandir(_dir: str, ext: list):
|
||||
files = []
|
||||
|
||||
for f in os.scandir(_dir):
|
||||
if f.is_dir() and not f.name.startswith('.'):
|
||||
if f.is_dir() and not f.name.startswith("."):
|
||||
subfolders.append(f.path)
|
||||
if f.is_file():
|
||||
if os.path.splitext(f.name)[1].lower() in ext:
|
||||
@@ -77,24 +79,26 @@ def run_fast_scandir(_dir: str, ext: list):
|
||||
return subfolders, files
|
||||
|
||||
|
||||
def remove_duplicates(array: list) -> list:
|
||||
def remove_duplicates(tracklist: List[models.Track]) -> List[models.Track]:
|
||||
"""
|
||||
Removes duplicates from a list. Returns a list without duplicates.
|
||||
"""
|
||||
|
||||
song_num = 0
|
||||
|
||||
while song_num < len(array) - 1:
|
||||
for index, song in enumerate(array):
|
||||
if array[song_num].title == song.title and \
|
||||
array[song_num].album == song.album and \
|
||||
array[song_num].artists == song.artists and \
|
||||
index != song_num:
|
||||
array.remove(song)
|
||||
while song_num < len(tracklist) - 1:
|
||||
for index, song in enumerate(tracklist):
|
||||
if (
|
||||
tracklist[song_num].title == song.title
|
||||
and tracklist[song_num].album == song.album
|
||||
and tracklist[song_num].artists == song.artists
|
||||
and index != song_num
|
||||
):
|
||||
tracklist.remove(song)
|
||||
|
||||
song_num += 1
|
||||
|
||||
return array
|
||||
return tracklist
|
||||
|
||||
|
||||
def save_image(url: str, path: str) -> None:
|
||||
@@ -104,7 +108,7 @@ def save_image(url: str, path: str) -> None:
|
||||
|
||||
response = requests.get(url)
|
||||
img = Image.open(BytesIO(response.content))
|
||||
img.save(path, 'JPEG')
|
||||
img.save(path, "JPEG")
|
||||
|
||||
|
||||
def is_valid_file(filename: str) -> bool:
|
||||
@@ -112,7 +116,7 @@ def is_valid_file(filename: str) -> bool:
|
||||
Checks if a file is valid. Returns True if it is, False if it isn't.
|
||||
"""
|
||||
|
||||
if filename.endswith('.flac') or filename.endswith('.mp3'):
|
||||
if filename.endswith(".flac") or filename.endswith(".mp3"):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -123,11 +127,10 @@ def create_config_dir() -> None:
|
||||
Creates the config directory if it doesn't exist.
|
||||
"""
|
||||
|
||||
_home_dir = os.path.expanduser('~')
|
||||
_home_dir = os.path.expanduser("~")
|
||||
config_folder = os.path.join(_home_dir, app_dir)
|
||||
|
||||
dirs = ["", "images", "images/defaults",
|
||||
"images/artists", "images/thumbnails"]
|
||||
dirs = ["", "images", "images/defaults", "images/artists", "images/thumbnails"]
|
||||
|
||||
for _dir in dirs:
|
||||
path = os.path.join(config_folder, _dir)
|
||||
@@ -140,19 +143,32 @@ def create_config_dir() -> None:
|
||||
os.chmod(path, 0o755)
|
||||
|
||||
|
||||
def get_all_songs() -> List:
|
||||
def get_all_songs() -> List[models.Track]:
|
||||
"""
|
||||
Gets all songs under the ~/ directory.
|
||||
"""
|
||||
print("Getting all songs...")
|
||||
tracks = []
|
||||
|
||||
tracks: list[models.Track] = []
|
||||
|
||||
for track in instances.songs_instance.get_all_songs():
|
||||
try:
|
||||
os.chmod(os.path.join(track["filepath"]), 0o755)
|
||||
except FileNotFoundError:
|
||||
instances.songs_instance.remove_song_by_filepath(track['filepath'])
|
||||
instances.songs_instance.remove_song_by_filepath(track["filepath"])
|
||||
|
||||
tracks.append(functions.create_track_class(track))
|
||||
|
||||
return tracks
|
||||
|
||||
|
||||
def extract_colors(image) -> list:
|
||||
colors = sorted(colorgram.extract(image, 2), key=lambda c: c.hsl.h)
|
||||
|
||||
formatted_colors = []
|
||||
|
||||
for color in colors:
|
||||
color = f"rgb({color.rgb.r}, {color.rgb.g}, {color.rgb.b})"
|
||||
formatted_colors.append(color)
|
||||
|
||||
return formatted_colors
|
||||
|
||||
Generated
+16
-1
@@ -36,6 +36,17 @@ category = "main"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
|
||||
[[package]]
|
||||
name = "colorgram.py"
|
||||
version = "1.2.0"
|
||||
description = "A Python module for extracting colors from images. Get a palette of any picture!"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[package.dependencies]
|
||||
pillow = ">=3.3.1"
|
||||
|
||||
[[package]]
|
||||
name = "flask"
|
||||
version = "2.0.2"
|
||||
@@ -234,7 +245,7 @@ watchdog = ["watchdog"]
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.8"
|
||||
content-hash = "43a8f1b3d32df323e4836559445b061c5ef7540471f75ffb3365b683e953f760"
|
||||
content-hash = "c5fb66888aa3ddc0828c3c7794409039ada460ab96b3f824fd76caa85e27fbfb"
|
||||
|
||||
[metadata.files]
|
||||
certifi = [
|
||||
@@ -253,6 +264,10 @@ colorama = [
|
||||
{file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
|
||||
{file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"},
|
||||
]
|
||||
"colorgram.py" = [
|
||||
{file = "colorgram.py-1.2.0-py2.py3-none-any.whl", hash = "sha256:e990769fa6df7261a450c7d5bef3a1a062f09ba1214bff67b4d6f02970a1a27b"},
|
||||
{file = "colorgram.py-1.2.0.tar.gz", hash = "sha256:e77766a5f9de7207bdef8f1c22a702cbf09630eae3bc46a450b9d9f12a7bfdbf"},
|
||||
]
|
||||
flask = [
|
||||
{file = "Flask-2.0.2-py3-none-any.whl", hash = "sha256:cb90f62f1d8e4dc4621f52106613488b5ba826b2e1e10a33eac92f723093ab6a"},
|
||||
{file = "Flask-2.0.2.tar.gz", hash = "sha256:7b2fb8e934ddd50731893bdcdb00fc8c0315916f9fcd50d22c7cc1a95ab634e2"},
|
||||
|
||||
@@ -16,6 +16,7 @@ progress = "^1.6"
|
||||
gunicorn = "^20.1.0"
|
||||
Pillow = "^9.0.1"
|
||||
Flask-Caching = "^1.10.1"
|
||||
"colorgram.py" = "^1.2.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user