Add some console error messages if streamlink path is bad

This commit is contained in:
Rasmus Karlsson 2017-12-17 15:46:22 +01:00
parent d182c22a4e
commit ef9aedb2cd

View file

@ -294,61 +294,78 @@ void Split::doOpenStreamlink()
QString path = QString::fromStdString(settings.streamlinkPath.getValue()); QString path = QString::fromStdString(settings.streamlinkPath.getValue());
QString channel = QString::fromStdString(this->channelName.getValue()); QString channel = QString::fromStdString(this->channelName.getValue());
QFileInfo fileinfo = QFileInfo(path); QFileInfo fileinfo = QFileInfo(path);
if (fileinfo.exists() && fileinfo.isExecutable()) {
if (preferredQuality != "choose") { if (path.isEmpty()) {
QStringList args = {"twitch.tv/" + channel}; debug::Log("[Split:doOpenStreamlink] No streamlink path selected in Settings");
QString quality = ""; return;
QString exclude = ""; }
if (preferredQuality == "high") {
exclude = ">720p30"; if (!fileinfo.exists()) {
quality = "high,best"; debug::Log("[Split:doOpenStreamlink] Streamlink path ({}) is invalid, file does not exist",
} else if (preferredQuality == "medium") { path);
exclude = ">540p30"; return;
quality = "medium,best"; }
} else if (preferredQuality == "low") {
exclude = ">360p30"; if (fileinfo.isDir() || !fileinfo.isExecutable()) {
quality = "low,best"; debug::Log("[Split:doOpenStreamlink] Streamlink path ({}) is invalid, it needs to point to "
} else if (preferredQuality == "audio only") { "the streamlink executable",
quality = "audio,audio_only"; path);
} else { return;
quality = "best"; }
}
if (quality != "") if (preferredQuality != "choose") {
args << quality; QStringList args = {"twitch.tv/" + channel};
if (exclude != "") QString quality = "";
args << "--stream-sorting-excludes" << exclude; QString exclude = "";
QProcess::startDetached(path, args); 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 { } else {
QProcess *p = new QProcess(); quality = "best";
// 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});
} }
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});
} }
} }