]> git.sur5r.net Git - minitube/blobdiff - src/channelsuggest.cpp
Fix updating QUrl query parameters with Qt5.
[minitube] / src / channelsuggest.cpp
index c252802f3455e34ce7ba45c0f64da0c1067dd538..20b564ac54249f5d4d00cb579bcde85a3e8059d0 100644 (file)
@@ -20,6 +20,7 @@ $END_LICENSE */
 
 #include "channelsuggest.h"
 #include "networkaccess.h"
+#include "compatibility/qurlqueryhelper.h"
 
 namespace The {
     NetworkAccess* http();
@@ -30,18 +31,13 @@ ChannelSuggest::ChannelSuggest(QObject *parent) : Suggester(parent) {
 }
 
 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)));
 }
@@ -51,14 +47,15 @@ void ChannelSuggest::handleNetworkData(QByteArray data) {
     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;
         }