diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35cb0d7af..b67a7c38c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -118,7 +118,6 @@ set(SOURCES covers/albumcoverfetcher.cpp covers/albumcoverfetchersearch.cpp covers/albumcoverloader.cpp - covers/amazoncoverprovider.cpp covers/coverexportrunnable.cpp covers/coverprovider.cpp covers/coverproviders.cpp @@ -437,7 +436,6 @@ set(HEADERS covers/albumcoverfetcher.h covers/albumcoverfetchersearch.h covers/albumcoverloader.h - covers/amazoncoverprovider.h covers/coverexportrunnable.h covers/coverprovider.h covers/coverproviders.h diff --git a/src/core/application.cpp b/src/core/application.cpp index 031ae2106..75975c712 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -30,7 +30,6 @@ #include "core/tagreaderclient.h" #include "core/taskmanager.h" #include "covers/albumcoverloader.h" -#include "covers/amazoncoverprovider.h" #include "covers/coverproviders.h" #include "covers/currentartloader.h" #include "covers/musicbrainzcoverprovider.h" @@ -98,7 +97,6 @@ class ApplicationImpl { cover_providers_([=]() { CoverProviders* cover_providers = new CoverProviders(app); // Initialize the repository of cover providers. - cover_providers->AddProvider(new AmazonCoverProvider); cover_providers->AddProvider(new MusicbrainzCoverProvider); #ifdef HAVE_LIBLASTFM cover_providers->AddProvider(new LastFmCoverProvider(app)); diff --git a/src/covers/amazoncoverprovider.cpp b/src/covers/amazoncoverprovider.cpp deleted file mode 100644 index 63aead35a..000000000 --- a/src/covers/amazoncoverprovider.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* This file is part of Clementine. - Copyright 2011-2012, David Sansome - Copyright 2011, 2014, John Maguire - Copyright 2012, Arnaud Bienner - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#include "amazoncoverprovider.h" - -#include -#include -#include -#include - -#include "core/closure.h" -#include "core/logging.h" -#include "core/network.h" -#include "core/utilities.h" - -// Amazon has a web crawler that looks for access keys in public source code, -// so we apply some sophisticated encryption to these keys. -const char* AmazonCoverProvider::kAccessKeyB64 = "QUtJQUlRSDI2UlZNNlVaNFdBNlE="; -const char* AmazonCoverProvider::kSecretAccessKeyB64 = - "ZTQ2UGczM0JRNytDajd4MWR6eFNvODVFd2tpdi9FbGVCcUZjMkVmMQ=="; -const char* AmazonCoverProvider::kUrl = "http://ecs.amazonaws.com/onca/xml"; -const char* AmazonCoverProvider::kAssociateTag = "clemmusiplay-20"; - -AmazonCoverProvider::AmazonCoverProvider(QObject* parent) - : CoverProvider("Amazon", parent), - network_(new NetworkAccessManager(this)) {} - -bool AmazonCoverProvider::StartSearch(const QString& artist, - const QString& album, int id) { - typedef QPair Arg; - typedef QList ArgList; - - typedef QPair EncodedArg; - typedef QList EncodedArgList; - - // Must be sorted by parameter name - ArgList args = - ArgList() << Arg("AWSAccessKeyId", QByteArray::fromBase64(kAccessKeyB64)) - << Arg("AssociateTag", kAssociateTag) - << Arg("Keywords", artist + " " + album) - << Arg("Operation", "ItemSearch") - << Arg("ResponseGroup", "Images") << Arg("SearchIndex", "All") - << Arg("Service", "AWSECommerceService") - << Arg("Timestamp", QDateTime::currentDateTime().toString( - "yyyy-MM-ddThh:mm:ss.zzzZ")) - << Arg("Version", "2009-11-01"); - - EncodedArgList encoded_args; - QStringList query_items; - - // Encode the arguments - for (const Arg& arg : args) { - EncodedArg encoded_arg(QUrl::toPercentEncoding(arg.first), - QUrl::toPercentEncoding(arg.second)); - encoded_args << encoded_arg; - query_items << QString(encoded_arg.first + "=" + encoded_arg.second); - } - - // Sign the request - QUrl url(kUrl); - - const QByteArray data_to_sign = - QString("GET\n%1\n%2\n%3") - .arg(url.host(), url.path(), query_items.join("&")) - .toAscii(); - const QByteArray signature(Utilities::HmacSha256( - QByteArray::fromBase64(kSecretAccessKeyB64), data_to_sign)); - - // Add the signature to the request - encoded_args << EncodedArg("Signature", - QUrl::toPercentEncoding(signature.toBase64())); - url.setEncodedQueryItems(encoded_args); - - QNetworkReply* reply = network_->get(QNetworkRequest(url)); - NewClosure(reply, SIGNAL(finished()), this, - SLOT(QueryFinished(QNetworkReply*, int)), reply, id); - - return true; -} - -void AmazonCoverProvider::QueryFinished(QNetworkReply* reply, int id) { - reply->deleteLater(); - - CoverSearchResults results; - - QXmlStreamReader reader(reply); - while (!reader.atEnd()) { - reader.readNext(); - if (reader.tokenType() == QXmlStreamReader::StartElement && - reader.name() == "Item") { - ReadItem(&reader, &results); - } - } - - emit SearchFinished(id, results); -} - -void AmazonCoverProvider::ReadItem(QXmlStreamReader* reader, - CoverSearchResults* results) { - while (!reader->atEnd()) { - switch (reader->readNext()) { - case QXmlStreamReader::StartElement: - if (reader->name() == "LargeImage") { - ReadLargeImage(reader, results); - } else { - reader->skipCurrentElement(); - } - break; - - case QXmlStreamReader::EndElement: - return; - - default: - break; - } - } -} - -void AmazonCoverProvider::ReadLargeImage(QXmlStreamReader* reader, - CoverSearchResults* results) { - while (!reader->atEnd()) { - switch (reader->readNext()) { - case QXmlStreamReader::StartElement: - if (reader->name() == "URL") { - CoverSearchResult result; - result.image_url = QUrl(reader->readElementText()); - results->append(result); - } else { - reader->skipCurrentElement(); - } - break; - - case QXmlStreamReader::EndElement: - return; - - default: - break; - } - } -} diff --git a/src/covers/amazoncoverprovider.h b/src/covers/amazoncoverprovider.h deleted file mode 100644 index 7044eb60b..000000000 --- a/src/covers/amazoncoverprovider.h +++ /dev/null @@ -1,53 +0,0 @@ -/* This file is part of Clementine. - Copyright 2011-2012, David Sansome - Copyright 2011, 2014, John Maguire - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef COVERS_AMAZONCOVERPROVIDER_H_ -#define COVERS_AMAZONCOVERPROVIDER_H_ - -#include "coverprovider.h" - -#include - -class QNetworkAccessManager; - -class AmazonCoverProvider : public CoverProvider { - Q_OBJECT - - public: - explicit AmazonCoverProvider(QObject* parent = nullptr); - - static const char* kAccessKeyB64; - static const char* kSecretAccessKeyB64; - static const char* kUrl; - static const char* kAssociateTag; - - bool StartSearch(const QString& artist, const QString& album, int id); - - private slots: - void QueryFinished(QNetworkReply* reply, int id); - - private: - void ReadItem(QXmlStreamReader* reader, CoverSearchResults* results); - void ReadLargeImage(QXmlStreamReader* reader, CoverSearchResults* results); - - private: - QNetworkAccessManager* network_; -}; - -#endif // COVERS_AMAZONCOVERPROVIDER_H_