From 722c75b52572a97a66d65f0fd24eda23786212e5 Mon Sep 17 00:00:00 2001 From: Negima1072 Date: Tue, 24 Sep 2024 20:33:16 +0900 Subject: [PATCH] fix: types for channel (#58) --- niconico/objects/common.py | 10 ++++++++++ niconico/objects/user/__init__.py | 14 ++------------ niconico/objects/video/__init__.py | 9 +++++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/niconico/objects/common.py b/niconico/objects/common.py index 222e99f..52a2201 100644 --- a/niconico/objects/common.py +++ b/niconico/objects/common.py @@ -25,3 +25,13 @@ class EssentialUser(BaseModel): id_: int = Field(..., alias="id") nickname: str icons: UserIcon + + +class EssentialChannel(BaseModel): + """A class that represents a essential channel object.""" + + id_: str = Field(..., alias="id") + name: str + description: str + thumbnail_url: str = Field(..., alias="thumbnailUrl") + thumbnail_small_url: str = Field(..., alias="thumbnailSmallUrl") diff --git a/niconico/objects/user/__init__.py b/niconico/objects/user/__init__.py index f77edc5..d47505c 100644 --- a/niconico/objects/user/__init__.py +++ b/niconico/objects/user/__init__.py @@ -6,7 +6,7 @@ from pydantic import BaseModel, Field -from niconico.objects.common import UserIcon +from niconico.objects.common import EssentialChannel, UserIcon from niconico.objects.video import EssentialVideo, MylistItem, MylistSortKey, MylistSortOrder, Owner @@ -32,16 +32,6 @@ class UserLevel(BaseModel): current_level_experience: int = Field(..., alias="currentLevelExperience") -class UserChannel(BaseModel): - """A class that represents a user channel object.""" - - id_: str = Field(..., alias="id") - name: str - description: str - thumbnail_url: str = Field(..., alias="thumbnailUrl") - thumbnail_small_url: str = Field(..., alias="thumbnailSmallUrl") - - class UserSNS(BaseModel): """A class that represents the SNS of a user.""" @@ -71,7 +61,7 @@ class NicoUser(BaseModel): followee_count: int = Field(..., alias="followeeCount") follower_count: int = Field(..., alias="followerCount") user_level: UserLevel = Field(..., alias="userLevel") - user_channel: UserChannel | None = Field(..., alias="userChannel") + user_channel: EssentialChannel | None = Field(..., alias="userChannel") is_nicorepo_readable: bool = Field(..., alias="isNicorepoReadable") sns: list[UserSNS] = Field(..., alias="sns") cover_image: UserCoverImage | None = Field(..., alias="coverImage") diff --git a/niconico/objects/video/__init__.py b/niconico/objects/video/__init__.py index 62f3eab..effd6f7 100644 --- a/niconico/objects/video/__init__.py +++ b/niconico/objects/video/__init__.py @@ -6,7 +6,7 @@ from pydantic import BaseModel, Field -from niconico.objects.common import EssentialUser +from niconico.objects.common import EssentialChannel, EssentialUser class VideoCount(BaseModel): @@ -32,7 +32,7 @@ class Owner(BaseModel): """A class that represents the owner of a video.""" owner_type: Literal["user", "channel", "hidden"] = Field(..., alias="ownerType") - type_: Literal["user", "unknown"] = Field(..., alias="type") + type_: Literal["user", "channel", "unknown"] = Field(..., alias="type") visibility: Literal["visible", "hidden"] id_: str | None = Field(..., alias="id") name: str | None @@ -126,9 +126,10 @@ class Mylist(BaseModel): class SeriesOwner(BaseModel): """A class that represents the owner of a series.""" - type_: Literal["user"] = Field(..., alias="type") + type_: Literal["user", "channel"] = Field(..., alias="type") id_: str = Field(..., alias="id") - user: EssentialUser + user: EssentialUser | None + channel: EssentialChannel | None class SeriesDetail(BaseModel):