Skip to content

Commit

Permalink
Fix parsing youtube failed with lux (Fix #150)
Browse files Browse the repository at this point in the history
  • Loading branch information
coslyk committed Feb 17, 2024
1 parent 8255f73 commit 267c316
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/parserLux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ ParserLux::~ParserLux()
}
}


void ParserLux::runParser(const QUrl &url)
{
runParserFull(url, true);
}

void ParserLux::runParserFull(const QUrl &url, bool parsePlaylist)
{
// Check if another task is running
if (m_process.state() == QProcess::Running)
Expand All @@ -41,7 +45,8 @@ void ParserLux::runParser(const QUrl &url)

// Get and apply proxy settings
QSettings settings;
NetworkAccessManager::ProxyType proxyType = (NetworkAccessManager::ProxyType) settings.value(QStringLiteral("network/proxy_type")).toInt();
NetworkAccessManager::ProxyType proxyType =
(NetworkAccessManager::ProxyType) settings.value(QStringLiteral("network/proxy_type")).toInt();
QString proxy = settings.value(QStringLiteral("network/proxy")).toString();

if (!proxy.isEmpty() && proxyType == NetworkAccessManager::HTTP_PROXY)
Expand All @@ -59,8 +64,14 @@ void ParserLux::runParser(const QUrl &url)

// Set user-agent
QStringList args;
args << QStringLiteral("-j") << QStringLiteral("-p") << QStringLiteral("-u") << QStringLiteral(DEFAULT_UA);
args << QStringLiteral("-j") << QStringLiteral("-u") << QStringLiteral(DEFAULT_UA);

// Parse playlist
if (parsePlaylist) {
args << QStringLiteral("-p");
}
m_url = url;
m_parsePlaylist = parsePlaylist;
args << url.toString();
m_process.start(userResourcesPath() + QStringLiteral("/lux"), args, QProcess::ReadOnly);
}
Expand All @@ -76,7 +87,14 @@ void ParserLux::parseOutput()

if (json_error.error != QJsonParseError::NoError)
{
showErrorDialog(QString::fromUtf8(m_process.readAllStandardError()));
if (m_parsePlaylist)
{
runParserFull(m_url, false);
}
else
{
showErrorDialog(QString::fromUtf8(m_process.readAllStandardError()));
}
return;
}

Expand Down
5 changes: 4 additions & 1 deletion src/parserLux.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ class ParserLux : public ParserBase
inline static ParserLux* instance() { return &s_instance; }

protected:
void runParser(const QUrl &url);
void runParser(const QUrl &url) override;

private slots:
void parseOutput(void);

private:
void runParserFull(const QUrl &url, bool parsePlaylist);
void parseEpisode(QJsonObject episode);

QProcess m_process;
QUrl m_url;
bool m_parsePlaylist;
static ParserLux s_instance;
};

Expand Down

0 comments on commit 267c316

Please sign in to comment.