Simple streamlink support (#97)

* Simple streamlink support

Relies on settings entry & loads best available quality by default.
This commit is contained in:
Confuseh 2017-08-12 13:44:27 +01:00 committed by pajlada
parent 63f85e9bee
commit a6573e83e0
7 changed files with 39 additions and 1 deletions

View file

@ -14,6 +14,7 @@ SettingsManager::SettingsManager()
, showTimestamps("/appearance/messages/showTimestamps", true) , showTimestamps("/appearance/messages/showTimestamps", true)
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true) , showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
, showBadges("/appearance/messages/showBadges", true) , showBadges("/appearance/messages/showBadges", true)
, streamlinkPath("/behaviour/streamlinkPath", "")
, selectedUser(_settingsItems, "selectedUser", "") , selectedUser(_settingsItems, "selectedUser", "")
, emoteScale(_settingsItems, "emoteScale", 1.0) , emoteScale(_settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0) , mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0)

View file

@ -43,6 +43,8 @@ public:
pajlada::Settings::Setting<bool> showTimestampSeconds; pajlada::Settings::Setting<bool> showTimestampSeconds;
pajlada::Settings::Setting<bool> showBadges; pajlada::Settings::Setting<bool> showBadges;
pajlada::Settings::Setting<std::string> streamlinkPath;
// Settings // Settings
Setting<QString> selectedUser; Setting<QString> selectedUser;
Setting<float> emoteScale; Setting<float> emoteScale;

View file

@ -11,6 +11,8 @@
#include <QPainter> #include <QPainter>
#include <QShortcut> #include <QShortcut>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QFileInfo>
#include <QProcess>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
#include <functional> #include <functional>
@ -270,5 +272,20 @@ void ChatWidget::doOpenPopupPlayer()
<< QString::fromStdString(this->channelName.getValue()) << "/popout"; << QString::fromStdString(this->channelName.getValue()) << "/popout";
} }
void ChatWidget::doOpenStreamlink()
{
SettingsManager &settings = SettingsManager::getInstance();
QString path = QString::fromStdString(settings.streamlinkPath.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"}));
}
}
} // namespace widgets } // namespace widgets
} // namespace chatterino } // namespace chatterino

View file

@ -63,7 +63,6 @@ protected:
public: public:
ChannelManager &channelManager; ChannelManager &channelManager;
CompletionManager &completionManager; CompletionManager &completionManager;
private: private:
void setChannel(std::shared_ptr<Channel> newChannel); void setChannel(std::shared_ptr<Channel> newChannel);
void detachChannel(); void detachChannel();
@ -109,6 +108,9 @@ public slots:
// Open popup player of twitch channel in default browser // Open popup player of twitch channel in default browser
void doOpenPopupPlayer(); void doOpenPopupPlayer();
// Open twitch channel stream through streamlink
void doOpenStreamlink();
}; };
} // namespace widgets } // namespace widgets

View file

@ -50,6 +50,7 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
this->leftMenu.addAction("Clear chat", this->chatWidget, &ChatWidget::doClearChat); this->leftMenu.addAction("Clear chat", this->chatWidget, &ChatWidget::doClearChat);
this->leftMenu.addAction("Open channel", this->chatWidget, &ChatWidget::doOpenChannel); this->leftMenu.addAction("Open channel", this->chatWidget, &ChatWidget::doOpenChannel);
this->leftMenu.addAction("Open popup player", this->chatWidget, &ChatWidget::doOpenPopupPlayer); this->leftMenu.addAction("Open popup player", this->chatWidget, &ChatWidget::doOpenPopupPlayer);
this->leftMenu.addAction("Open in Streamlink", this->chatWidget, &ChatWidget::doOpenStreamlink);
this->leftMenu.addSeparator(); this->leftMenu.addSeparator();
this->leftMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes())); this->leftMenu.addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));
this->leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect())); this->leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));

View file

@ -312,6 +312,8 @@ void SettingsDialog::addTabs()
auto scroll = new QSlider(Qt::Horizontal); auto scroll = new QSlider(Qt::Horizontal);
form->addRow("Mouse scroll speed:", scroll); form->addRow("Mouse scroll speed:", scroll);
form->addRow("Streamlink Path", createLineEdit(settings.streamlinkPath));
// v->addWidget(scroll); // v->addWidget(scroll);
// v->addStretch(1); // v->addStretch(1);
// vbox->addLayout(v); // vbox->addLayout(v);
@ -583,6 +585,18 @@ QHBoxLayout *SettingsDialog::createCombobox(
return box; return box;
} }
QLineEdit *SettingsDialog::createLineEdit(pajlada::Settings::Setting<std::string> &setting)
{
auto widget = new QLineEdit(QString::fromStdString(setting.getValue()));
QObject::connect(widget, &QLineEdit::textChanged, this,
[&setting](const QString &newValue) {
setting = newValue.toStdString();
});
return widget;
}
void SettingsDialog::okButtonClicked() void SettingsDialog::okButtonClicked()
{ {
this->close(); this->close();

View file

@ -60,6 +60,7 @@ private:
QHBoxLayout *createCombobox(const QString &title, pajlada::Settings::Setting<int> &setting, QHBoxLayout *createCombobox(const QString &title, pajlada::Settings::Setting<int> &setting,
QStringList items, QStringList items,
std::function<void(QString, pajlada::Settings::Setting<int> &)> cb); std::function<void(QString, pajlada::Settings::Setting<int> &)> cb);
QLineEdit *createLineEdit(pajlada::Settings::Setting<std::string> &setting);
void okButtonClicked(); void okButtonClicked();
void cancelButtonClicked(); void cancelButtonClicked();