mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Quality options for Streamlink (#103)
* added quality options for streamlink * wrong default value
This commit is contained in:
parent
7db45aa7f2
commit
6ec8f6e032
8 changed files with 188 additions and 10 deletions
|
@ -95,7 +95,8 @@ SOURCES += \
|
|||
src/widgets/basewidget.cpp \
|
||||
src/widgets/resizingtextedit.cpp \
|
||||
src/completionmanager.cpp \
|
||||
src/widgets/logindialog.cpp
|
||||
src/widgets/logindialog.cpp \
|
||||
src/widgets/qualitypopup.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/asyncexec.hpp \
|
||||
|
@ -155,7 +156,8 @@ HEADERS += \
|
|||
src/widgets/accountpopup.hpp \
|
||||
src/util/distancebetweenpoints.hpp \
|
||||
src/widgets/basewidget.hpp \
|
||||
src/completionmanager.hpp
|
||||
src/completionmanager.hpp \
|
||||
src/widgets/qualitypopup.h
|
||||
|
||||
PRECOMPILED_HEADER =
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ SettingsManager::SettingsManager()
|
|||
, showTimestamps("/appearance/messages/showTimestamps", true)
|
||||
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
|
||||
, showBadges("/appearance/messages/showBadges", true)
|
||||
, streamlinkPath("/behaviour/streamlinkPath", "")
|
||||
, streamlinkPath("/behaviour/streamlink/path", "")
|
||||
, preferredQuality("/behaviour/streamlink/quality", "Choose")
|
||||
, emoteScale(_settingsItems, "emoteScale", 1.0)
|
||||
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0)
|
||||
, scaleEmotesByLineHeight(_settingsItems, "scaleEmotesByLineHeight", false)
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
pajlada::Settings::Setting<bool> showBadges;
|
||||
|
||||
pajlada::Settings::Setting<std::string> streamlinkPath;
|
||||
pajlada::Settings::Setting<std::string> preferredQuality;
|
||||
|
||||
// Settings
|
||||
Setting<float> emoteScale;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "settingsmanager.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
#include "widgets/textinputdialog.hpp"
|
||||
#include "widgets/qualitypopup.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDockWidget>
|
||||
|
@ -293,15 +294,65 @@ void ChatWidget::doOpenPopupPlayer()
|
|||
void ChatWidget::doOpenStreamlink()
|
||||
{
|
||||
SettingsManager &settings = SettingsManager::getInstance();
|
||||
QString preferredQuality = QString::fromStdString(settings.preferredQuality.getValue()).toLower();
|
||||
// TODO(Confuseh): Default streamlink paths
|
||||
QString path = QString::fromStdString(settings.streamlinkPath.getValue());
|
||||
QString channel = QString::fromStdString(this->channelName.getValue());
|
||||
QFileInfo fileinfo = QFileInfo(path);
|
||||
// TODO(Confuseh): Add default checks for streamlink/livestreamer
|
||||
// TODO(Confuseh): Add quality switcher
|
||||
if (fileinfo.exists() && fileinfo.isExecutable()) {
|
||||
// works on leenux, idk whether it would work on whindows or mehOS
|
||||
QProcess::startDetached(
|
||||
path, QStringList({"twitch.tv/" + QString::fromStdString(this->channelName.getValue()),
|
||||
"best"}));
|
||||
if (preferredQuality != "choose") {
|
||||
QStringList args = {"twitch.tv/" + channel};
|
||||
QString quality = "";
|
||||
QString exclude = "";
|
||||
if (preferredQuality == "high") {
|
||||
exclude = ">720p30";
|
||||
quality = "high,best";
|
||||
} else if (preferredQuality == "medium") {
|
||||
exclude = ">540p30";
|
||||
quality = "medium,best";
|
||||
} else if (preferredQuality == "low") {
|
||||
exclude = ">360p30";
|
||||
quality = "low,best";
|
||||
} else if (preferredQuality == "audio only") {
|
||||
quality = "audio,audio_only";
|
||||
} else {
|
||||
quality = "best";
|
||||
}
|
||||
if (quality != "")
|
||||
args << quality;
|
||||
if (exclude != "")
|
||||
args << "--stream-sorting-excludes" << exclude;
|
||||
QProcess::startDetached(path, args);
|
||||
} else {
|
||||
QProcess *p = new QProcess();
|
||||
// my god that signal though
|
||||
QObject::connect(p, static_cast<void (QProcess::*)(int)>(&QProcess::finished), this,
|
||||
[path, channel, p](int exitCode) {
|
||||
if (exitCode > 0) {
|
||||
return;
|
||||
}
|
||||
QString lastLine = QString(p->readAllStandardOutput());
|
||||
lastLine = lastLine.trimmed().split('\n').last();
|
||||
if (lastLine.startsWith("Available streams: ")) {
|
||||
QStringList options;
|
||||
QStringList split = lastLine.right(lastLine.length() - 19).split(", ");
|
||||
|
||||
for (int i = split.length() - 1; i >= 0; i--) {
|
||||
QString option = split.at(i);
|
||||
if (option.endsWith(" (worst)")) {
|
||||
options << option.left(option.length() - 8);
|
||||
} else if (option.endsWith(" (best)")) {
|
||||
options << option.left(option.length() - 7);
|
||||
} else {
|
||||
options << option;
|
||||
}
|
||||
}
|
||||
|
||||
QualityPopup::showDialog(channel, path, options);
|
||||
}
|
||||
});
|
||||
p->start(path, {"twitch.tv/" + channel});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
53
src/widgets/qualitypopup.cpp
Normal file
53
src/widgets/qualitypopup.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "qualitypopup.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
QualityPopup::QualityPopup(const QString &channel, const QString &path, QStringList options)
|
||||
: channel(channel)
|
||||
, path(path)
|
||||
{
|
||||
this->ui.okButton.setText("OK");
|
||||
this->ui.cancelButton.setText("Cancel");
|
||||
|
||||
QObject::connect(&this->ui.okButton, &QPushButton::clicked, this, &QualityPopup::okButtonClicked);
|
||||
QObject::connect(&this->ui.cancelButton, &QPushButton::clicked, this,
|
||||
&QualityPopup::cancelButtonClicked);
|
||||
|
||||
this->ui.buttonBox.addButton(&this->ui.okButton, QDialogButtonBox::ButtonRole::AcceptRole);
|
||||
this->ui.buttonBox.addButton(&this->ui.cancelButton, QDialogButtonBox::ButtonRole::RejectRole);
|
||||
|
||||
for (int i = 0; i < options.length(); ++i) {
|
||||
this->ui.selector.addItem(options.at(i));
|
||||
}
|
||||
|
||||
this->ui.vbox.addWidget(&this->ui.selector);
|
||||
this->ui.vbox.addWidget(&this->ui.buttonBox);
|
||||
|
||||
this->setLayout(&this->ui.vbox);
|
||||
}
|
||||
|
||||
void QualityPopup::showDialog(const QString &channel, const QString &path, QStringList options) {
|
||||
static QualityPopup *instance = new QualityPopup(channel, path, options);
|
||||
|
||||
instance->show();
|
||||
instance->activateWindow();
|
||||
instance->raise();
|
||||
instance->setFocus();
|
||||
}
|
||||
|
||||
void QualityPopup::okButtonClicked() {
|
||||
QProcess::startDetached(this->path,
|
||||
{"twitch.tv/" + this->channel, this->ui.selector.currentText()});
|
||||
this->close();
|
||||
}
|
||||
|
||||
void QualityPopup::cancelButtonClicked()
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
39
src/widgets/qualitypopup.h
Normal file
39
src/widgets/qualitypopup.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef QUALITYPOPUP_H
|
||||
#define QUALITYPOPUP_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class QualityPopup : public QWidget
|
||||
{
|
||||
public:
|
||||
QualityPopup(const QString &channel, const QString &path, QStringList options);
|
||||
static void showDialog(const QString &channel, const QString &path, QStringList options);
|
||||
private:
|
||||
struct {
|
||||
QVBoxLayout vbox;
|
||||
QComboBox selector;
|
||||
QDialogButtonBox buttonBox;
|
||||
QPushButton okButton;
|
||||
QPushButton cancelButton;
|
||||
} ui;
|
||||
|
||||
QString channel;
|
||||
QString path;
|
||||
|
||||
void okButtonClicked();
|
||||
void cancelButtonClicked();
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
#endif // QUALITYPOPUP_H
|
|
@ -313,7 +313,14 @@ void SettingsDialog::addTabs()
|
|||
auto scroll = new QSlider(Qt::Horizontal);
|
||||
form->addRow("Mouse scroll speed:", scroll);
|
||||
|
||||
form->addRow("Streamlink Path", createLineEdit(settings.streamlinkPath));
|
||||
form->addRow("Streamlink path:", createLineEdit(settings.streamlinkPath));
|
||||
form->addRow(this->createCombobox(
|
||||
"Preferred quality:", settings.preferredQuality,
|
||||
{"Choose", "Source", "High", "Medium", "Low", "Audio only"},
|
||||
[](const QString &newValue, pajlada::Settings::Setting<std::string> &setting) {
|
||||
setting = newValue.toStdString();
|
||||
})
|
||||
);
|
||||
|
||||
// v->addWidget(scroll);
|
||||
// v->addStretch(1);
|
||||
|
@ -586,6 +593,27 @@ QHBoxLayout *SettingsDialog::createCombobox(
|
|||
return box;
|
||||
}
|
||||
|
||||
QHBoxLayout *SettingsDialog::createCombobox(
|
||||
const QString &title, pajlada::Settings::Setting<std::string> &setting, QStringList items,
|
||||
std::function<void(QString, pajlada::Settings::Setting<std::string> &)> cb)
|
||||
{
|
||||
auto box = new QHBoxLayout();
|
||||
auto label = new QLabel(title);
|
||||
auto widget = new QComboBox();
|
||||
widget->addItems(items);
|
||||
widget->setCurrentText(QString::fromStdString(setting.getValue()));
|
||||
|
||||
QObject::connect(widget, &QComboBox::currentTextChanged, this,
|
||||
[&setting, cb](const QString &newValue) {
|
||||
cb(newValue, setting); //
|
||||
});
|
||||
|
||||
box->addWidget(label);
|
||||
box->addWidget(widget);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
QLineEdit *SettingsDialog::createLineEdit(pajlada::Settings::Setting<std::string> &setting)
|
||||
{
|
||||
auto widget = new QLineEdit(QString::fromStdString(setting.getValue()));
|
||||
|
|
|
@ -60,6 +60,9 @@ private:
|
|||
QHBoxLayout *createCombobox(const QString &title, pajlada::Settings::Setting<int> &setting,
|
||||
QStringList items,
|
||||
std::function<void(QString, pajlada::Settings::Setting<int> &)> cb);
|
||||
QHBoxLayout *createCombobox(const QString &title, pajlada::Settings::Setting<std::string> &setting,
|
||||
QStringList items,
|
||||
std::function<void(QString, pajlada::Settings::Setting<std::string> &)> cb);
|
||||
QLineEdit *createLineEdit(pajlada::Settings::Setting<std::string> &setting);
|
||||
|
||||
void okButtonClicked();
|
||||
|
|
Loading…
Reference in a new issue