Added clip creation support 🎬 (#2271)

You can create clips with `/clip` command, `Alt+X` keybind or `Create a clip` option in split header's context menu. This requires a new authentication scope so re-authentication will be required to use it.

Co-authored-by: Leon Richardt <leon.richardt@gmail.com>
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Paweł
2021-01-17 14:47:34 +01:00
committed by GitHub
parent 0542b81a03
commit cfcac99ae6
12 changed files with 253 additions and 8 deletions
+54
View File
@@ -359,6 +359,60 @@ void Helix::unfollowUser(QString userId, QString targetId,
.execute();
}
void Helix::createClip(QString channelId,
ResultCallback<HelixClip> successCallback,
std::function<void(HelixClipError)> failureCallback,
std::function<void()> finallyCallback)
{
QUrlQuery urlQuery;
urlQuery.addQueryItem("broadcaster_id", channelId);
this->makeRequest("clips", urlQuery)
.type(NetworkRequestType::Post)
.header("Content-Type", "application/json")
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
auto root = result.parseJson();
auto data = root.value("data");
if (!data.isArray())
{
failureCallback(HelixClipError::Unknown);
return Failure;
}
HelixClip clip(data.toArray()[0].toObject());
successCallback(clip);
return Success;
})
.onError([failureCallback](NetworkResult result) {
switch (result.status())
{
case 503: {
// Channel has disabled clip-creation, or channel has made cliops only creatable by followers and the user is not a follower (or subscriber)
failureCallback(HelixClipError::ClipsDisabled);
}
break;
case 401: {
// User does not have the required scope to be able to create clips, user must reauthenticate
failureCallback(HelixClipError::UserNotAuthenticated);
}
break;
default: {
qCDebug(chatterinoTwitch)
<< "Failed to create a clip: " << result.status()
<< result.getData();
failureCallback(HelixClipError::Unknown);
}
break;
}
})
.finally(finallyCallback)
.execute();
}
NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery)
{
assert(!url.startsWith("/"));
+25
View File
@@ -135,6 +135,23 @@ struct HelixGame {
}
};
struct HelixClip {
QString id; // clip slug
QString editUrl;
explicit HelixClip(QJsonObject jsonObject)
: id(jsonObject.value("id").toString())
, editUrl(jsonObject.value("edit_url").toString())
{
}
};
enum class HelixClipError {
Unknown,
ClipsDisabled,
UserNotAuthenticated,
};
class Helix final : boost::noncopyable
{
public:
@@ -185,14 +202,22 @@ public:
void getGameById(QString gameId, ResultCallback<HelixGame> successCallback,
HelixFailureCallback failureCallback);
// https://dev.twitch.tv/docs/api/reference#create-user-follows
void followUser(QString userId, QString targetId,
std::function<void()> successCallback,
HelixFailureCallback failureCallback);
// https://dev.twitch.tv/docs/api/reference#delete-user-follows
void unfollowUser(QString userId, QString targetlId,
std::function<void()> successCallback,
HelixFailureCallback failureCallback);
// https://dev.twitch.tv/docs/api/reference#create-clip
void createClip(QString channelId,
ResultCallback<HelixClip> successCallback,
std::function<void(HelixClipError)> failureCallback,
std::function<void()> finallyCallback);
void update(QString clientId, QString oauthToken);
static void initialize();
+10 -2
View File
@@ -90,7 +90,7 @@ URL: https://dev.twitch.tv/docs/api/reference#get-streams
* `NotificationController` to provide notifications for channels you might not have open in Chatterino, but are still interested in getting notifications for
### Follow User
URL: https://dev.twitch.tv/docs/api/reference#create-user-follows
URL: https://dev.twitch.tv/docs/api/reference#create-user-follows
Requires `user:edit:follows` scope
* We implement this in `providers/twitch/api/Helix.cpp followUser`
@@ -99,7 +99,7 @@ Requires `user:edit:follows` scope
* `controllers/commands/CommandController.cpp` in /follow command
### Unfollow User
URL: https://dev.twitch.tv/docs/api/reference#delete-user-follows
URL: https://dev.twitch.tv/docs/api/reference#delete-user-follows
Requires `user:edit:follows` scope
* We implement this in `providers/twitch/api/Helix.cpp unfollowUser`
@@ -107,6 +107,14 @@ Requires `user:edit:follows` scope
* `widgets/dialogs/UserInfoPopup.cpp` to unfollow a user by unticking follow checkbox in usercard
* `controllers/commands/CommandController.cpp` in /unfollow command
### Create Clip
URL: https://dev.twitch.tv/docs/api/reference#create-clip
Requires `clips:edit` scope
* We implement this in `providers/twitch/api/Helix.cpp createClip`
Used in:
* `TwitchChannel` to create a clip of a live broadcast
## TMI
The TMI api is undocumented.