So i made a program that connects to Youtube, downloads the page and parses for video title and tags. It works fine for 5-6 times the request is being called, but then the functionality of the youtube class stops, and processor usage rises to 12% and stays at this level. This is my code
#include "youtube.h"
#include <QByteArray>
#include <QNetworkCookieJar>
#include "youtube.h"
{
manager = new QNetworkAccessManager(this);
manager->setCookieJar(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotReadyRead(QNetworkReply*)));
auto aName = manager->objectName();
connect(manager, &QNetworkAccessManager::encrypted,
this, [aName]{ qDebug()<< "connect - encrypted"; });
}
void Youtube
::makeRequest(QString indexCore
) {
youtubeActive_is = true;
url = "https://" + indexCore;
QUrl urlForCookies
(url
);
request.setRawHeader("COOKIE" , "CONSENT=YES+42"); //works
request.setUrl(urlForCookies);
manager->get(request);
}
void Youtube::slotReadyRead(QNetworkReply *replay)
{
website = dataTemp.toStdString();
if(website.size()!=0)
{
Parser parser;
std::string title = parser.extract_tagContent(website, "title");
title = "\u00034" +title;
postToIRC(title);
youtubeActive_is = false;
}
manager->autoDeleteReplies();
manager->clearAccessCache();
manager->clearConnectionCache();
replay->abort();
replay->close();
replay->deleteLater();
for (int i = 0; i < allCookies().size(); ++i) {
manager->cookieJar()->deleteCookie(allCookies().at(i));
}
}
#include "youtube.h"
#include <QByteArray>
#include <QNetworkCookieJar>
#include "youtube.h"
Youtube::Youtube(QObject *parent)
{
manager = new QNetworkAccessManager(this);
manager->setCookieJar(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotReadyRead(QNetworkReply*)));
auto aName = manager->objectName();
connect(manager, &QNetworkAccessManager::encrypted,
this, [aName]{ qDebug()<< "connect - encrypted"; });
}
void Youtube::makeRequest(QString indexCore)
{
youtubeActive_is = true;
url = "https://" + indexCore;
QUrl urlForCookies (url);
request.setRawHeader("COOKIE" , "CONSENT=YES+42"); //works
request.setUrl(urlForCookies);
manager->get(request);
}
void Youtube::slotReadyRead(QNetworkReply *replay)
{
QByteArray dataTemp = replay->readAll();
website = dataTemp.toStdString();
if(website.size()!=0)
{
Parser parser;
std::string title = parser.extract_tagContent(website, "title");
title = "\u00034" +title;
postToIRC(title);
youtubeActive_is = false;
}
manager->autoDeleteReplies();
manager->clearAccessCache();
manager->clearConnectionCache();
replay->abort();
replay->close();
replay->deleteLater();
for (int i = 0; i < allCookies().size(); ++i) {
manager->cookieJar()->deleteCookie(allCookies().at(i));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks