mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
add new flags to disable cleaning track and album titles
+ update readme +
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""
|
||||
Contains all the artist(s) routes.
|
||||
"""
|
||||
import random
|
||||
from collections import deque
|
||||
|
||||
from flask import Blueprint, request
|
||||
@@ -9,7 +8,6 @@ from flask import Blueprint, request
|
||||
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||
from app.models import Album, FavType, Track
|
||||
from app.utils.remove_duplicates import remove_duplicates
|
||||
from app.requests.artists import fetch_similar_artists
|
||||
|
||||
from app.store.albums import AlbumStore
|
||||
from app.store.tracks import TrackStore
|
||||
|
||||
+54
-8
@@ -28,8 +28,14 @@ class HandleArgs:
|
||||
self.handle_host()
|
||||
self.handle_port()
|
||||
self.handle_config_path()
|
||||
|
||||
self.handle_no_feat()
|
||||
self.handle_remove_prod()
|
||||
self.handle_cleaning_albums()
|
||||
self.handle_cleaning_tracks()
|
||||
self.handle_periodic_scan()
|
||||
self.handle_periodic_scan_interval()
|
||||
|
||||
self.handle_help()
|
||||
self.handle_version()
|
||||
|
||||
@@ -68,7 +74,7 @@ class HandleArgs:
|
||||
@staticmethod
|
||||
def handle_port():
|
||||
if ALLARGS.port in ARGS:
|
||||
index = ARGS.index(ALLARGS.port)
|
||||
index = ARGS.index(ALLARGS.port.value)
|
||||
try:
|
||||
port = ARGS[index + 1]
|
||||
except IndexError:
|
||||
@@ -84,7 +90,7 @@ class HandleArgs:
|
||||
@staticmethod
|
||||
def handle_host():
|
||||
if ALLARGS.host in ARGS:
|
||||
index = ARGS.index(ALLARGS.host)
|
||||
index = ARGS.index(ALLARGS.host.value)
|
||||
|
||||
try:
|
||||
host = ARGS[index + 1]
|
||||
@@ -92,7 +98,7 @@ class HandleArgs:
|
||||
print("ERROR: Host not specified")
|
||||
sys.exit(0)
|
||||
|
||||
settings.FLASKVARS.FLASK_HOST = host # type: ignore
|
||||
settings.FLASKVARS.set_flask_host(host) # type: ignore
|
||||
|
||||
@staticmethod
|
||||
def handle_config_path():
|
||||
@@ -100,7 +106,7 @@ class HandleArgs:
|
||||
Modifies the config path.
|
||||
"""
|
||||
if ALLARGS.config in ARGS:
|
||||
index = ARGS.index(ALLARGS.config)
|
||||
index = ARGS.index(ALLARGS.config.value)
|
||||
|
||||
try:
|
||||
config_path = ARGS[index + 1]
|
||||
@@ -119,22 +125,62 @@ class HandleArgs:
|
||||
@staticmethod
|
||||
def handle_no_feat():
|
||||
# if ArgsEnum.no_feat in ARGS:
|
||||
if any((a in ARGS for a in ALLARGS.show_feat)):
|
||||
if any((a in ARGS for a in ALLARGS.show_feat.value)):
|
||||
settings.FromFlags.EXTRACT_FEAT = False
|
||||
|
||||
@staticmethod
|
||||
def handle_remove_prod():
|
||||
if any((a in ARGS for a in ALLARGS.show_prod)):
|
||||
if any((a in ARGS for a in ALLARGS.show_prod.value)):
|
||||
settings.FromFlags.REMOVE_PROD = False
|
||||
|
||||
@staticmethod
|
||||
def handle_cleaning_albums():
|
||||
if any((a in ARGS for a in ALLARGS.dont_clean_albums.value)):
|
||||
settings.FromFlags.CLEAN_ALBUM_TITLE = False
|
||||
|
||||
@staticmethod
|
||||
def handle_cleaning_tracks():
|
||||
if any((a in ARGS for a in ALLARGS.dont_clean_tracks.value)):
|
||||
settings.FromFlags.REMOVE_REMASTER_FROM_TRACK = False
|
||||
|
||||
@staticmethod
|
||||
def handle_periodic_scan():
|
||||
if any((a in ARGS for a in ALLARGS.no_periodic_scan.value)):
|
||||
settings.FromFlags.DO_PERIODIC_SCANS = False
|
||||
|
||||
@staticmethod
|
||||
def handle_periodic_scan_interval():
|
||||
if any((a in ARGS for a in ALLARGS.periodic_scan_interval.value)):
|
||||
index = [ARGS.index(a) for a in ALLARGS.periodic_scan_interval.value if a in ARGS][0]
|
||||
|
||||
try:
|
||||
interval = ARGS[index + 1]
|
||||
except IndexError:
|
||||
print("ERROR: Interval not specified")
|
||||
sys.exit(0)
|
||||
|
||||
# psi = 0
|
||||
|
||||
try:
|
||||
psi = int(interval)
|
||||
except ValueError:
|
||||
print("ERROR: Interval should be a number")
|
||||
sys.exit(0)
|
||||
|
||||
if psi < 0:
|
||||
print("WADAFUCK ARE YOU TRYING?")
|
||||
sys.exit(0)
|
||||
|
||||
settings.FromFlags.PERIODIC_SCAN_INTERVAL = psi
|
||||
|
||||
@staticmethod
|
||||
def handle_help():
|
||||
if any((a in ARGS for a in ALLARGS.help)):
|
||||
if any((a in ARGS for a in ALLARGS.help.value)):
|
||||
print(HELP_MESSAGE)
|
||||
sys.exit(0)
|
||||
|
||||
@staticmethod
|
||||
def handle_version():
|
||||
if any((a in ARGS for a in ALLARGS.version)):
|
||||
if any((a in ARGS for a in ALLARGS.version.value)):
|
||||
print(settings.Release.APP_VERSION)
|
||||
sys.exit(0)
|
||||
|
||||
@@ -6,8 +6,6 @@ import sqlite3
|
||||
from pathlib import Path
|
||||
from sqlite3 import Connection as SqlConn
|
||||
|
||||
from app.settings import Db
|
||||
|
||||
|
||||
def create_connection(db_file: str) -> SqlConn:
|
||||
"""
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ def extract_thumb(filepath: str, webp_path: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def extract_date(date_str: str | None, filepath: str) -> int:
|
||||
def extract_date(date_str: str | None) -> int:
|
||||
try:
|
||||
return int(date_str.split("-")[0])
|
||||
except: # pylint: disable=bare-except
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
import dataclasses
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
+2
-3
@@ -1,10 +1,9 @@
|
||||
import dataclasses
|
||||
from dataclasses import dataclass
|
||||
|
||||
from app.settings import FromFlags, get_flag, ParserFlags
|
||||
from .artist import ArtistMinimal
|
||||
from app.settings import get_flag, ParserFlags
|
||||
from app.utils.hashing import create_hash
|
||||
from app.utils.parsers import split_artists, remove_prod, parse_feat_from_title, clean_title
|
||||
from .artist import ArtistMinimal
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
|
||||
+13
-6
@@ -6,14 +6,21 @@ HELP_MESSAGE = f"""
|
||||
Usage: swingmusic [options]
|
||||
|
||||
Options:
|
||||
{args.build}: Build the application (in development)
|
||||
{', '.join(args.help.value)}: Show this help message
|
||||
{', '.join(args.version.value)}: Show the app version
|
||||
|
||||
{args.host}: Set the host
|
||||
{args.port}: Set the port
|
||||
{args.config}: Set the config path
|
||||
|
||||
{', '.join(args.show_feat)}: Do not extract featured artists from the song title
|
||||
{', '.join(args.show_prod)}: Do not hide producers in the song title
|
||||
|
||||
{', '.join(args.help)}: Show this help message
|
||||
{', '.join(args.version)}: Show the app version
|
||||
{', '.join(args.show_feat.value)}: Do not extract featured artists from the song title
|
||||
{', '.join(args.show_prod.value)}: Do not hide producers in the song title
|
||||
{', '.join(args.dont_clean_albums.value)}: Don't clean album titles. Cleaning is done by removing information in
|
||||
parentheses and showing it separately
|
||||
{', '.join(args.dont_clean_tracks.value)}: Don't remove remaster information from track titles
|
||||
{', '.join(args.no_periodic_scan.value)}: Disable periodic scan
|
||||
{', '.join(args.periodic_scan_interval.value)}: Set the periodic scan interval in seconds. Default is 300 seconds (5
|
||||
minutes)
|
||||
|
||||
{args.build}: Build the application (in development)
|
||||
"""
|
||||
|
||||
+29
-5
@@ -106,8 +106,24 @@ class FLASKVARS:
|
||||
FLASK_PORT = 1970
|
||||
FLASK_HOST = "localhost"
|
||||
|
||||
@classmethod
|
||||
def get_flask_port(cls):
|
||||
return cls.FLASK_PORT
|
||||
|
||||
class ALLARGS:
|
||||
@classmethod
|
||||
def get_flask_host(cls):
|
||||
return cls.FLASK_HOST
|
||||
|
||||
@classmethod
|
||||
def set_flask_port(cls, port):
|
||||
cls.FLASK_PORT = port
|
||||
|
||||
@classmethod
|
||||
def set_flask_host(cls, host):
|
||||
cls.FLASK_HOST = host
|
||||
|
||||
|
||||
class ALLARGS(Enum):
|
||||
"""
|
||||
Enumerates the possible app arguments.
|
||||
"""
|
||||
@@ -116,10 +132,16 @@ class ALLARGS:
|
||||
port = "--port"
|
||||
host = "--host"
|
||||
config = "--config"
|
||||
show_feat = ["--show-feat", "-sf"]
|
||||
show_prod = ["--show-prod", "-sp"]
|
||||
help = ["--help", "-h"]
|
||||
version = ["--version", "-v"]
|
||||
|
||||
show_feat = ("--show-feat", "-sf")
|
||||
show_prod = ("--show-prod", "-sp")
|
||||
dont_clean_albums = ("--no-clean-albums", "-nca")
|
||||
dont_clean_tracks = ("--no-clean-tracks", "-nct")
|
||||
no_periodic_scan = ("--no-periodic-scan", "-nps")
|
||||
periodic_scan_interval = ("--scan-interval", "-psi")
|
||||
|
||||
help = ("--help", "-h")
|
||||
version = ("--version", "-v")
|
||||
|
||||
|
||||
class FromFlags:
|
||||
@@ -135,6 +157,7 @@ class FromFlags:
|
||||
|
||||
CLEAN_ALBUM_TITLE = False
|
||||
REMOVE_REMASTER_FROM_TRACK = False
|
||||
SHOW_ALBUM_VERSION = False
|
||||
|
||||
DO_PERIODIC_SCANS = True
|
||||
PERIODIC_SCAN_INTERVAL = 300 # seconds
|
||||
@@ -146,6 +169,7 @@ class ParserFlags(Enum):
|
||||
EXTRACT_FEAT = 'EXTRACT_FEAT'
|
||||
REMOVE_PROD = 'REMOVE_PROD'
|
||||
CLEAN_ALBUM_TITLE = 'CLEAN_ALBUM_TITLE'
|
||||
SHOW_ALBUM_VERSION = 'SHOW_ALBUM_VERSION'
|
||||
REMOVE_REMASTER_FROM_TRACK = 'REMOVE_REMASTER_FROM_TRACK'
|
||||
DO_PERIODIC_SCANS = 'DO_PERIODIC_SCANS'
|
||||
PERIODIC_SCAN_INTERVAL = 'PERIODIC_SCAN_INTERVAL'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
from app.settings import TCOLOR, Release, FLASKVARS, Paths, FromFlags, get_flag, ParserFlags
|
||||
from app.settings import TCOLOR, Release, FLASKVARS, Paths, get_flag, ParserFlags
|
||||
from app.utils.network import get_ip
|
||||
|
||||
|
||||
@@ -12,16 +12,16 @@ def log_startup_info():
|
||||
print(lines)
|
||||
print(f"{TCOLOR.HEADER}SwingMusic {Release.APP_VERSION} {TCOLOR.ENDC}")
|
||||
|
||||
adresses = [FLASKVARS.FLASK_HOST]
|
||||
adresses = [FLASKVARS.get_flask_host()]
|
||||
|
||||
if FLASKVARS.FLASK_HOST == "0.0.0.0":
|
||||
if FLASKVARS.get_flask_host() == "0.0.0.0":
|
||||
adresses = ["localhost", get_ip()]
|
||||
|
||||
print("Started app on:")
|
||||
for address in adresses:
|
||||
# noinspection HttpUrlsUsage
|
||||
print(
|
||||
f"➤ {TCOLOR.OKGREEN}http://{address}:{FLASKVARS.FLASK_PORT}{TCOLOR.ENDC}"
|
||||
f"➤ {TCOLOR.OKGREEN}http://{address}:{FLASKVARS.get_flask_port()}{TCOLOR.ENDC}"
|
||||
)
|
||||
|
||||
print(lines)
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ class TrackStore:
|
||||
track.is_favorite = False
|
||||
|
||||
@classmethod
|
||||
def append_track_artists(cls, albumhash: str, artists: list[str], new_album_title:str):
|
||||
def append_track_artists(cls, albumhash: str, artists: list[str], new_album_title: str):
|
||||
tracks = cls.get_tracks_by_albumhash(albumhash)
|
||||
|
||||
for track in tracks:
|
||||
|
||||
Reference in New Issue
Block a user