From f3c0d202686340c33a5a5751fff4af24778daeee Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Tue, 5 Nov 2024 16:27:16 -0500 Subject: [PATCH] [scrobbles] Fix ntfy formatting --- vrobbler/apps/beers/models.py | 6 +++--- vrobbler/apps/boardgames/models.py | 6 +++--- vrobbler/apps/books/models.py | 5 +++-- vrobbler/apps/lifeevents/models.py | 6 +++--- vrobbler/apps/locations/models.py | 8 +++++--- vrobbler/apps/moods/models.py | 6 +++--- vrobbler/apps/music/models.py | 6 +++--- vrobbler/apps/scrobbles/dataclasses.py | 8 ++++---- vrobbler/apps/scrobbles/mixins.py | 22 ++++++++++++++++++++-- vrobbler/apps/scrobbles/models.py | 4 ++-- vrobbler/apps/sports/models.py | 6 +++--- vrobbler/apps/tasks/models.py | 6 +++--- vrobbler/apps/trails/models.py | 6 +++--- vrobbler/apps/videogames/models.py | 6 +++--- vrobbler/apps/videos/models.py | 10 +++++++--- vrobbler/apps/webpages/models.py | 6 +++--- 16 files changed, 71 insertions(+), 46 deletions(-) diff --git a/vrobbler/apps/beers/models.py b/vrobbler/apps/beers/models.py index 8f49f1c..12c46c7 100644 --- a/vrobbler/apps/beers/models.py +++ b/vrobbler/apps/beers/models.py @@ -7,7 +7,7 @@ from django_extensions.db.models import TimeStampedModel from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFit from scrobbles.dataclasses import BeerLogData -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin from vrobbler.apps.beers.untappd import ( get_beer_from_untappd_id, get_rating_from_soup, @@ -75,8 +75,8 @@ class Beer(ScrobblableMixin): return self.producer.name @property - def verb(self) -> str: - return "Drinking" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Drinking", tags="beer") @property def beeradvocate_link(self) -> str: diff --git a/vrobbler/apps/boardgames/models.py b/vrobbler/apps/boardgames/models.py index 912a737..1757a13 100644 --- a/vrobbler/apps/boardgames/models.py +++ b/vrobbler/apps/boardgames/models.py @@ -13,7 +13,7 @@ from django_extensions.db.models import TimeStampedModel from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFit from scrobbles.dataclasses import BoardGameLogData -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin logger = logging.getLogger(__name__) BNULL = {"blank": True, "null": True} @@ -101,8 +101,8 @@ class BoardGame(ScrobblableMixin): return BoardGameLogData @property - def verb(self) -> str: - return "Playing" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Playing", tags="game_die") def primary_image_url(self) -> str: url = "" diff --git a/vrobbler/apps/books/models.py b/vrobbler/apps/books/models.py index aac0434..ed23d90 100644 --- a/vrobbler/apps/books/models.py +++ b/vrobbler/apps/books/models.py @@ -19,6 +19,7 @@ from imagekit.processors import ResizeToFit from scrobbles.mixins import ( LongPlayScrobblableMixin, ObjectWithGenres, + ScrobblableConstants, ScrobblableMixin, ) from scrobbles.utils import get_scrobbles_for_media @@ -135,8 +136,8 @@ class Book(LongPlayScrobblableMixin): return f" by {self.author}" @property - def verb(self) -> str: - return "Reading" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Reading", tags="book") @property def logdata_cls(self): diff --git a/vrobbler/apps/lifeevents/models.py b/vrobbler/apps/lifeevents/models.py index 0b42ae6..03e6613 100644 --- a/vrobbler/apps/lifeevents/models.py +++ b/vrobbler/apps/lifeevents/models.py @@ -2,7 +2,7 @@ from django.apps import apps from django.db import models from django.urls import reverse from scrobbles.dataclasses import LifeEventLogData -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin BNULL = {"blank": True, "null": True} @@ -23,8 +23,8 @@ class LifeEvent(ScrobblableMixin): return LifeEventLogData @property - def verb(self) -> str: - return "Experiencing" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Experiencing", tags="camping") @classmethod def find_or_create(cls, title: str) -> "LifeEvent": diff --git a/vrobbler/apps/locations/models.py b/vrobbler/apps/locations/models.py index 7d578c5..1fd1745 100644 --- a/vrobbler/apps/locations/models.py +++ b/vrobbler/apps/locations/models.py @@ -8,7 +8,7 @@ from django.conf import settings from django.db import models from django.urls import reverse from django_extensions.db.models import TimeStampedModel -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin logger = logging.getLogger(__name__) BNULL = {"blank": True, "null": True} @@ -91,8 +91,10 @@ class GeoLocation(ScrobblableMixin): return "" @property - def verb(self) -> str: - return "Going" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants( + verb="Going", tags="world_map", priority="low" + ) def loc_diff(self, old_lat_lon: tuple) -> tuple: return ( diff --git a/vrobbler/apps/moods/models.py b/vrobbler/apps/moods/models.py index 8bb4a1d..136d1f9 100644 --- a/vrobbler/apps/moods/models.py +++ b/vrobbler/apps/moods/models.py @@ -5,7 +5,7 @@ from django.db import models from django.urls import reverse from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFit -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin from vrobbler.apps.scrobbles.dataclasses import MoodLogData @@ -46,8 +46,8 @@ class Mood(ScrobblableMixin): return "" @property - def verb(self) -> str: - return "Feeling" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Feeling", tags="thinking") @property def logdata_cls(self): diff --git a/vrobbler/apps/music/models.py b/vrobbler/apps/music/models.py index 54cb33e..a362a07 100644 --- a/vrobbler/apps/music/models.py +++ b/vrobbler/apps/music/models.py @@ -17,7 +17,7 @@ from imagekit.processors import ResizeToFit from music.allmusic import get_allmusic_slug, scrape_data_from_allmusic from music.bandcamp import get_bandcamp_slug from music.theaudiodb import lookup_album_from_tadb, lookup_artist_from_tadb -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin logger = logging.getLogger(__name__) BNULL = {"blank": True, "null": True} @@ -429,8 +429,8 @@ class Track(ScrobblableMixin): return self.artist @property - def verb(self) -> str: - return "Listening" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Listening", tags="headphones") @property def mb_link(self): diff --git a/vrobbler/apps/scrobbles/dataclasses.py b/vrobbler/apps/scrobbles/dataclasses.py index 5bfd701..716203d 100644 --- a/vrobbler/apps/scrobbles/dataclasses.py +++ b/vrobbler/apps/scrobbles/dataclasses.py @@ -172,10 +172,10 @@ class VideoLogData(JSONDataclass): @dataclass class VideoGameLogData(LongPlayLogData): - serial_scrobble_id: Optional[int] - long_play_complete: bool = False - console: str = "" - emulated: bool = False + serial_scrobble_id: Optional[int] = None + long_play_complete: Optional[bool] = False + console: Optional[str] = None + emulated: Optional[bool] = False emulator: Optional[str] = None diff --git a/vrobbler/apps/scrobbles/mixins.py b/vrobbler/apps/scrobbles/mixins.py index d236bfe..aecac9f 100644 --- a/vrobbler/apps/scrobbles/mixins.py +++ b/vrobbler/apps/scrobbles/mixins.py @@ -1,3 +1,4 @@ +from dataclasses import dataclass import logging from typing import Optional from uuid import uuid4 @@ -16,6 +17,23 @@ BNULL = {"blank": True, "null": True} logger = logging.getLogger(__name__) +@dataclass +class ScrobblableConstants: + verb: str + tags: str + priority: str + + def __init__( + self, + verb: str = "Scrobbling", + tags: str = "green_square", + priority: str = "default", + ): + self.verb = verb + self.tags = tags + self.priority = priority + + class Genre(TagBase): source = models.CharField(max_length=255, **BNULL) @@ -81,8 +99,8 @@ class ScrobblableMixin(TimeStampedModel): return reverse("scrobbles:start", kwargs={"uuid": self.uuid}) @property - def verb(self) -> str: - return "Scrobbling" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants() @property def primary_image_url(self) -> str: diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 87d45ec..bb57972 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -1192,9 +1192,9 @@ class Scrobble(TimeStampedModel): profile.ntfy_url, data=f"{scrobble.media_obj}".encode(encoding="utf-8"), headers={ - "Title": scrobble.media_obj.verb, + "Title": scrobble.media_obj.strings.verb, "Priority": "default", - "Tags": "loudspeaker", + "Tags": scrobble.media_obj.strings.tags, }, ) diff --git a/vrobbler/apps/sports/models.py b/vrobbler/apps/sports/models.py index e61bbe4..0d44d10 100644 --- a/vrobbler/apps/sports/models.py +++ b/vrobbler/apps/sports/models.py @@ -7,7 +7,7 @@ from django.db import models from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django_extensions.db.models import TimeStampedModel -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin from sports.utils import get_players_from_event, get_round_name_from_event logger = logging.getLogger(__name__) @@ -134,8 +134,8 @@ class SportEvent(ScrobblableMixin): return self.round.season.league @property - def verb(self) -> str: - return "Watching" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Watching", tags="trophy") @property def sportsdb_link(self): diff --git a/vrobbler/apps/tasks/models.py b/vrobbler/apps/tasks/models.py index 32b2511..e60f5f9 100644 --- a/vrobbler/apps/tasks/models.py +++ b/vrobbler/apps/tasks/models.py @@ -6,7 +6,7 @@ from django.apps import apps from django.db import models from django.urls import reverse from scrobbles.dataclasses import JSONDataclass -from scrobbles.mixins import LongPlayScrobblableMixin +from scrobbles.mixins import LongPlayScrobblableMixin, ScrobblableConstants BNULL = {"blank": True, "null": True} @@ -39,8 +39,8 @@ class Task(LongPlayScrobblableMixin): return reverse("tasks:task_detail", kwargs={"slug": self.uuid}) @property - def verb(self) -> str: - return "Doing" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Doing", tags="white_check_mark") # @property # def logdata_cls(self): diff --git a/vrobbler/apps/trails/models.py b/vrobbler/apps/trails/models.py index 8247b5f..7f15a79 100644 --- a/vrobbler/apps/trails/models.py +++ b/vrobbler/apps/trails/models.py @@ -3,7 +3,7 @@ from django.apps import apps from django.db import models from django.urls import reverse from scrobbles.dataclasses import TrailLogData -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin from locations.models import GeoLocation BNULL = {"blank": True, "null": True} @@ -39,8 +39,8 @@ class Trail(ScrobblableMixin): return TrailLogData @property - def verb(self) -> str: - return "Moving" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Moving", tags="runner") @classmethod def find_or_create(cls, title: str) -> "Trail": diff --git a/vrobbler/apps/videogames/models.py b/vrobbler/apps/videogames/models.py index 07b90d7..43182f0 100644 --- a/vrobbler/apps/videogames/models.py +++ b/vrobbler/apps/videogames/models.py @@ -9,7 +9,7 @@ from django_extensions.db.models import TimeStampedModel from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFit from scrobbles.dataclasses import VideoGameLogData -from scrobbles.mixins import LongPlayScrobblableMixin +from scrobbles.mixins import LongPlayScrobblableMixin, ScrobblableConstants from scrobbles.utils import get_scrobbles_for_media from videogames.igdb import lookup_game_id_from_gdb @@ -145,8 +145,8 @@ class VideoGame(LongPlayScrobblableMixin): return f" On {self.platforms.first()}" @property - def verb(self) -> str: - return "Sessioning" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Sessioning", tags="joystick") @property def primary_image_url(self) -> str: diff --git a/vrobbler/apps/videos/models.py b/vrobbler/apps/videos/models.py index 1476879..d45500b 100644 --- a/vrobbler/apps/videos/models.py +++ b/vrobbler/apps/videos/models.py @@ -12,7 +12,11 @@ from django_extensions.db.models import TimeStampedModel from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFit from music.constants import JELLYFIN_POST_KEYS -from scrobbles.mixins import ObjectWithGenres, ScrobblableMixin +from scrobbles.mixins import ( + ObjectWithGenres, + ScrobblableConstants, + ScrobblableMixin, +) from taggit.managers import TaggableManager from videos.imdb import lookup_video_from_imdb @@ -197,8 +201,8 @@ class Video(ScrobblableMixin): return url @property - def verb(self) -> str: - return "Watching" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Watching", tags="movie_camera") def fix_metadata(self, force_update=False): imdb_dict = lookup_video_from_imdb(self.imdb_id) diff --git a/vrobbler/apps/webpages/models.py b/vrobbler/apps/webpages/models.py index 201f05d..13d5ce8 100644 --- a/vrobbler/apps/webpages/models.py +++ b/vrobbler/apps/webpages/models.py @@ -13,7 +13,7 @@ from django.contrib.auth import get_user_model from django.db import models from django.urls import reverse from htmldate import find_date -from scrobbles.mixins import ScrobblableMixin +from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin logger = logging.getLogger(__name__) BNULL = {"blank": True, "null": True} @@ -86,8 +86,8 @@ class WebPage(ScrobblableMixin): return int(self.estimated_time_to_read_in_seconds / 60) @property - def verb(self) -> str: - return "Browsing" + def strings(self) -> ScrobblableConstants: + return ScrobblableConstants(verb="Browsing", tags="earth_americas") @property def subtitle(self):