mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +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):
|
||||
timestamp: int = Field(description="The timestamp of the track", example=1622217600)
|
||||
duration: int = Field(
|
||||
description="The duration of the track in seconds", example=300
|
||||
)
|
||||
timestamp: int = Field(description="The timestamp of the track")
|
||||
duration: int = Field(description="The duration of the track in seconds")
|
||||
source: str = Field(
|
||||
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
|
||||
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)
|
||||
|
||||
@@ -11,7 +11,6 @@ from typing import Literal
|
||||
from flask import send_file, request, Response, send_from_directory
|
||||
from flask_openapi3 import APIBlueprint, Tag
|
||||
from pydantic import BaseModel, Field
|
||||
import werkzeug
|
||||
import werkzeug.wsgi
|
||||
from app.api.apischemas import TrackHashSchema
|
||||
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.
|
||||
"""
|
||||
request.environ["wsgi.file_wrapper"] = werkzeug.wsgi.FileWrapper
|
||||
trackhash = path.trackhash
|
||||
filepath = query.filepath
|
||||
msg = {"msg": "File Not Found"}
|
||||
|
||||
@@ -311,6 +311,20 @@ class FavoritesTable(Base):
|
||||
|
||||
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):
|
||||
__tablename__ = "scrobble"
|
||||
|
||||
@@ -98,10 +98,20 @@ def recover_items(items: list[dict]):
|
||||
"item": serialize_playlist(playlist),
|
||||
}
|
||||
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 = {
|
||||
"type": "favorite",
|
||||
"item": {
|
||||
"count": FavoritesTable.count(),
|
||||
"count": FavoritesTable.count_tracks(),
|
||||
"image": image,
|
||||
},
|
||||
}
|
||||
elif item["type"] == "track":
|
||||
|
||||
@@ -48,8 +48,8 @@ class RecentlyPlayed(HomepageRoutine):
|
||||
if (
|
||||
store_entry
|
||||
and item
|
||||
and store_entry["type"] + store_entry["hash"]
|
||||
== item["type"] + item["hash"]
|
||||
and store_entry.get("type", "") + store_entry.get("hash", "")
|
||||
== item.get("type", "") + item.get("hash", "")
|
||||
):
|
||||
# If the item is the same as the one in the store
|
||||
# only update the timestamp
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
import math
|
||||
import os
|
||||
from functools import partial
|
||||
from multiprocessing import Pool, cpu_count
|
||||
@@ -139,7 +140,7 @@ class IndexTracks:
|
||||
config = UserConfig()
|
||||
|
||||
# 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)
|
||||
|
||||
# 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:
|
||||
# INFO: If no artist, use the albumartist
|
||||
metadata["artist"] = tags.albumartist
|
||||
metadata["artists"] = tags.albumartist
|
||||
|
||||
parse_data = None
|
||||
|
||||
@@ -255,7 +255,7 @@ def get_tags(filepath: str, config: UserConfig):
|
||||
)
|
||||
|
||||
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] = {
|
||||
@@ -267,7 +267,7 @@ def get_tags(filepath: str, config: UserConfig):
|
||||
"format": "[:5]+[-5:]", # first 5 + last 5 chars
|
||||
}
|
||||
|
||||
to_pop = ["filename", "artist", "albumartist", "year"]
|
||||
to_pop = ["filename", "artists", "albumartist", "year"]
|
||||
|
||||
# REMOVE EMPTY VALUES
|
||||
for key, value in extra.items():
|
||||
|
||||
Reference in New Issue
Block a user