[media.jellyfin] Several improvements on schema definitions.

This commit is contained in:
Fabio Manganiello 2024-10-15 23:24:59 +02:00
parent 12c800b7a9
commit 3e61bd7a9b
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -11,6 +11,8 @@ logger = logging.getLogger(__name__)
class JellyfinSchema(Schema):
can_delete = fields.Boolean(attribute='CanDelete')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if 'id' in self.fields:
@ -133,12 +135,6 @@ class JellyfinTrackSchema(JellyfinSchema):
data['community_rating'] *= 10
return data
@post_dump
def _normalize_duration(self, data: dict, **_) -> dict:
if data.get('duration'):
data['duration'] //= 1e7
return data
@post_dump
def _add_title(self, data: dict, **_) -> dict:
if not data.get('title'):
@ -185,7 +181,6 @@ class JellyfinCollectionSchema(JellyfinSchema, MediaCollectionSchema):
class JellyfinVideoSchema(JellyfinSchema, MediaVideoSchema):
type = fields.Constant('video')
item_type = fields.Constant('video')
path = fields.String(attribute='Path')
duration = fields.Number(attribute='RunTimeTicks')
community_rating = fields.Number(attribute='CommunityRating')
container = fields.String(
@ -196,7 +191,6 @@ class JellyfinVideoSchema(JellyfinSchema, MediaVideoSchema):
},
)
critic_rating = fields.Number(attribute='CriticRating')
created_at = DateTime(attribute='DateCreated')
imdb_url = fields.URL(
attribute='ExternalUrl',
metadata={
@ -214,6 +208,7 @@ class JellyfinVideoSchema(JellyfinSchema, MediaVideoSchema):
super().__init__(*args, **kwargs)
self.fields['year'].attribute = 'ProductionYear'
self.fields['has_subtitles'].attribute = 'HasSubtitles'
self.fields['created_at'].attribute = 'DateCreated'
@post_dump
def _normalize_community_rating(self, data: dict, **_) -> dict:
@ -221,12 +216,6 @@ class JellyfinVideoSchema(JellyfinSchema, MediaVideoSchema):
data['community_rating'] *= 10
return data
@post_dump
def _normalize_duration(self, data: dict, **_) -> dict:
if data.get('duration'):
data['duration'] //= 1e7
return data
@pre_dump
def _extract_imdb_url(self, data: dict, **_) -> dict:
external_urls = data.get('ExternalUrls', [])