fix artist color mapping

This commit is contained in:
cwilvx
2025-01-31 12:01:09 +03:00
parent b8ff6070f7
commit d6e8a09aeb
7 changed files with 29 additions and 20 deletions
-1
View File
@@ -18,7 +18,6 @@ class Mixes(CronJob):
""" """
Creates the artist mixes Creates the artist mixes
""" """
print("⭐⭐⭐⭐ Mixes cron job running")
ArtistMixes() ArtistMixes()
# INFO: Because you listened to artist items are generated using # INFO: Because you listened to artist items are generated using
+17 -6
View File
@@ -474,7 +474,7 @@ class LibDataTable(Base):
result = cls.execute( result = cls.execute(
select(cls.itemhash, cls.color).where(cls.itemtype == type) select(cls.itemhash, cls.color).where(cls.itemtype == type)
) )
return [{"itemhash": r[0], "color": r[1]} for r in result.fetchall()] return [{"itemhash": r[0].replace(type, ''), "color": r[1]} for r in result.fetchall()]
class MixTable(Base): class MixTable(Base):
@@ -610,26 +610,37 @@ class PageTable(Base):
@classmethod @classmethod
def get_all(cls): def get_all(cls):
result = cls.execute(select(cls)) result = cls.execute(select(cls).where(cls.userid == get_current_userid()))
return [cls.to_dict(entry) for entry in result.fetchall()] return [cls.to_dict(entry) for entry in result.fetchall()]
@classmethod @classmethod
def get_by_id(cls, id: int): def get_by_id(cls, id: int):
result = cls.execute(select(cls).where(cls.id == id)) result = cls.execute(
select(cls).where(and_(cls.id == id, cls.userid == get_current_userid()))
)
return cls.to_dict(result.fetchone()) return cls.to_dict(result.fetchone())
@classmethod @classmethod
def delete_by_id(cls, id: int): def delete_by_id(cls, id: int):
return cls.execute(delete(cls).where(cls.id == id), commit=True) return cls.execute(
delete(cls).where(and_(cls.id == id, cls.userid == get_current_userid())),
commit=True,
)
@classmethod @classmethod
def update_items(cls, id: int, items: list[dict[str, Any]]): def update_items(cls, id: int, items: list[dict[str, Any]]):
return cls.execute( return cls.execute(
update(cls).where(cls.id == id).values(items=items), commit=True update(cls)
.where(and_(cls.id == id, cls.userid == get_current_userid()))
.values(items=items),
commit=True,
) )
@classmethod @classmethod
def update_one(cls, payload: dict[str, Any]): def update_one(cls, payload: dict[str, Any]):
return cls.execute( return cls.execute(
update(cls).where(cls.id == payload["id"]).values(payload), commit=True update(cls)
.where(and_(cls.id == payload["id"], cls.userid == get_current_userid()))
.values(payload),
commit=True,
) )
+5 -5
View File
@@ -84,7 +84,11 @@ class ProcessAlbumColors:
# INFO: Write to the database. # INFO: Write to the database.
if albumrecord is None: if albumrecord is None:
LibDataTable.insert_one( LibDataTable.insert_one(
{"itemhash": albumhash, "color": colors[0], "itemtype": "album"} {
"itemhash": "album" + albumhash,
"color": colors[0],
"itemtype": "album",
}
) )
else: else:
LibDataTable.update_one(albumhash, {"color": colors[0]}) LibDataTable.update_one(albumhash, {"color": colors[0]})
@@ -109,7 +113,6 @@ class ProcessArtistColors:
) )
record = LibDataTable.find_one(artisthash, "artist") record = LibDataTable.find_one(artisthash, "artist")
if (record is not None) and (record.color is not None): if (record is not None) and (record.color is not None):
continue continue
@@ -123,9 +126,6 @@ class ProcessArtistColors:
if artist: if artist:
artist.set_color(colors[0]) artist.set_color(colors[0])
# INFO: Write to the database.
print("RECORD")
print(record)
if record is None: if record is None:
LibDataTable.insert_one( LibDataTable.insert_one(
{ {
+1 -5
View File
@@ -100,7 +100,7 @@ class MixesPlugin(Plugin):
print("Failed to decode JSON response from recommendation server") print("Failed to decode JSON response from recommendation server")
return [], [], [] return [], [], []
trackhashes: list[str] = results["tracks"] trackhashes: list[str] = results.get("tracks", [])
trackmatches = TrackStore.get_flat_list() trackmatches = TrackStore.get_flat_list()
trackmatches = [t for t in trackmatches if t.weakhash in trackhashes] trackmatches = [t for t in trackmatches if t.weakhash in trackhashes]
@@ -234,8 +234,6 @@ class MixesPlugin(Plugin):
indexed.add(artist["artisthash"]) indexed.add(artist["artisthash"])
period["created"] += 1 period["created"] += 1
print(f"⭐⭐⭐⭐ Created {len(mixes)} mixes")
print([m.title for m in mixes])
return mixes return mixes
@classmethod @classmethod
@@ -286,8 +284,6 @@ class MixesPlugin(Plugin):
db_mix = MixTable.get_by_sourcehash(sourcehash) db_mix = MixTable.get_by_sourcehash(sourcehash)
if db_mix: if db_mix:
print(f"🔍 Found existing mix for {_artist.artist.name}")
print(db_mix.title)
return db_mix return db_mix
mix_tracks, albums, artists = self.get_track_mix_data(tracks) mix_tracks, albums, artists = self.get_track_mix_data(tracks)
+2 -1
View File
@@ -15,7 +15,8 @@ def log_startup_info():
adresses = [FLASKVARS.get_flask_host()] adresses = [FLASKVARS.get_flask_host()]
if FLASKVARS.get_flask_host() == "0.0.0.0": if FLASKVARS.get_flask_host() == "0.0.0.0":
adresses = ["localhost", get_ip()] remote_ip = get_ip()
adresses = ["localhost"] + ([remote_ip] if remote_ip else [])
print("Started app on:") print("Started app on:")
for address in adresses: for address in adresses:
-1
View File
@@ -77,7 +77,6 @@ def get_date_range(duration: str, units_ago: int = 0):
seconds_ago = ( seconds_ago = (
pendulum.now() - pendulum.now().subtract().start_of(duration) pendulum.now() - pendulum.now().subtract().start_of(duration)
).total_seconds() * units_ago ).total_seconds() * units_ago
print("seconds_ago", duration, str(seconds_ago))
match duration: match duration:
case "day" | "week" | "month" | "year": case "day" | "week" | "month" | "year":
+4 -1
View File
@@ -22,7 +22,10 @@ def get_ip():
Returns the IP address of this device. Returns the IP address of this device.
""" """
soc = Socket.socket(Socket.AF_INET, Socket.SOCK_DGRAM) soc = Socket.socket(Socket.AF_INET, Socket.SOCK_DGRAM)
soc.connect(("8.8.8.8", 80)) try:
soc.connect(("8.8.8.8", 80))
except OSError:
return None
ip_address = str(soc.getsockname()[0]) ip_address = str(soc.getsockname()[0])
soc.close() soc.close()