Skip to content

Commit 45af4cf

Browse files
committed
Add new args to create_clip and deprecate has_delay
1 parent 2215ee8 commit 45af4cf

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

docs/getting-started/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Changelog
1818
This replaces :func:`~twitchio.PartialUser.fetch_hype_train_events` which has been deprecated
1919
- Added - :attr:`~twitchio.Chatter.lead_moderator`
2020
- Added - :func:`~twitchio.ext.commands.is_lead_moderator` guard
21+
- Added - New optional title and duration arguments for :func:`~twitchio.PartialUser.create_clip`
2122

2223
- Changes
2324
- :attr:`~twitchio.Chatter.moderator` returns True for Lead Moderator role.
25+
- :func:`~twitchio.PartialUser.create_clip` `has_delay` argument has been deprecated.
2426

2527
- Bug fixes
2628
- Fix :func:`~twitchio.utils.setup_logging` breaking coloured formatting on `CRITICAL` logging level

twitchio/http.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,9 +1337,15 @@ async def post_create_clip(
13371337
*,
13381338
broadcaster_id: str | int,
13391339
token_for: str | PartialUser,
1340-
has_delay: bool = False,
1340+
title: str | None = None,
1341+
duration: float | None = None,
13411342
) -> CreateClipResponse:
1342-
params = {"broadcaster_id": broadcaster_id, "has_delay": has_delay}
1343+
params: dict[str, str | float] = {"broadcaster_id": broadcaster_id}
1344+
1345+
if title is not None:
1346+
params["title"] = title
1347+
if duration is not None:
1348+
params["duration"] = duration
13431349

13441350
route: Route = Route("POST", "clips", params=params, token_for=token_for)
13451351
return await self.request_json(route)

twitchio/models/clips.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ async def fetch_video(self) -> Video | None:
166166

167167

168168
class CreatedClip:
169+
"""Represents a Created Clip
170+
171+
Attributes
172+
-----------
173+
id: str
174+
An ID that uniquely identifies the clip.
175+
edit_url: str
176+
A URL that you can use to edit the clip's title, identify the part of the clip to publish, and publish the clip. `Learn More <https://help.twitch.tv/s/article/how-to-use-clips>`_
177+
178+
The URL is valid for up to 24 hours or until the clip is published, whichever comes first.
179+
"""
180+
169181
__slots__ = ("edit_url", "id")
170182

171183
def __init__(self, data: CreateClipResponseData) -> None:

twitchio/user.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,12 @@ async def update_chatter_color(self, color: str) -> None:
12361236
return await self._http.put_user_chat_color(user_id=self.id, color=color, token_for=self.id)
12371237

12381238
async def create_clip(
1239-
self, *, token_for: str | PartialUser, has_delay: bool = False
1239+
self,
1240+
*,
1241+
token_for: str | PartialUser,
1242+
has_delay: bool = False,
1243+
title: str | None = None,
1244+
duration: float | None = None,
12401245
) -> CreatedClip: # TODO Test this with non broadcaster token
12411246
"""|coro|
12421247
@@ -1248,7 +1253,7 @@ async def create_clip(
12481253
This may occur if you begin capturing the clip near the beginning or end of the stream.
12491254
12501255
By default, Twitch publishes up to the last 30 seconds of the 90 seconds window and provides a default title for the clip.
1251-
To specify the title and the portion of the 90 seconds window that's used for the clip, use the URL in the CreatedClip's ``edit_url`` attribute.
1256+
You can now specify the title and the duration via this method, or specify the title and the portion of the 90 seconds window that's used for the clip by using the URL in the CreatedClip's ``edit_url`` attribute.
12521257
You can specify a clip that's from 5 seconds to 60 seconds in length. The URL is valid for up to 24 hours or until the clip is published, whichever comes first.
12531258
12541259
Creating a clip is an asynchronous process that can take a short amount of time to complete.
@@ -1258,23 +1263,38 @@ async def create_clip(
12581263
.. note::
12591264
Requires a user access token that includes the ``clips:edit`` scope.
12601265
1266+
1267+
.. warning::
1268+
The `has_delay` argument has been removed by Twitch and no longer has any effect.
1269+
It has been retained to avoid breaking changes for users who still have it set.
1270+
12611271
Parameters
12621272
----------
1273+
title: str | None
1274+
The title of the clip.
1275+
duration: float | None
1276+
The length of the clip in seconds. Possible values range from 5 to 60 inclusively with a precision of 0.1. The default is 30
12631277
has_delay: bool
1264-
A Boolean value that determines whether the API captures the clip at the moment the viewer requests it or after a delay.
1265-
If False (default), Twitch captures the clip at the moment the viewer requests it (this is the same clip experience as the Twitch UX).
1266-
If True, Twitch adds a delay before capturing the clip (this basically shifts the capture window to the right slightly).
1278+
This has been been removed by Twitch and no longer has any effect.
1279+
It has been retained to avoid breaking changes for users who still have it set.
12671280
token_for: str | PartialUser
12681281
User access token that includes the ``clips:edit`` scope.
12691282
12701283
Returns
12711284
-------
12721285
CreatedClip
12731286
The CreatedClip object.
1287+
Raises
1288+
------
1289+
ValueError
1290+
Clip duration must be between 5 and 60, with precision of 0.1
12741291
"""
1292+
if duration is not None and not (5 <= duration <= 60):
1293+
raise ValueError("Clip duration must be between 5 and 60, with precision of 0.1")
1294+
12751295
from .models.clips import CreatedClip
12761296

1277-
data = await self._http.post_create_clip(broadcaster_id=self.id, token_for=token_for, has_delay=has_delay)
1297+
data = await self._http.post_create_clip(broadcaster_id=self.id, token_for=token_for, title=title, duration=duration)
12781298
return CreatedClip(data["data"][0])
12791299

12801300
def fetch_clips(

0 commit comments

Comments
 (0)