Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: add new ImagePost FeedItem model #330

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
33 changes: 30 additions & 3 deletions tiktokpy/models/feed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import ClassVar, List
from typing import ClassVar, List, Optional

from pydantic import BaseModel, HttpUrl

Expand Down Expand Up @@ -80,8 +80,8 @@ class VideoInfo(BaseModel):
duration: int
ratio: str
cover: HttpUrl
play_addr: HttpUrl
download_addr: HttpUrl
play_addr: Optional[HttpUrl]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= None?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I assume you would keep this line as it is, right?

download_addr: Optional[HttpUrl]

class Config:
fields: ClassVar[dict] = {
Expand All @@ -94,6 +94,31 @@ def original_video_url(self) -> str:
return f"https://api2.musical.ly/aweme/v1/playwm/?video_id={self.id}"


class ImageUrls(BaseModel):
url_list: List[HttpUrl]

class Config:
fields: ClassVar[dict] = {"url_list": "urlList"}


class ImageInfo(BaseModel):
image_height: int
image_width: int
image_url: ImageUrls

class Config:
fields: ClassVar[dict] = {
"image_url": "imageURL",
"image_width": "imageWidth",
"image_height": "imageHeight",
}


class ImagePostlInfo(BaseModel):
cover: ImageInfo
images: List[ImageInfo]


class FeedItem(BaseModel):
id: str
desc: str
Expand All @@ -102,11 +127,13 @@ class FeedItem(BaseModel):
music: MusicInfo
stats: StatisticsInfo
video: VideoInfo
image_post: ImagePostlInfo = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry late response. I made it optional as it is not a property that is returned when it is a standard video.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now understand your comment.
Which way would you prefer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image_post: Optional[ImagePostlInfo]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Gr3gnov, I can not test it properly right now, I will try to push it tomorrow.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! And I will probably rename that class to ImagePostInfo.

challenges: List[ChallengeInfo] = []

class Config:
fields: ClassVar[dict] = {
"create_time": "createTime",
"image_post": "imagePost",
}


Expand Down