[scrobbles] Add metadata accessor
This commit is contained in:
@ -27,20 +27,20 @@ class JSONMetadata(object):
|
|||||||
@dataclass
|
@dataclass
|
||||||
class BoardGameScore(JSONMetadata):
|
class BoardGameScore(JSONMetadata):
|
||||||
user_id: int
|
user_id: int
|
||||||
score: Optional[int]
|
score: Optional[int] = None
|
||||||
win: Optional[bool]
|
win: Optional[bool] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BoardGameMetadata(JSONMetadata):
|
class BoardGameMetadata(JSONMetadata):
|
||||||
players: Optional[list[BoardGameScore]]
|
players: Optional[list[BoardGameScore]] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LifeEventMetadata(JSONMetadata):
|
class LifeEventMetadata(JSONMetadata):
|
||||||
location: Optional[str]
|
location: Optional[str] = None
|
||||||
geo_location_id: Optional[int]
|
geo_location_id: Optional[int] = None
|
||||||
participant_user_ids: Optional[list[int]]
|
participant_user_ids: Optional[list[int]] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __dict__(self):
|
def __dict__(self):
|
||||||
|
|||||||
@ -39,8 +39,11 @@ from videogames import retroarch
|
|||||||
from videogames.models import VideoGame
|
from videogames.models import VideoGame
|
||||||
from videos.models import Series, Video
|
from videos.models import Series, Video
|
||||||
from scrobbles.dataclasses import (
|
from scrobbles.dataclasses import (
|
||||||
|
BoardGameMetadata,
|
||||||
|
LifeEventMetadata,
|
||||||
ScrobbleMetadataDecoder,
|
ScrobbleMetadataDecoder,
|
||||||
ScrobbleMetadataEncoder,
|
ScrobbleMetadataEncoder,
|
||||||
|
VideoMetadata,
|
||||||
)
|
)
|
||||||
from webpages.models import WebPage
|
from webpages.models import WebPage
|
||||||
from lifeevents.models import LifeEvent
|
from lifeevents.models import LifeEvent
|
||||||
@ -602,6 +605,25 @@ class Scrobble(TimeStampedModel):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def metadata(self):
|
||||||
|
metadata_cls = None
|
||||||
|
if self.media_type == self.MediaType.LIFE_EVENT:
|
||||||
|
metadata_cls = LifeEventMetadata
|
||||||
|
if self.media_type == self.MediaType.BOARD_GAME:
|
||||||
|
metadata_cls = BoardGameMetadata
|
||||||
|
if self.media_type == self.MediaType.VIDEO:
|
||||||
|
metadata_cls = VideoMetadata
|
||||||
|
|
||||||
|
if not metadata_cls:
|
||||||
|
logger.warn(
|
||||||
|
f"Media type has no metadata class",
|
||||||
|
extra={"media_type": self.media_type, "scrobble_id": self.id},
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
return metadata_cls(**self.log)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tzinfo(self):
|
def tzinfo(self):
|
||||||
return pytz.timezone(self.timezone)
|
return pytz.timezone(self.timezone)
|
||||||
|
|||||||
Reference in New Issue
Block a user