mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
fix favorites on homescreen
+ reduce tagger process count
This commit is contained in:
@@ -43,13 +43,17 @@ api = APIBlueprint("logger", __name__, url_prefix="/logger", abp_tags=[bp_tag])
|
|||||||
|
|
||||||
|
|
||||||
class LogTrackBody(TrackHashSchema):
|
class LogTrackBody(TrackHashSchema):
|
||||||
timestamp: int = Field(description="The timestamp of the track", example=1622217600)
|
timestamp: int = Field(description="The timestamp of the track")
|
||||||
duration: int = Field(
|
duration: int = Field(description="The duration of the track in seconds")
|
||||||
description="The duration of the track in seconds", example=300
|
|
||||||
)
|
|
||||||
source: str = Field(
|
source: str = Field(
|
||||||
description="The play source of the track",
|
description="The play source of the track",
|
||||||
example=f"al:{Defaults.API_ALBUMHASH}",
|
json_schema_extra={
|
||||||
|
"examples": [
|
||||||
|
f"al:{Defaults.API_ALBUMHASH}",
|
||||||
|
f"tr:{Defaults.API_TRACKHASH}",
|
||||||
|
f"ar:{Defaults.API_ARTISTHASH}",
|
||||||
|
]
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -354,11 +358,7 @@ def get_stats():
|
|||||||
if len(tracks) > 0
|
if len(tracks) > 0
|
||||||
else "—"
|
else "—"
|
||||||
),
|
),
|
||||||
(
|
(tracks[0].image if len(tracks) > 0 else None),
|
||||||
tracks[0].image
|
|
||||||
if len(tracks) > 0
|
|
||||||
else None
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fav_count = FavoritesTable.count_favs_in_period(start_time, end_time)
|
fav_count = FavoritesTable.count_favs_in_period(start_time, end_time)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from typing import Literal
|
|||||||
from flask import send_file, request, Response, send_from_directory
|
from flask import send_file, request, Response, send_from_directory
|
||||||
from flask_openapi3 import APIBlueprint, Tag
|
from flask_openapi3 import APIBlueprint, Tag
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
import werkzeug
|
|
||||||
import werkzeug.wsgi
|
import werkzeug.wsgi
|
||||||
from app.api.apischemas import TrackHashSchema
|
from app.api.apischemas import TrackHashSchema
|
||||||
from app.lib.trackslib import get_silence_paddings
|
from app.lib.trackslib import get_silence_paddings
|
||||||
@@ -61,7 +60,6 @@ def send_track_file_legacy(path: TrackHashSchema, query: SendTrackFileQuery):
|
|||||||
|
|
||||||
NOTE: Does not support range requests or transcoding.
|
NOTE: Does not support range requests or transcoding.
|
||||||
"""
|
"""
|
||||||
request.environ["wsgi.file_wrapper"] = werkzeug.wsgi.FileWrapper
|
|
||||||
trackhash = path.trackhash
|
trackhash = path.trackhash
|
||||||
filepath = query.filepath
|
filepath = query.filepath
|
||||||
msg = {"msg": "File Not Found"}
|
msg = {"msg": "File Not Found"}
|
||||||
|
|||||||
@@ -311,6 +311,20 @@ class FavoritesTable(Base):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def count_tracks(cls):
|
||||||
|
result = cls.execute(select(func.count(cls.id)).where(cls.type == "track"))
|
||||||
|
|
||||||
|
return next(result).scalar()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_last_trackhash(cls):
|
||||||
|
result = cls.execute(
|
||||||
|
select(cls.hash).where(cls.type == "track").order_by(cls.timestamp.desc())
|
||||||
|
)
|
||||||
|
|
||||||
|
return next(result).scalar()
|
||||||
|
|
||||||
|
|
||||||
class ScrobbleTable(Base):
|
class ScrobbleTable(Base):
|
||||||
__tablename__ = "scrobble"
|
__tablename__ = "scrobble"
|
||||||
|
|||||||
@@ -98,10 +98,20 @@ def recover_items(items: list[dict]):
|
|||||||
"item": serialize_playlist(playlist),
|
"item": serialize_playlist(playlist),
|
||||||
}
|
}
|
||||||
elif item["type"] == "favorite":
|
elif item["type"] == "favorite":
|
||||||
|
image = None
|
||||||
|
last_trackhash = FavoritesTable.get_last_trackhash()
|
||||||
|
|
||||||
|
if last_trackhash:
|
||||||
|
trackhash = last_trackhash.replace("track_", "")
|
||||||
|
entry = TrackStore.trackhashmap.get(trackhash)
|
||||||
|
if entry:
|
||||||
|
image = entry.tracks[0].image
|
||||||
|
|
||||||
recovered_item = {
|
recovered_item = {
|
||||||
"type": "favorite",
|
"type": "favorite",
|
||||||
"item": {
|
"item": {
|
||||||
"count": FavoritesTable.count(),
|
"count": FavoritesTable.count_tracks(),
|
||||||
|
"image": image,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
elif item["type"] == "track":
|
elif item["type"] == "track":
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ class RecentlyPlayed(HomepageRoutine):
|
|||||||
if (
|
if (
|
||||||
store_entry
|
store_entry
|
||||||
and item
|
and item
|
||||||
and store_entry["type"] + store_entry["hash"]
|
and store_entry.get("type", "") + store_entry.get("hash", "")
|
||||||
== item["type"] + item["hash"]
|
== item.get("type", "") + item.get("hash", "")
|
||||||
):
|
):
|
||||||
# If the item is the same as the one in the store
|
# If the item is the same as the one in the store
|
||||||
# only update the timestamp
|
# only update the timestamp
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import math
|
||||||
import os
|
import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from multiprocessing import Pool, cpu_count
|
from multiprocessing import Pool, cpu_count
|
||||||
@@ -139,7 +140,7 @@ class IndexTracks:
|
|||||||
config = UserConfig()
|
config = UserConfig()
|
||||||
|
|
||||||
# Create process pool with worker function
|
# Create process pool with worker function
|
||||||
with Pool(processes=cpu_count()) as pool:
|
with Pool(processes=math.floor(cpu_count() / 2)) as pool:
|
||||||
worker = partial(self._process_file, config=config, key=key)
|
worker = partial(self._process_file, config=config, key=key)
|
||||||
|
|
||||||
# Process files and track progress
|
# Process files and track progress
|
||||||
|
|||||||
+3
-3
@@ -193,7 +193,7 @@ def get_tags(filepath: str, config: UserConfig):
|
|||||||
|
|
||||||
if no_artist and not no_albumartist:
|
if no_artist and not no_albumartist:
|
||||||
# INFO: If no artist, use the albumartist
|
# INFO: If no artist, use the albumartist
|
||||||
metadata["artist"] = tags.albumartist
|
metadata["artists"] = tags.albumartist
|
||||||
|
|
||||||
parse_data = None
|
parse_data = None
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ def get_tags(filepath: str, config: UserConfig):
|
|||||||
)
|
)
|
||||||
|
|
||||||
metadata["trackhash"] = create_hash(
|
metadata["trackhash"] = create_hash(
|
||||||
metadata.get("artist", ""), metadata.get("album", ""), metadata.get("title", "")
|
metadata.get("artists", ""), metadata.get("album", ""), metadata.get("title", "")
|
||||||
)
|
)
|
||||||
|
|
||||||
extra: dict[str, Any] = {
|
extra: dict[str, Any] = {
|
||||||
@@ -267,7 +267,7 @@ def get_tags(filepath: str, config: UserConfig):
|
|||||||
"format": "[:5]+[-5:]", # first 5 + last 5 chars
|
"format": "[:5]+[-5:]", # first 5 + last 5 chars
|
||||||
}
|
}
|
||||||
|
|
||||||
to_pop = ["filename", "artist", "albumartist", "year"]
|
to_pop = ["filename", "artists", "albumartist", "year"]
|
||||||
|
|
||||||
# REMOVE EMPTY VALUES
|
# REMOVE EMPTY VALUES
|
||||||
for key, value in extra.items():
|
for key, value in extra.items():
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "swingmusic"
|
name = "swingmusic"
|
||||||
version = "2.0.0"
|
version = "2.0.2"
|
||||||
description = "Swing Music"
|
description = "Swing Music"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
@@ -20,7 +20,6 @@ dependencies = [
|
|||||||
"tabulate>=0.9.0",
|
"tabulate>=0.9.0",
|
||||||
"setproctitle>=1.3.2",
|
"setproctitle>=1.3.2",
|
||||||
"locust>=2.20.1",
|
"locust>=2.20.1",
|
||||||
"waitress>=2.1.2",
|
|
||||||
"watchdog>=4.0.0",
|
"watchdog>=4.0.0",
|
||||||
"pendulum>=3.0.0",
|
"pendulum>=3.0.0",
|
||||||
"flask-jwt-extended>=4.6.0",
|
"flask-jwt-extended>=4.6.0",
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,6 @@
|
|||||||
altgraph==0.17.4
|
altgraph==0.17.4
|
||||||
annotated-types==0.7.0
|
annotated-types==0.7.0
|
||||||
|
bjoern==3.2.2
|
||||||
blinker==1.9.0
|
blinker==1.9.0
|
||||||
brotli==1.1.0
|
brotli==1.1.0
|
||||||
certifi==2025.1.31
|
certifi==2025.1.31
|
||||||
@@ -54,7 +55,6 @@ typing-extensions==4.12.2
|
|||||||
tzdata==2025.1
|
tzdata==2025.1
|
||||||
unidecode==1.3.8
|
unidecode==1.3.8
|
||||||
urllib3==2.3.0
|
urllib3==2.3.0
|
||||||
waitress==3.0.2
|
|
||||||
watchdog==6.0.0
|
watchdog==6.0.0
|
||||||
werkzeug==3.1.3
|
werkzeug==3.1.3
|
||||||
xxhash==3.5.0
|
xxhash==3.5.0
|
||||||
|
|||||||
@@ -1236,7 +1236,6 @@ dependencies = [
|
|||||||
{ name = "tinytag" },
|
{ name = "tinytag" },
|
||||||
{ name = "tqdm" },
|
{ name = "tqdm" },
|
||||||
{ name = "unidecode" },
|
{ name = "unidecode" },
|
||||||
{ name = "waitress" },
|
|
||||||
{ name = "watchdog" },
|
{ name = "watchdog" },
|
||||||
{ name = "xxhash" },
|
{ name = "xxhash" },
|
||||||
]
|
]
|
||||||
@@ -1272,7 +1271,6 @@ requires-dist = [
|
|||||||
{ name = "tinytag", specifier = ">=2.0.0" },
|
{ name = "tinytag", specifier = ">=2.0.0" },
|
||||||
{ name = "tqdm", specifier = ">=4.65.0" },
|
{ name = "tqdm", specifier = ">=4.65.0" },
|
||||||
{ name = "unidecode", specifier = ">=1.3.6" },
|
{ name = "unidecode", specifier = ">=1.3.6" },
|
||||||
{ name = "waitress", specifier = ">=2.1.2" },
|
|
||||||
{ name = "watchdog", specifier = ">=4.0.0" },
|
{ name = "watchdog", specifier = ">=4.0.0" },
|
||||||
{ name = "xxhash", specifier = ">=3.4.1" },
|
{ name = "xxhash", specifier = ">=3.4.1" },
|
||||||
]
|
]
|
||||||
@@ -1390,15 +1388,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/c8/19/4ec628951a74043532ca2cf5d97b7b14863931476d117c471e8e2b1eb39f/urllib3-2.3.0-py3-none-any.whl", hash = "sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df", size = 128369 },
|
{ url = "https://files.pythonhosted.org/packages/c8/19/4ec628951a74043532ca2cf5d97b7b14863931476d117c471e8e2b1eb39f/urllib3-2.3.0-py3-none-any.whl", hash = "sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df", size = 128369 },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "waitress"
|
|
||||||
version = "3.0.2"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/bf/cb/04ddb054f45faa306a230769e868c28b8065ea196891f09004ebace5b184/waitress-3.0.2.tar.gz", hash = "sha256:682aaaf2af0c44ada4abfb70ded36393f0e307f4ab9456a215ce0020baefc31f", size = 179901 }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8d/57/a27182528c90ef38d82b636a11f606b0cbb0e17588ed205435f8affe3368/waitress-3.0.2-py3-none-any.whl", hash = "sha256:c56d67fd6e87c2ee598b76abdd4e96cfad1f24cacdea5078d382b1f9d7b5ed2e", size = 56232 },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "watchdog"
|
name = "watchdog"
|
||||||
version = "6.0.0"
|
version = "6.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user