mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
fix watchdoge.py add_track()
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import urllib
|
||||
from typing import List
|
||||
from app import models, functions, helpers
|
||||
from app import trackslib, api
|
||||
@@ -44,6 +45,37 @@ def get_album_image(album: list) -> str:
|
||||
return functions.use_defaults()
|
||||
|
||||
|
||||
def get_album_tracks(album: str, artist: str) -> List:
|
||||
return [
|
||||
track
|
||||
for track in api.DB_TRACKS
|
||||
if track["album"] == album and track["albumartist"] == artist
|
||||
]
|
||||
|
||||
|
||||
def create_album(track) -> models.Album:
|
||||
"""
|
||||
Generates and returns an album object from a track object.
|
||||
"""
|
||||
album = {
|
||||
"album": track["album"],
|
||||
"artist": track["albumartist"],
|
||||
}
|
||||
|
||||
album_tracks = get_album_tracks(album["album"], album["artist"])
|
||||
|
||||
album["count"] = len(album_tracks)
|
||||
album["duration"] = get_album_duration(album_tracks)
|
||||
album["date"] = album_tracks[0]["date"]
|
||||
album["artistimage"] = urllib.parse.quote_plus(
|
||||
album_tracks[0]["albumartist"] + ".webp"
|
||||
)
|
||||
|
||||
album["image"] = get_album_image(album_tracks)
|
||||
|
||||
return models.Album(album)
|
||||
|
||||
|
||||
def find_album(albumtitle, artist):
|
||||
for album in api.ALBUMS:
|
||||
if album.album == albumtitle and album.artist == artist:
|
||||
|
||||
+4
-4
@@ -10,11 +10,13 @@ from app import trackslib
|
||||
bp = Blueprint("api", __name__, url_prefix="")
|
||||
functions.start_watchdog()
|
||||
|
||||
DB_TRACKS = instances.songs_instance.get_all_songs()
|
||||
ALBUMS: List[models.Album] = []
|
||||
TRACKS: List[models.Track] = []
|
||||
|
||||
home_dir = helpers.home_dir
|
||||
|
||||
|
||||
@helpers.background
|
||||
def initialize() -> None:
|
||||
"""
|
||||
@@ -201,7 +203,7 @@ def get_artist_data(artist: str):
|
||||
|
||||
|
||||
@bp.route("/f/<folder>")
|
||||
@cache.cached()
|
||||
# @cache.cached()
|
||||
def get_folder_tree(folder: str):
|
||||
"""
|
||||
Returns a list of all the folders and tracks in the given folder.
|
||||
@@ -251,11 +253,9 @@ def get_folder_tree(folder: str):
|
||||
@bp.route("/albums")
|
||||
def get_albums():
|
||||
"""returns all the albums"""
|
||||
s = instances.songs_instance.get_all_songs()
|
||||
|
||||
albums = []
|
||||
|
||||
for song in s:
|
||||
for song in DB_TRACKS:
|
||||
al_obj = {"name": song["album"], "artist": song["artists"]}
|
||||
|
||||
if al_obj not in albums:
|
||||
|
||||
+10
-37
@@ -100,11 +100,9 @@ def fetch_image_path(artist: str) -> str or None:
|
||||
def populate_images():
|
||||
"""populates the artists images"""
|
||||
|
||||
all_songs = instances.songs_instance.get_all_songs()
|
||||
|
||||
artists = []
|
||||
|
||||
for song in all_songs:
|
||||
for song in api.DB_TRACKS:
|
||||
this_artists = song["artists"].split(", ")
|
||||
|
||||
for artist in this_artists:
|
||||
@@ -170,10 +168,9 @@ def return_album_art(filepath):
|
||||
|
||||
|
||||
def save_t_colors():
|
||||
tracks = instances.songs_instance.get_all_songs()
|
||||
_bar = Bar("Processing image colors", max=len(tracks))
|
||||
_bar = Bar("Processing image colors", max=len(api.DB_TRACKS))
|
||||
|
||||
for track in tracks:
|
||||
for track in api.DB_TRACKS:
|
||||
filepath = track["filepath"]
|
||||
album_art = return_album_art(filepath)
|
||||
|
||||
@@ -366,38 +363,14 @@ def get_album_bio(title: str, albumartist: str):
|
||||
|
||||
|
||||
def get_all_albums() -> List[models.Album]:
|
||||
"""
|
||||
Returns a list of album objects for all albums in the database.
|
||||
"""
|
||||
print("processing albums started ...")
|
||||
|
||||
all_tracks = instances.songs_instance.get_all_songs()
|
||||
album_dicts = []
|
||||
albums = []
|
||||
albums: List[models.Album] = []
|
||||
|
||||
for track in all_tracks:
|
||||
album_dict = {
|
||||
"album": track["album"],
|
||||
"artist": track["albumartist"],
|
||||
}
|
||||
for track in api.DB_TRACKS:
|
||||
albums.append(albumslib.create_album(track))
|
||||
|
||||
if album_dict not in album_dicts:
|
||||
album_dicts.append(album_dict)
|
||||
|
||||
for album in album_dicts:
|
||||
album_tracks = [
|
||||
track
|
||||
for track in all_tracks
|
||||
if track["album"] == album["album"]
|
||||
and track["albumartist"] == album["artist"]
|
||||
]
|
||||
|
||||
album["count"] = len(album_tracks)
|
||||
album["duration"] = albumslib.get_album_duration(album_tracks)
|
||||
album["date"] = album_tracks[0]["date"]
|
||||
album["artistimage"] = urllib.parse.quote_plus(
|
||||
album_tracks[0]["albumartist"] + ".webp"
|
||||
)
|
||||
|
||||
album["image"] = albumslib.get_album_image(album_tracks)
|
||||
|
||||
albums.append(album)
|
||||
|
||||
return [models.Album(album) for album in albums]
|
||||
return albums
|
||||
|
||||
@@ -334,5 +334,5 @@ class Album:
|
||||
self.count = tags["count"]
|
||||
self.duration = tags["duration"]
|
||||
self.date = tags["date"]
|
||||
self.artistimage = "http://127.0.0.1:8900/images/artists/" + tags["artistimage"]
|
||||
self.image = "http://127.0.0.1:8900/images/thumbnails/" + tags["image"]
|
||||
self.artistimage = "http://0.0.0.0:8900/images/artists/" + tags["artistimage"]
|
||||
self.image = "http://0.0.0.0:8900/images/thumbnails/" + tags["image"]
|
||||
|
||||
@@ -12,17 +12,13 @@ def create_all_tracks() -> List[models.Track]:
|
||||
print("Getting all songs...")
|
||||
tracks: list[models.Track] = []
|
||||
|
||||
for track in instances.songs_instance.get_all_songs():
|
||||
# print(track)
|
||||
# print(albumslib.ALBUMS)
|
||||
for track in api.DB_TRACKS:
|
||||
try:
|
||||
os.chmod(track["filepath"], 0o755)
|
||||
except FileNotFoundError:
|
||||
instances.songs_instance.remove_song_by_filepath(track["filepath"])
|
||||
|
||||
album = albumslib.find_album(track["album"], track["albumartist"])
|
||||
# print(album)
|
||||
# print(track["album"], track["albumartist"])
|
||||
|
||||
track["image"] = album.image
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from watchdog.events import PatternMatchingEventHandler
|
||||
|
||||
from app import instances, functions
|
||||
from app import api, models
|
||||
from app import albumslib
|
||||
|
||||
|
||||
class OnMyWatch:
|
||||
@@ -35,14 +36,18 @@ def add_track(filepath: str) -> None:
|
||||
Processes the audio tags for a given file ands add them to the music dict.
|
||||
"""
|
||||
tags = functions.get_tags(filepath)
|
||||
print(tags)
|
||||
|
||||
if tags is not None:
|
||||
instances.songs_instance.insert_song(tags)
|
||||
track_obj = instances.songs_instance.get_song_by_path(tags["filepath"])
|
||||
track = instances.songs_instance.get_song_by_path(tags["filepath"])
|
||||
|
||||
api.DB_TRACKS.append(track)
|
||||
album = albumslib.create_album(track)
|
||||
api.ALBUMS.append(album)
|
||||
|
||||
track["image"] = album.image
|
||||
api.TRACKS.append(models.Track(track))
|
||||
|
||||
track = models.Track(track_obj)
|
||||
api.TRACKS.extend(track)
|
||||
|
||||
|
||||
def remove_track(filepath: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user