mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Fix quotation and handling of additional streamlink options (#2495)
This commit is contained in:
parent
1eb6aa64db
commit
f53b0a9e0f
|
@ -54,7 +54,7 @@
|
|||
- Minor: Added human-readable formatting to remaining timeout duration. (#2398)
|
||||
- Minor: Update emojis version to 13 (2020). (#1555)
|
||||
- Minor: Remove EmojiOne 2 and 3 due to license restrictions. (#1555)
|
||||
- Minor: Added `/streamlink` command. Usage: `/streamlink <channel>`. You can also use the command without arguments in any twitch channel to open it in streamlink. (#2443)
|
||||
- Minor: Added `/streamlink` command. Usage: `/streamlink <channel>`. You can also use the command without arguments in any twitch channel to open it in streamlink. (#2443, #2495)
|
||||
- Minor: Humanized all numbers visible to end-users. (#2488)
|
||||
- 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)
|
||||
|
|
|
@ -246,6 +246,7 @@ SOURCES += \
|
|||
src/util/RapidjsonHelpers.cpp \
|
||||
src/util/StreamerMode.cpp \
|
||||
src/util/StreamLink.cpp \
|
||||
src/util/SplitCommand.cpp \
|
||||
src/util/Twitch.cpp \
|
||||
src/util/WindowsHelper.cpp \
|
||||
src/widgets/AccountSwitchPopup.cpp \
|
||||
|
|
93
src/util/SplitCommand.cpp
Normal file
93
src/util/SplitCommand.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Intel Corporation.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "SplitCommand.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QStringView>
|
||||
|
||||
QStringList chatterino::splitCommand(QStringView command)
|
||||
{
|
||||
QStringList args;
|
||||
QString tmp;
|
||||
int quoteCount = 0;
|
||||
bool inQuote = false;
|
||||
|
||||
// handle quoting. tokens can be surrounded by double quotes
|
||||
// "hello world". three consecutive double quotes represent
|
||||
// the quote character itself.
|
||||
for (int i = 0; i < command.size(); ++i)
|
||||
{
|
||||
if (command.at(i) == QLatin1Char('"'))
|
||||
{
|
||||
++quoteCount;
|
||||
if (quoteCount == 3)
|
||||
{
|
||||
// third consecutive quote
|
||||
quoteCount = 0;
|
||||
tmp += command.at(i);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (quoteCount)
|
||||
{
|
||||
if (quoteCount == 1)
|
||||
inQuote = !inQuote;
|
||||
quoteCount = 0;
|
||||
}
|
||||
if (!inQuote && command.at(i).isSpace())
|
||||
{
|
||||
if (!tmp.isEmpty())
|
||||
{
|
||||
args += tmp;
|
||||
tmp.clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp += command.at(i);
|
||||
}
|
||||
}
|
||||
if (!tmp.isEmpty())
|
||||
args += tmp;
|
||||
|
||||
return args;
|
||||
}
|
15
src/util/SplitCommand.hpp
Normal file
15
src/util/SplitCommand.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <QStringList>
|
||||
#include <QStringView>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// Splits the string command into a list of tokens, and returns the list.
|
||||
// Tokens with spaces can be surrounded by double quotes;
|
||||
// three consecutive double quotes represent the quote character itself.
|
||||
//
|
||||
// Backported from QProcess 5.15
|
||||
QStringList splitCommand(QStringView command);
|
||||
|
||||
} // namespace chatterino
|
|
@ -3,6 +3,7 @@
|
|||
#include "Application.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/SplitCommand.hpp"
|
||||
#include "widgets/dialogs/QualityPopup.hpp"
|
||||
|
||||
#include <QErrorMessage>
|
||||
|
@ -170,22 +171,14 @@ void getStreamQualities(const QString &channelURL,
|
|||
void openStreamlink(const QString &channelURL, const QString &quality,
|
||||
QStringList extraArguments)
|
||||
{
|
||||
QStringList arguments;
|
||||
QStringList arguments = extraArguments << channelURL << quality;
|
||||
|
||||
// Remove empty arguments before appending additional streamlink options
|
||||
// as the options might purposely contain empty arguments
|
||||
arguments.removeAll(QString());
|
||||
|
||||
QString additionalOptions = getSettings()->streamlinkOpts.getValue();
|
||||
if (!additionalOptions.isEmpty())
|
||||
{
|
||||
arguments << getSettings()->streamlinkOpts;
|
||||
}
|
||||
|
||||
arguments.append(extraArguments);
|
||||
|
||||
arguments << channelURL;
|
||||
|
||||
if (!quality.isEmpty())
|
||||
{
|
||||
arguments << quality;
|
||||
}
|
||||
arguments << splitCommand(additionalOptions);
|
||||
|
||||
bool res = QProcess::startDetached(getStreamlinkProgram(), arguments);
|
||||
|
||||
|
|
Loading…
Reference in a new issue