mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-07 19:55:40 +00:00
Restyle Remove global lists and read everything from the database. (#71)
This commit is contained in:
parent
73891aa5cf
commit
e77f2b9f2b
@ -3,7 +3,6 @@ This module contains all the Flask Blueprints and API routes. It also contains a
|
|||||||
that are used through-out the app. It handles the initialization of the watchdog,
|
that are used through-out the app. It handles the initialization of the watchdog,
|
||||||
checking and creating config dirs and starting the re-indexing process using a background thread.
|
checking and creating config dirs and starting the re-indexing process using a background thread.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from app import functions
|
from app import functions
|
||||||
from app import helpers
|
from app import helpers
|
||||||
from app import prep
|
from app import prep
|
||||||
|
@ -10,7 +10,6 @@ from flask import Blueprint
|
|||||||
|
|
||||||
artist_bp = Blueprint("artist", __name__, url_prefix="/")
|
artist_bp = Blueprint("artist", __name__, url_prefix="/")
|
||||||
|
|
||||||
|
|
||||||
# @artist_bp.route("/artist/<artist>")
|
# @artist_bp.route("/artist/<artist>")
|
||||||
# @cache.cached()
|
# @cache.cached()
|
||||||
# def get_artist_data(artist: str):
|
# def get_artist_data(artist: str):
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
This file contains the Playlists class for interacting with the playlist documents in MongoDB.
|
This file contains the Playlists class for interacting with the playlist documents in MongoDB.
|
||||||
"""
|
"""
|
||||||
|
from app import helpers
|
||||||
from app.db.mongodb import convert_many
|
from app.db.mongodb import convert_many
|
||||||
from app.db.mongodb import convert_one
|
from app.db.mongodb import convert_one
|
||||||
from app.db.mongodb import MongoPlaylists
|
from app.db.mongodb import MongoPlaylists
|
||||||
from app import helpers
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
|
|
||||||
@ -18,8 +18,12 @@ class Playlists(MongoPlaylists):
|
|||||||
Inserts a new playlist object into the database.
|
Inserts a new playlist object into the database.
|
||||||
"""
|
"""
|
||||||
return self.collection.update_one(
|
return self.collection.update_one(
|
||||||
{"name": playlist["name"]},
|
{
|
||||||
{"$set": playlist},
|
"name": playlist["name"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$set": playlist
|
||||||
|
},
|
||||||
upsert=True,
|
upsert=True,
|
||||||
).upserted_id
|
).upserted_id
|
||||||
|
|
||||||
@ -45,7 +49,9 @@ class Playlists(MongoPlaylists):
|
|||||||
|
|
||||||
return self.collection.update_one(
|
return self.collection.update_one(
|
||||||
{"_id": ObjectId(playlistid)},
|
{"_id": ObjectId(playlistid)},
|
||||||
{"$set": {"lastUpdated": date}},
|
{"$set": {
|
||||||
|
"lastUpdated": date
|
||||||
|
}},
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_track_to_playlist(self, playlistid: str, track: dict) -> None:
|
def add_track_to_playlist(self, playlistid: str, track: dict) -> None:
|
||||||
@ -56,7 +62,9 @@ class Playlists(MongoPlaylists):
|
|||||||
{
|
{
|
||||||
"_id": ObjectId(playlistid),
|
"_id": ObjectId(playlistid),
|
||||||
},
|
},
|
||||||
{"$push": {"pre_tracks": track}},
|
{"$push": {
|
||||||
|
"pre_tracks": track
|
||||||
|
}},
|
||||||
)
|
)
|
||||||
self.set_last_updated(playlistid)
|
self.set_last_updated(playlistid)
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
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.
|
||||||
"""
|
"""
|
||||||
import pymongo
|
import pymongo
|
||||||
from app.db.mongodb import MongoTracks, convert_many, convert_one
|
from app.db.mongodb import convert_many
|
||||||
|
from app.db.mongodb import convert_one
|
||||||
|
from app.db.mongodb import MongoTracks
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
|
|
||||||
@ -18,9 +20,12 @@ class Tracks(MongoTracks):
|
|||||||
"""
|
"""
|
||||||
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 insert_many(self, songs: list):
|
def insert_many(self, songs: list):
|
||||||
"""
|
"""
|
||||||
@ -52,21 +57,33 @@ class Tracks(MongoTracks):
|
|||||||
"""
|
"""
|
||||||
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:
|
||||||
@ -80,7 +97,9 @@ class Tracks(MongoTracks):
|
|||||||
"""
|
"""
|
||||||
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", pymongo.ASCENDING)
|
songs = self.collection.find({
|
||||||
|
"folder": query
|
||||||
|
}).sort("title", pymongo.ASCENDING)
|
||||||
return convert_many(songs)
|
return convert_many(songs)
|
||||||
|
|
||||||
def find_songs_by_filenames(self, filenames: list) -> list:
|
def find_songs_by_filenames(self, filenames: list) -> list:
|
||||||
@ -102,8 +121,10 @@ class Tracks(MongoTracks):
|
|||||||
Returns a list of all the tracks matching the path in the query params.
|
Returns a list of all the tracks matching the path in the query params.
|
||||||
"""
|
"""
|
||||||
return self.collection.count_documents(
|
return self.collection.count_documents(
|
||||||
{"filepath": {"$regex": f"^{path}", "$options": "i"}}
|
{"filepath": {
|
||||||
)
|
"$regex": f"^{path}",
|
||||||
|
"$options": "i"
|
||||||
|
}})
|
||||||
|
|
||||||
def find_songs_by_artist(self, query: str) -> list:
|
def find_songs_by_artist(self, query: str) -> list:
|
||||||
"""
|
"""
|
||||||
@ -117,8 +138,10 @@ class Tracks(MongoTracks):
|
|||||||
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:
|
||||||
@ -155,13 +178,14 @@ class Tracks(MongoTracks):
|
|||||||
songs = self.collection.find({"albumhash": hash})
|
songs = self.collection.find({"albumhash": hash})
|
||||||
return convert_many(songs)
|
return convert_many(songs)
|
||||||
|
|
||||||
def find_track_by_title_artists_album(
|
def find_track_by_title_artists_album(self, title: str, artist: str,
|
||||||
self, title: str, artist: str, album: str
|
album: str) -> dict:
|
||||||
) -> dict:
|
|
||||||
"""
|
"""
|
||||||
Returns a single track matching the title, artist, and album in the query params.
|
Returns a single track matching the title, artist, and album in the query params.
|
||||||
"""
|
"""
|
||||||
song = self.collection.find_one(
|
song = self.collection.find_one({
|
||||||
{"title": title, "artists": artist, "album": album}
|
"title": title,
|
||||||
)
|
"artists": artist,
|
||||||
|
"album": album
|
||||||
|
})
|
||||||
return convert_one(song)
|
return convert_one(song)
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
|
import time
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from os import scandir
|
from os import scandir
|
||||||
import time
|
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
|
|
||||||
from app.models import Folder
|
|
||||||
from app.models import Track
|
|
||||||
|
|
||||||
from app import instances
|
from app import instances
|
||||||
|
from app.models import Folder
|
||||||
|
from app.models import Track
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -27,10 +26,14 @@ def get_folder_track_count(path: str) -> int:
|
|||||||
def create_folder(dir: Dir) -> Folder:
|
def create_folder(dir: Dir) -> Folder:
|
||||||
"""Create a single Folder object"""
|
"""Create a single Folder object"""
|
||||||
folder = {
|
folder = {
|
||||||
"name": dir.path.split("/")[-1],
|
"name":
|
||||||
"path": dir.path,
|
dir.path.split("/")[-1],
|
||||||
"is_sym": dir.is_sym,
|
"path":
|
||||||
"trackcount": instances.tracks_instance.find_tracks_inside_path_regex(dir.path),
|
dir.path,
|
||||||
|
"is_sym":
|
||||||
|
dir.is_sym,
|
||||||
|
"trackcount":
|
||||||
|
instances.tracks_instance.find_tracks_inside_path_regex(dir.path),
|
||||||
}
|
}
|
||||||
|
|
||||||
return Folder(folder)
|
return Folder(folder)
|
||||||
|
@ -11,14 +11,13 @@ from app import exceptions
|
|||||||
from app import instances
|
from app import instances
|
||||||
from app import models
|
from app import models
|
||||||
from app import settings
|
from app import settings
|
||||||
|
from app.helpers import Get
|
||||||
|
from app.lib import trackslib
|
||||||
|
from app.logger import get_logger
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import ImageSequence
|
from PIL import ImageSequence
|
||||||
from werkzeug import datastructures
|
from werkzeug import datastructures
|
||||||
|
|
||||||
from app.lib import trackslib
|
|
||||||
from app.helpers import Get
|
|
||||||
from app.logger import get_logger
|
|
||||||
|
|
||||||
TrackExistsInPlaylist = exceptions.TrackExistsInPlaylist
|
TrackExistsInPlaylist = exceptions.TrackExistsInPlaylist
|
||||||
|
|
||||||
logg = get_logger()
|
logg = get_logger()
|
||||||
@ -53,7 +52,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
|
||||||
|
|
||||||
@ -71,11 +71,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 = []
|
||||||
|
@ -22,5 +22,4 @@ def validate_tracks() -> None:
|
|||||||
|
|
||||||
def get_p_track(ptrack):
|
def get_p_track(ptrack):
|
||||||
return instances.tracks_instance.find_track_by_title_artists_album(
|
return instances.tracks_instance.find_track_by_title_artists_album(
|
||||||
ptrack["title"], ptrack["artists"], ptrack["album"]
|
ptrack["title"], ptrack["artists"], ptrack["album"])
|
||||||
)
|
|
||||||
|
@ -11,13 +11,11 @@ class CopyFiles:
|
|||||||
"""Copies assets to the app directory."""
|
"""Copies assets to the app directory."""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
files = [
|
files = [{
|
||||||
{
|
"src": "assets",
|
||||||
"src": "assets",
|
"dest": os.path.join(settings.APP_DIR, "assets"),
|
||||||
"dest": os.path.join(settings.APP_DIR, "assets"),
|
"is_dir": True,
|
||||||
"is_dir": True,
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
for entry in files:
|
for entry in files:
|
||||||
src = os.path.join(os.getcwd(), entry["src"])
|
src = os.path.join(os.getcwd(), entry["src"])
|
||||||
@ -26,9 +24,7 @@ class CopyFiles:
|
|||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
src,
|
src,
|
||||||
entry["dest"],
|
entry["dest"],
|
||||||
ignore=shutil.ignore_patterns(
|
ignore=shutil.ignore_patterns("*.pyc", ),
|
||||||
"*.pyc",
|
|
||||||
),
|
|
||||||
copy_function=shutil.copy2,
|
copy_function=shutil.copy2,
|
||||||
dirs_exist_ok=True,
|
dirs_exist_ok=True,
|
||||||
)
|
)
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
import { createRouter, createWebHashHistory } from "vue-router";
|
import state from "@/composables/state";
|
||||||
import Home from "@/views/Home.vue";
|
import useAStore from "@/stores/pages/album";
|
||||||
import FolderView from "@/views/FolderView.vue";
|
import useFStore from "@/stores/pages/folder";
|
||||||
import PlaylistView from "@/views/PlaylistView.vue";
|
import usePTrackStore from "@/stores/pages/playlist";
|
||||||
import Playlists from "@/views/Playlists.vue";
|
import usePStore from "@/stores/pages/playlists";
|
||||||
|
|
||||||
import AlbumsExplorer from "@/views/AlbumsExplorer.vue";
|
import AlbumsExplorer from "@/views/AlbumsExplorer.vue";
|
||||||
import AlbumView from "@/views/AlbumView.vue";
|
import AlbumView from "@/views/AlbumView.vue";
|
||||||
|
|
||||||
import ArtistsExplorer from "@/views/ArtistsExplorer.vue";
|
import ArtistsExplorer from "@/views/ArtistsExplorer.vue";
|
||||||
|
import FolderView from "@/views/FolderView.vue";
|
||||||
|
import Home from "@/views/Home.vue";
|
||||||
|
import Playlists from "@/views/Playlists.vue";
|
||||||
|
import PlaylistView from "@/views/PlaylistView.vue";
|
||||||
import SettingsView from "@/views/SettingsView.vue";
|
import SettingsView from "@/views/SettingsView.vue";
|
||||||
|
import { createRouter, createWebHashHistory } from "vue-router";
|
||||||
import usePStore from "@/stores/pages/playlists";
|
|
||||||
import usePTrackStore from "@/stores/pages/playlist";
|
|
||||||
import useFStore from "@/stores/pages/folder";
|
|
||||||
import useAStore from "@/stores/pages/album";
|
|
||||||
import state from "@/composables/state";
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
|
4
todo
4
todo
@ -7,7 +7,7 @@
|
|||||||
- [ ] Add and deploy demo branch
|
- [ ] Add and deploy demo branch
|
||||||
|
|
||||||
### Client
|
### Client
|
||||||
- [ ] Add processes tab to show running tasks, eg. when tagging files. I have no idea on how to go about it so far. Web sockets?
|
- [ ] Add processes tab to show running tasks, eg. when tagging files. I have no idea on how to go about it so far. Web sockets?
|
||||||
- [ ] Responsiveness, especially the track list.
|
- [ ] Responsiveness, especially the track list.
|
||||||
- [ ] Make dummy buttons functional.
|
- [ ] Make dummy buttons functional.
|
||||||
- [ ] Add settings page (or modal)
|
- [ ] Add settings page (or modal)
|
||||||
@ -21,4 +21,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
- Resolve album page using albumhash instead of album title and artist
|
- Resolve album page using albumhash instead of album title and artist
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { defineConfig } from "vite";
|
|
||||||
import svgLoader from 'vite-svg-loader'
|
|
||||||
import vue from "@vitejs/plugin-vue";
|
import vue from "@vitejs/plugin-vue";
|
||||||
|
import { defineConfig } from "vite";
|
||||||
|
import svgLoader from "vite-svg-loader";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user