Permalink
Browse files

Fixes #325

  • Loading branch information...
1 parent c3e9c69 commit 9ae32d41f613ac02770e3ddda1a3a57151da5500 Daniel Kabel committed Mar 26, 2013
Showing with 22 additions and 12 deletions.
  1. +9 −1 globals/Helper.cpp
  2. +2 −1 globals/Helper.h
  3. +10 −9 scrapers/IMDB.cpp
  4. +1 −1 trailerProviders/HdTrailers.cpp
View
@@ -47,12 +47,20 @@ QString Helper::toLatin1PercentEncoding(QString str)
return str;
}
-QString Helper::urlFromEncoded(QString str)
+QString Helper::urlDecode(QString str)
{
str = str.replace("&", "&");
return str;
}
+QString Helper::urlEncode(QString str)
+{
+ QUrl url(str);
+ str = url.toEncoded();
+ str = str.replace("%26", "&");
+ return str;
+}
+
/**
* @brief Changes the format of a trailer url
* @param url Trailer Url
View
@@ -11,7 +11,8 @@ class Helper
{
public:
static QString toLatin1PercentEncoding(QString str);
- static QString urlFromEncoded(QString str);
+ static QString urlDecode(QString str);
+ static QString urlEncode(QString str);
static QString formatTrailerUrl(QString url);
static bool isDvd(QString path);
static bool isBluRay(QString path);
View
@@ -70,8 +70,9 @@ QList<int> IMDB::scraperSupports()
void IMDB::search(QString searchStr)
{
- QString encodedSearch = QUrl::toPercentEncoding(searchStr);
- QUrl url(QString("http://imdbapi.org/?q=%1&type=json&plot=full&episode=0&limit=5&yg=0&mt=M&lang=en-US").arg(encodedSearch));
+ QString encodedSearch = Helper::urlEncode(searchStr);
+ QUrl url;
+ url.setEncodedUrl(QString("http://imdbapi.org/?q=%1&type=json&plot=full&episode=0&limit=5&yg=0&mt=M&lang=en-US").arg(encodedSearch).toUtf8());
QNetworkRequest request(url);
QNetworkReply *reply = qnam()->get(request);
connect(reply, SIGNAL(finished()), this, SLOT(onSearchFinished()));
@@ -105,7 +106,7 @@ QList<ScraperSearchResult> IMDB::parseSearch(QString json)
if (it.value().property("imdb_id").toString().isEmpty())
continue;
ScraperSearchResult result;
- result.name = it.value().property("title").toString();
+ result.name = Helper::urlDecode(it.value().property("title").toString());
result.id = it.value().property("imdb_id").toString();
result.released = QDate::fromString(it.value().property("year").toString(), "yyyy");
results.append(result);
@@ -153,7 +154,7 @@ void IMDB::parseAndAssignInfos(QString json, Movie *movie, QList<int> infos)
sc = engine.evaluate("(" + QString(json) + ")");
if (infos.contains(MovieScraperInfos::Title) && sc.property("title").isValid())
- movie->setName(sc.property("title").toString());
+ movie->setName(Helper::urlDecode(sc.property("title").toString()));
if (infos.contains(MovieScraperInfos::Overview) && sc.property("plot").isValid() && !sc.property("plot").isNull()) {
movie->setOverview(sc.property("plot").toString());
if (sc.property("plot_simple").isValid() && !sc.property("plot_simple").isNull() && !sc.property("plot_simple").toString().isEmpty())
@@ -188,7 +189,7 @@ void IMDB::parseAndAssignInfos(QString json, Movie *movie, QList<int> infos)
while (itC.hasNext()) {
itC.next();
if (itC.hasNext())
- movie->addGenre(Helper::mapGenre(itC.value().toString()));
+ movie->addGenre(Helper::mapGenre(Helper::urlDecode(itC.value().toString())));
}
}
@@ -198,7 +199,7 @@ void IMDB::parseAndAssignInfos(QString json, Movie *movie, QList<int> infos)
while (itC.hasNext()) {
itC.next();
if (itC.hasNext())
- directors << itC.value().toString();
+ directors << Helper::urlDecode(itC.value().toString());
}
movie->setDirector(directors.join(", "));
}
@@ -209,7 +210,7 @@ void IMDB::parseAndAssignInfos(QString json, Movie *movie, QList<int> infos)
while (itC.hasNext()) {
itC.next();
if (itC.hasNext())
- writers << itC.value().toString();
+ writers << Helper::urlDecode(itC.value().toString());
}
movie->setWriter(writers.join(", "));
}
@@ -219,7 +220,7 @@ void IMDB::parseAndAssignInfos(QString json, Movie *movie, QList<int> infos)
while (itC.hasNext()) {
itC.next();
if (itC.hasNext())
- movie->addCountry(Helper::mapCountry(itC.value().toString()));
+ movie->addCountry(Helper::mapCountry(Helper::urlDecode(itC.value().toString())));
}
}
@@ -228,7 +229,7 @@ void IMDB::parseAndAssignInfos(QString json, Movie *movie, QList<int> infos)
while (itC.hasNext()) {
itC.next();
Actor a;
- a.name = itC.value().toString();
+ a.name = Helper::urlDecode(itC.value().toString());
if (itC.hasNext())
movie->addActor(a);
}
@@ -117,7 +117,7 @@ QList<TrailerResult> HdTrailers::parseTrailers(QString html)
if (rx2.cap(1).contains("http://trailers.apple.com"))
continue;
TrailerResult r;
- r.trailerUrl = Helper::urlFromEncoded(rx2.cap(1));
+ r.trailerUrl = Helper::urlDecode(rx2.cap(1));
r.name = QString("%2, %1").arg(rx.cap(1)).arg(rx2.cap(2));
results.append(r);
}

0 comments on commit 9ae32d4

Please sign in to comment.