diff --git a/app/crons/mixes.py b/app/crons/mixes.py index dbb596c1..8683b6f0 100644 --- a/app/crons/mixes.py +++ b/app/crons/mixes.py @@ -18,7 +18,6 @@ class Mixes(CronJob): """ Creates the artist mixes """ - print("⭐⭐⭐⭐ Mixes cron job running") ArtistMixes() # INFO: Because you listened to artist items are generated using diff --git a/app/db/userdata.py b/app/db/userdata.py index 8db27e8f..cf1537fa 100644 --- a/app/db/userdata.py +++ b/app/db/userdata.py @@ -474,7 +474,7 @@ class LibDataTable(Base): result = cls.execute( 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): @@ -610,26 +610,37 @@ class PageTable(Base): @classmethod 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()] @classmethod 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()) @classmethod 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 def update_items(cls, id: int, items: list[dict[str, Any]]): 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 def update_one(cls, payload: dict[str, Any]): 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, ) diff --git a/app/lib/colorlib.py b/app/lib/colorlib.py index 8f5587ce..8d6b53f8 100644 --- a/app/lib/colorlib.py +++ b/app/lib/colorlib.py @@ -84,7 +84,11 @@ class ProcessAlbumColors: # INFO: Write to the database. if albumrecord is None: LibDataTable.insert_one( - {"itemhash": albumhash, "color": colors[0], "itemtype": "album"} + { + "itemhash": "album" + albumhash, + "color": colors[0], + "itemtype": "album", + } ) else: LibDataTable.update_one(albumhash, {"color": colors[0]}) @@ -109,7 +113,6 @@ class ProcessArtistColors: ) record = LibDataTable.find_one(artisthash, "artist") - if (record is not None) and (record.color is not None): continue @@ -123,9 +126,6 @@ class ProcessArtistColors: if artist: artist.set_color(colors[0]) - # INFO: Write to the database. - print("RECORD") - print(record) if record is None: LibDataTable.insert_one( { diff --git a/app/plugins/mixes.py b/app/plugins/mixes.py index 999b8ad2..096afae7 100644 --- a/app/plugins/mixes.py +++ b/app/plugins/mixes.py @@ -100,7 +100,7 @@ class MixesPlugin(Plugin): print("Failed to decode JSON response from recommendation server") return [], [], [] - trackhashes: list[str] = results["tracks"] + trackhashes: list[str] = results.get("tracks", []) trackmatches = TrackStore.get_flat_list() trackmatches = [t for t in trackmatches if t.weakhash in trackhashes] @@ -234,8 +234,6 @@ class MixesPlugin(Plugin): indexed.add(artist["artisthash"]) period["created"] += 1 - print(f"⭐⭐⭐⭐ Created {len(mixes)} mixes") - print([m.title for m in mixes]) return mixes @classmethod @@ -286,8 +284,6 @@ class MixesPlugin(Plugin): db_mix = MixTable.get_by_sourcehash(sourcehash) if db_mix: - print(f"🔍 Found existing mix for {_artist.artist.name}") - print(db_mix.title) return db_mix mix_tracks, albums, artists = self.get_track_mix_data(tracks) diff --git a/app/start_info_logger.py b/app/start_info_logger.py index 5b497341..301e44d6 100644 --- a/app/start_info_logger.py +++ b/app/start_info_logger.py @@ -15,7 +15,8 @@ def log_startup_info(): adresses = [FLASKVARS.get_flask_host()] 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:") for address in adresses: diff --git a/app/utils/dates.py b/app/utils/dates.py index 67e77ef7..a1fc2052 100644 --- a/app/utils/dates.py +++ b/app/utils/dates.py @@ -77,7 +77,6 @@ def get_date_range(duration: str, units_ago: int = 0): seconds_ago = ( pendulum.now() - pendulum.now().subtract().start_of(duration) ).total_seconds() * units_ago - print("seconds_ago", duration, str(seconds_ago)) match duration: case "day" | "week" | "month" | "year": diff --git a/app/utils/network.py b/app/utils/network.py index e4f1467b..4f8b19d1 100644 --- a/app/utils/network.py +++ b/app/utils/network.py @@ -22,7 +22,10 @@ def get_ip(): Returns the IP address of this device. """ 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]) soc.close()