mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
try adding playlists list to context menu - unsuccsessfully
This commit is contained in:
@@ -19,13 +19,14 @@ def create_app():
|
||||
cache.init_app(app)
|
||||
|
||||
with app.app_context():
|
||||
from app.api import artist, track, search, folder, album
|
||||
from app.api import artist, track, search, folder, album, playlist
|
||||
|
||||
app.register_blueprint(album.album_bp, url_prefix="/")
|
||||
app.register_blueprint(artist.artist_bp, url_prefix="/")
|
||||
app.register_blueprint(track.track_bp, url_prefix="/")
|
||||
app.register_blueprint(search.search_bp, url_prefix="/")
|
||||
app.register_blueprint(folder.folder_bp, url_prefix="/")
|
||||
app.register_blueprint(playlist.playlist_bp, url_prefix="/")
|
||||
|
||||
|
||||
return app
|
||||
|
||||
@@ -10,6 +10,7 @@ from app import models, instances
|
||||
from app import functions, helpers, prep
|
||||
from app.lib import albumslib
|
||||
from app.lib import folderslib
|
||||
from app.lib import playlistlib
|
||||
|
||||
|
||||
DB_TRACKS = instances.songs_instance.get_all_songs()
|
||||
@@ -20,6 +21,7 @@ TRACKS: List[models.Track] = []
|
||||
PLAYLISTS: List[models.Playlist] = []
|
||||
FOLDERS: List[models.Folder] = []
|
||||
|
||||
|
||||
@helpers.background
|
||||
def initialize() -> None:
|
||||
"""
|
||||
@@ -29,8 +31,8 @@ def initialize() -> None:
|
||||
prep.create_config_dir()
|
||||
albumslib.create_everything()
|
||||
folderslib.run_scandir()
|
||||
playlistlib.create_all_playlists()
|
||||
functions.reindex_tracks()
|
||||
|
||||
|
||||
initialize()
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ def get_folder_tree():
|
||||
songs = []
|
||||
|
||||
for track in api.TRACKS:
|
||||
if track.folder + "/" == req_dir:
|
||||
if track.folder == req_dir:
|
||||
songs.append(track)
|
||||
|
||||
final_tracks = helpers.remove_duplicates(songs)
|
||||
|
||||
@@ -11,22 +11,24 @@ playlist_bp = Blueprint("playlist", __name__, url_prefix="/")
|
||||
|
||||
@playlist_bp.route("/playlists", methods=["GET"])
|
||||
def get_all_playlists():
|
||||
print(api.PLAYLISTS)
|
||||
playlists = []
|
||||
|
||||
for playlist in api.PLAYLISTS:
|
||||
del playlist.tracks
|
||||
playlist.tracks = []
|
||||
playlists.append(playlist)
|
||||
|
||||
return playlists
|
||||
return {"data": playlists}
|
||||
|
||||
|
||||
@playlist_bp.route("/playlist/new")
|
||||
@playlist_bp.route("/playlist/new", methods=["POST"])
|
||||
def create_playlist():
|
||||
data = request.get_json()
|
||||
|
||||
playlist = {"name": data["name"], "description": data["description"], "tracks": []}
|
||||
playlist = {"name": data["name"], "description": [], "tracks": []}
|
||||
|
||||
instances.playlist_instance.insert_playlist(playlist)
|
||||
return 200
|
||||
return {"msg": "success"}
|
||||
|
||||
|
||||
@playlist_bp.route("/playlist/<playlist_id>/add", methods=["POST"])
|
||||
|
||||
@@ -26,6 +26,7 @@ from app import settings, models
|
||||
from app.lib import albumslib
|
||||
from app import api
|
||||
from app.lib import watchdoge
|
||||
from app.lib import folderslib
|
||||
|
||||
|
||||
@helpers.background
|
||||
@@ -61,7 +62,6 @@ def populate():
|
||||
start = time.time()
|
||||
|
||||
s, files = helpers.run_fast_scandir(settings.HOME_DIR, [".flac", ".mp3"], full=True)
|
||||
# pprint(s)
|
||||
|
||||
_bar = Bar("Processing files", max=len(files))
|
||||
for file in files:
|
||||
@@ -74,7 +74,8 @@ def populate():
|
||||
_bar.finish()
|
||||
|
||||
albumslib.create_everything()
|
||||
|
||||
folderslib.run_scandir()
|
||||
|
||||
end = time.time()
|
||||
|
||||
print(
|
||||
@@ -340,7 +341,7 @@ def get_tags(fullpath: str) -> dict:
|
||||
"length": round(audio.info.length),
|
||||
"bitrate": round(int(audio.info.bitrate) / 1000),
|
||||
"filepath": fullpath,
|
||||
"folder": os.path.dirname(fullpath),
|
||||
"folder": os.path.dirname(fullpath) + "/",
|
||||
}
|
||||
|
||||
return tags
|
||||
|
||||
@@ -29,11 +29,11 @@ def create_folder(foldername: str) -> models.Folder:
|
||||
return models.Folder(folder)
|
||||
|
||||
|
||||
def create_all_folders(foldernames: List[str]) -> List[models.Folder]:
|
||||
def create_all_folders() -> List[models.Folder]:
|
||||
folders_: List[models.Folder] = []
|
||||
_bar = Bar("Creating folders", max=len(foldernames))
|
||||
_bar = Bar("Creating folders", max=len(api.VALID_FOLDERS))
|
||||
|
||||
for foldername in foldernames:
|
||||
for foldername in api.VALID_FOLDERS:
|
||||
folder = create_folder(foldername)
|
||||
folders_.append(folder)
|
||||
_bar.next()
|
||||
@@ -61,11 +61,17 @@ def get_subdirs(foldername: str) -> List[models.Folder]:
|
||||
|
||||
@helpers.background
|
||||
def run_scandir():
|
||||
"""
|
||||
Initiates the creation of all folder objects for each folder with a track in it.
|
||||
|
||||
Runs in a background thread after every 5 minutes.
|
||||
It calls the
|
||||
"""
|
||||
flag = False
|
||||
|
||||
while flag is False:
|
||||
get_valid_folders()
|
||||
folders_ = create_all_folders(api.VALID_FOLDERS)
|
||||
folders_ = create_all_folders()
|
||||
"""Create all the folder objects before clearing api.FOLDERS"""
|
||||
|
||||
api.FOLDERS.clear()
|
||||
|
||||
Reference in New Issue
Block a user