Skip to content

Commit

Permalink
Add is_featured for clips
Browse files Browse the repository at this point in the history
Add is_featured for clips model and endpoint
  • Loading branch information
chillymosh committed Sep 16, 2023
1 parent 012f551 commit 9628522
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Expand Up @@ -13,6 +13,8 @@ Master
- New models for the new methods have been added:
- :class:`~twitchio.ChannelFollowerEvent`
- :class:`~twitchio.ChannelFollowingEvent`
- New optional ``is_featured`` query parameter for :func:`~twitchio.PartialUser.fetch_clips`
- New attribute :attr:`~twitchio.Clip.is_featured` for :class:`~twitchio.Clip`

- Bug fixes
- Fix IndexError when getting prefix when empty message is sent in a reply.
Expand Down
4 changes: 2 additions & 2 deletions twitchio/ext/eventsub/models.py
Expand Up @@ -252,15 +252,15 @@ def __init__(
self, client: Union[EventSubClient, EventSubWSClient], _data: Union[str, dict], request: Optional[web.Request]
):
# we skip the super init here because reconnect events dont have headers or subscription information

self._client = client
self._raw_data = _data

if isinstance(_data, str):
data: dict = _loads(_data)
else:
data = _data

self.setup(data["payload"])

def setup(self, data: dict):
Expand Down
2 changes: 2 additions & 0 deletions twitchio/http.py
Expand Up @@ -574,6 +574,7 @@ async def get_clips(
ids: Optional[List[str]] = None,
started_at: Optional[datetime.datetime] = None,
ended_at: Optional[datetime.datetime] = None,
is_featured: Optional[bool] = None,
token: Optional[str] = None,
):
if started_at and started_at.tzinfo is None:
Expand All @@ -586,6 +587,7 @@ async def get_clips(
("game_id", game_id),
("started_at", started_at.isoformat() if started_at else None),
("ended_at", ended_at.isoformat() if ended_at else None),
("is_featured", str(is_featured) if is_featured is not None else None),
]
if ids:
q.extend(("id", id) for id in ids)
Expand Down
4 changes: 4 additions & 0 deletions twitchio/models.py
Expand Up @@ -293,6 +293,8 @@ class Clip:
vod_offset: Optional[:class:`int`]
The zero-based offset, in seconds, to where the clip starts in the video (VOD) or stream.
This can be None if the parent no longer exists
is_featured: :class:`bool`
Indicates if the clip is featured or not.
"""

__slots__ = (
Expand All @@ -310,6 +312,7 @@ class Clip:
"thumbnail_url",
"duration",
"vod_offset",
"is_featured",
)

def __init__(self, http: "TwitchHTTP", data: dict):
Expand All @@ -327,6 +330,7 @@ def __init__(self, http: "TwitchHTTP", data: dict):
self.thumbnail_url: str = data["thumbnail_url"]
self.duration: float = data["duration"]
self.vod_offset: Optional[int] = data["vod_offset"]
self.is_featured: bool = data["is_featured"]

def __repr__(self):
return f"<Clip id={self.id} broadcaster={self.broadcaster} creator={self.creator}>"
Expand Down
10 changes: 8 additions & 2 deletions twitchio/user.py
Expand Up @@ -335,7 +335,10 @@ async def create_clip(self, token: str, has_delay=False) -> dict:
return data[0]

async def fetch_clips(
self, started_at: Optional[datetime.datetime] = None, ended_at: Optional[datetime.datetime] = None
self,
started_at: Optional[datetime.datetime] = None,
ended_at: Optional[datetime.datetime] = None,
is_featured: Optional[bool] = None,
) -> List["Clip"]:
"""|coro|
Expand All @@ -350,14 +353,17 @@ async def fetch_clips(
ended_at: Optional[:class:`datetime.datetime`]
Ending date/time for returned clips.
If this is specified, started_at also must be specified; otherwise, the time period is ignored.
is_featured: Optional[:class:`bool`]
Optional bool to only return only featured clips or not featured clips.
Returns
--------
List[:class:`twitchio.Clip`]
"""
from .models import Clip

data = await self._http.get_clips(self.id, started_at=started_at, ended_at=ended_at)
data = await self._http.get_clips(self.id, started_at=started_at, ended_at=ended_at, is_featured=is_featured)

return [Clip(self._http, x) for x in data]

Expand Down

0 comments on commit 9628522

Please sign in to comment.