From 185980f8a2d94b61265e84362f1d76bfe2abab7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Fri, 12 Feb 2021 14:16:44 +0100 Subject: [PATCH] Added /streamlink command (#2443) Co-authored-by: pajlada --- CHANGELOG.md | 1 + .../commands/CommandController.cpp | 29 +++++++++++++++++++ src/util/StreamLink.cpp | 3 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bc0ff3fc..18ec15e9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - Minor: Update the listing of top-level domains. (#2345) - Minor: Properly respect RECONNECT messages from Twitch (#2347) - Minor: Added human-readable formatting to remaining timeout duration. (#2398) +- Minor: Added `/streamlink` command. Usage: `/streamlink `. You can also use the command without arguments in any twitch channel to open it in streamlink. (#2443) - Bugfix: Fix crash occurring when pressing Escape in the Color Picker Dialog (#1843) - Bugfix: Fix bug where the "check user follow state" event could trigger a network request requesting the user to follow or unfollow a user. By itself its quite harmless as it just repeats to Twitch the same follow state we had, so no follows should have been lost by this but it meant there was a rogue network request that was fired that could cause a crash (#1906) - Bugfix: /usercard command will now respect the "Automatically close user popup" setting (#1918) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 14b98763c..f1b7479a7 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -17,6 +17,7 @@ #include "singletons/WindowManager.hpp" #include "util/CombinePath.hpp" #include "util/FormatTime.hpp" +#include "util/StreamLink.hpp" #include "util/Twitch.hpp" #include "widgets/Window.hpp" #include "widgets/dialogs/UserInfoPopup.hpp" @@ -538,6 +539,34 @@ void CommandController::initialize(Settings &, Paths &paths) return ""; }); + + this->registerCommand( + "/streamlink", [](const QStringList &words, ChannelPtr channel) { + if (words.size() < 2) + { + if (!channel->isTwitchChannel() || channel->isEmpty()) + { + channel->addMessage(makeSystemMessage( + "Usage: /streamlink . You can also use the " + "command without arguments in any twitch channel to " + "open it in streamlink.")); + } + else + { + channel->addMessage( + makeSystemMessage(QString("Opening %1 in streamlink...") + .arg(channel->getName()))); + openStreamlinkForChannel(channel->getName()); + } + return ""; + } + + channel->addMessage(makeSystemMessage( + QString("Opening %1 in streamlink...").arg(words[1]))); + openStreamlinkForChannel(words[1]); + + return ""; + }); } void CommandController::save() diff --git a/src/util/StreamLink.cpp b/src/util/StreamLink.cpp index b47297aa9..46463724e 100644 --- a/src/util/StreamLink.cpp +++ b/src/util/StreamLink.cpp @@ -187,8 +187,7 @@ void openStreamlink(const QString &channelURL, const QString &quality, arguments << quality; } - bool res = QProcess::startDetached(getStreamlinkProgram() + " " + - QString(arguments.join(' '))); + bool res = QProcess::startDetached(getStreamlinkProgram(), arguments); if (!res) {