#include "channelsuggest.h"
#include "networkaccess.h"
+#include "compatibility/qurlqueryhelper.h"
namespace The {
NetworkAccess* http();
}
void ChannelSuggest::suggest(const QString &query) {
- QUrl url("http://www.youtube.com/results");
-#if QT_VERSION >= 0x050000
- {
- QUrl &u = url;
- QUrlQuery url;
-#endif
- url.addQueryItem("search_type", "search_users");
- url.addQueryItem("search_query", query);
-#if QT_VERSION >= 0x050000
- u.setQuery(url);
- }
-#endif
+ QUrl url("https://www.youtube.com/results");
+ {
+ QUrlQueryHelper urlHelper(url);
+ urlHelper.addQueryItem("search_type", "search_users");
+ urlHelper.addQueryItem("search_query", query);
+ }
+
QObject *reply = The::http()->get(url);
connect(reply, SIGNAL(data(QByteArray)), SLOT(handleNetworkData(QByteArray)));
}
QList<Suggestion*> suggestions;
QString html = QString::fromUtf8(data);
- QRegExp re("/user/([a-zA-Z0-9]+)");
+ QRegExp re("/(?:user|channel)/[a-zA-Z0-9]+[^>]+data-ytid=[\"']([^\"']+)[\"'][^>]+>([a-zA-Z0-9 ]+)</a>");
int pos = 0;
while ((pos = re.indexIn(html, pos)) != -1) {
- // qDebug() << re.cap(0) << re.cap(1);
- QString choice = re.cap(1);
+ QString choice = re.cap(2);
if (!choices.contains(choice, Qt::CaseInsensitive)) {
- suggestions << new Suggestion(choice);
+ qDebug() << re.capturedTexts();
+ QString channelId = re.cap(1);
+ suggestions << new Suggestion(choice, "channel", channelId);
choices << choice;
if (choices.size() == 10) break;
}