mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
finalize thumbnail validators
- add logger colors
This commit is contained in:
@@ -12,6 +12,8 @@ from PIL import Image
|
|||||||
from app import helpers, settings
|
from app import helpers, settings
|
||||||
from app.lib import watchdoge
|
from app.lib import watchdoge
|
||||||
from app.lib.albumslib import ValidateThumbs
|
from app.lib.albumslib import ValidateThumbs
|
||||||
|
from app.lib import trackslib
|
||||||
|
from app.lib.populate import CreateAlbums, Populate
|
||||||
|
|
||||||
|
|
||||||
@helpers.background
|
@helpers.background
|
||||||
@@ -21,13 +23,13 @@ def run_checks():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# while True:
|
# while True:
|
||||||
# trackslib.validate_tracks()
|
trackslib.validate_tracks()
|
||||||
|
|
||||||
# Populate()
|
Populate()
|
||||||
# CreateAlbums()
|
CreateAlbums()
|
||||||
|
|
||||||
# if helpers.Ping()():
|
if helpers.Ping()():
|
||||||
# CheckArtistImages()()
|
CheckArtistImages()()
|
||||||
|
|
||||||
ValidateThumbs()
|
ValidateThumbs()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
This library contains all the functions related to albums.
|
This library contains all the functions related to albums.
|
||||||
"""
|
"""
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
@@ -80,13 +81,18 @@ class ValidateThumbs:
|
|||||||
albums = helpers.Get.get_all_albums()
|
albums = helpers.Get.get_all_albums()
|
||||||
thumbs = [(album.hash + ".webp") for album in albums]
|
thumbs = [(album.hash + ".webp") for album in albums]
|
||||||
|
|
||||||
for t in thumbs:
|
def rip_image(t_hash: str):
|
||||||
e = helpers.UseBisection(entries, "filename", [t])
|
e = helpers.UseBisection(entries, "filename", [t_hash])()[0]
|
||||||
|
|
||||||
if e is None:
|
if e is None:
|
||||||
hash = t.split(".")[0]
|
hash = t_hash.split(".")[0]
|
||||||
RipAlbumImage(hash)
|
RipAlbumImage(hash)
|
||||||
|
|
||||||
|
return e
|
||||||
|
|
||||||
|
with ThreadPoolExecutor() as pool:
|
||||||
|
pool.map(rip_image, thumbs)
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.remove_obsolete()
|
self.remove_obsolete()
|
||||||
self.find_lost_thumbnails()
|
self.find_lost_thumbnails()
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from app.models import Folder
|
|||||||
from app.models import Track
|
from app.models import Track
|
||||||
|
|
||||||
from app import instances
|
from app import instances
|
||||||
from app.logger import Log
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -65,14 +64,11 @@ class getFnF:
|
|||||||
|
|
||||||
tracks = instances.tracks_instance.find_songs_by_filenames(files)
|
tracks = instances.tracks_instance.find_songs_by_filenames(files)
|
||||||
tracks = [Track(track) for track in tracks]
|
tracks = [Track(track) for track in tracks]
|
||||||
s = time.time()
|
|
||||||
|
|
||||||
# folders = [create_folder(dir) for dir in dirs]
|
|
||||||
with ThreadPoolExecutor() as pool:
|
with ThreadPoolExecutor() as pool:
|
||||||
iter = pool.map(create_folder, dirs)
|
iter = pool.map(create_folder, dirs)
|
||||||
folders = [i for i in iter if i is not None]
|
folders = [i for i in iter if i is not None]
|
||||||
d = time.time() - s
|
|
||||||
Log(f"Did that in {d} seconds")
|
|
||||||
folders = filter(lambda f: f.trackcount > 0, folders)
|
folders = filter(lambda f: f.trackcount > 0, folders)
|
||||||
|
|
||||||
return tracks, folders
|
return tracks, folders
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ from concurrent.futures import ThreadPoolExecutor
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from app import settings
|
from app import settings
|
||||||
|
from app.logger import logg
|
||||||
from app.helpers import Get, UseBisection, create_album_hash
|
from app.helpers import Get, UseBisection, create_album_hash
|
||||||
from app.helpers import run_fast_scandir
|
from app.helpers import run_fast_scandir
|
||||||
from app.instances import tracks_instance
|
from app.instances import tracks_instance
|
||||||
from app.lib.albumslib import create_album
|
from app.lib.albumslib import create_album
|
||||||
from app.lib.taglib import get_tags
|
from app.lib.taglib import get_tags
|
||||||
from app.logger import Log
|
|
||||||
from app.models import Album, Track
|
from app.models import Album, Track
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
@@ -45,8 +45,6 @@ class Populate:
|
|||||||
if track["filepath"] in self.files:
|
if track["filepath"] in self.files:
|
||||||
self.files.remove(track["filepath"])
|
self.files.remove(track["filepath"])
|
||||||
|
|
||||||
Log(f"Found {len(self.files)} untagged tracks")
|
|
||||||
|
|
||||||
def get_tags(self, file: str):
|
def get_tags(self, file: str):
|
||||||
tags = get_tags(file)
|
tags = get_tags(file)
|
||||||
|
|
||||||
@@ -60,16 +58,14 @@ class Populate:
|
|||||||
Loops through all the untagged files and tags them.
|
Loops through all the untagged files and tags them.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
s = time.time()
|
logg.info("Tagging untagged tracks...")
|
||||||
print(f"Started tagging files")
|
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor() as executor:
|
||||||
executor.map(self.get_tags, self.files)
|
executor.map(self.get_tags, self.files)
|
||||||
|
|
||||||
if len(self.tagged_tracks) > 0:
|
if len(self.tagged_tracks) > 0:
|
||||||
tracks_instance.insert_many(self.tagged_tracks)
|
tracks_instance.insert_many(self.tagged_tracks)
|
||||||
|
|
||||||
d = time.time() - s
|
logg.info(f"Tagged {len(self.tagged_tracks)} tracks.")
|
||||||
Log(f"Tagged {len(self.tagged_tracks)} files in {d} seconds")
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -86,9 +82,7 @@ class CreateAlbums:
|
|||||||
|
|
||||||
prealbums = self.create_pre_albums(self.db_tracks)
|
prealbums = self.create_pre_albums(self.db_tracks)
|
||||||
prealbums = self.filter_processed(self.db_albums, prealbums)
|
prealbums = self.filter_processed(self.db_albums, prealbums)
|
||||||
print(f"📌 {len(prealbums)}")
|
|
||||||
|
|
||||||
s = time.time()
|
|
||||||
albums = []
|
albums = []
|
||||||
|
|
||||||
for album in tqdm(prealbums, desc="Creating albums"):
|
for album in tqdm(prealbums, desc="Creating albums"):
|
||||||
@@ -103,9 +97,6 @@ class CreateAlbums:
|
|||||||
# if i is not None:
|
# if i is not None:
|
||||||
# albums.append(i)
|
# albums.append(i)
|
||||||
|
|
||||||
d = time.time() - s
|
|
||||||
Log(f"Created {len(albums)} albums in {d} seconds")
|
|
||||||
|
|
||||||
if len(albums) > 0:
|
if len(albums) > 0:
|
||||||
instances.album_instance.insert_many(albums)
|
instances.album_instance.insert_many(albums)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ This library contains the classes and functions related to the watchdog file wat
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from app import api
|
from app.logger import logg
|
||||||
from app import instances
|
from app import instances
|
||||||
from app import models
|
from app import models
|
||||||
from app.helpers import Get, create_album_hash
|
from app.helpers import Get, create_album_hash
|
||||||
@@ -27,7 +27,12 @@ class OnMyWatch:
|
|||||||
def run(self):
|
def run(self):
|
||||||
event_handler = Handler()
|
event_handler = Handler()
|
||||||
self.observer.schedule(event_handler, self.directory, recursive=True)
|
self.observer.schedule(event_handler, self.directory, recursive=True)
|
||||||
self.observer.start()
|
|
||||||
|
try:
|
||||||
|
self.observer.start()
|
||||||
|
except OSError:
|
||||||
|
logg.error("Could not start watchdog.")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
+49
-4
@@ -1,8 +1,53 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from app.settings import logger
|
from app.settings import logger
|
||||||
|
|
||||||
|
|
||||||
class Log:
|
class CustomFormatter(logging.Formatter):
|
||||||
|
|
||||||
def __init__(self, msg):
|
grey = "\x1b[38;20m"
|
||||||
if logger.enable:
|
yellow = "\x1b[33;20m"
|
||||||
print("\n🦋 " + msg + "\n")
|
red = "\x1b[31;20m"
|
||||||
|
bold_red = "\x1b[31;1m"
|
||||||
|
reset = "\x1b[0m"
|
||||||
|
# format = (
|
||||||
|
# "%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
|
||||||
|
# )
|
||||||
|
format = "%(levelname)s: @%(name)s: >>> %(message)s (%(filename)s:%(lineno)d)"
|
||||||
|
|
||||||
|
FORMATS = {
|
||||||
|
logging.DEBUG: grey + format + reset,
|
||||||
|
logging.INFO: grey + format + reset,
|
||||||
|
logging.WARNING: yellow + format + reset,
|
||||||
|
logging.ERROR: red + format + reset,
|
||||||
|
logging.CRITICAL: bold_red + format + reset,
|
||||||
|
}
|
||||||
|
|
||||||
|
def format(self, record):
|
||||||
|
log_fmt = self.FORMATS.get(record.levelno)
|
||||||
|
formatter = logging.Formatter(log_fmt)
|
||||||
|
return formatter.format(record)
|
||||||
|
|
||||||
|
|
||||||
|
logg = logging.getLogger("ALICE_MUSIC_SERVER")
|
||||||
|
logg.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
# create console handler with a higher log level
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
ch.setFormatter(CustomFormatter())
|
||||||
|
|
||||||
|
logg.addHandler(ch)
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger():
|
||||||
|
if logger.enable:
|
||||||
|
return logg
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
logg = get_logger()
|
||||||
|
|
||||||
|
# copied from: https://stackoverflow.com/a/56944256:
|
||||||
|
|||||||
Reference in New Issue
Block a user