1 /* DiscogsCoverFetcher.cpp */ 2 3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras) 4 * 5 * This file is part of sayonara player 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "Discogs.h" 22 23 #include <QRegExp> 24 #include <QStringList> 25 #include <QUrl> 26 27 using namespace Cover::Fetcher; 28 29 namespace 30 { basicUrl(const QString & str)31 QString basicUrl(const QString& str) 32 { 33 auto stringCopy = str; 34 stringCopy = stringCopy.replace(" ", "+"); 35 36 return QString("https://%1/search/?q=%2") 37 .arg("www.discogs.com") 38 .arg(QString(QUrl::toPercentEncoding(stringCopy))); 39 } 40 } 41 canFetchCoverDirectly() const42bool Discogs::canFetchCoverDirectly() const 43 { 44 return false; 45 } 46 parseAddresses(const QByteArray & website) const47QStringList Discogs::parseAddresses(const QByteArray& website) const 48 { 49 QStringList ret; 50 51 auto regExp = QRegExp("class=\"thumbnail_center\">\\s*<img\\s*data-src\\s*=\\s*\"(.+)\""); 52 regExp.setMinimal(true); 53 54 const auto websiteData = QString::fromLocal8Bit(website); 55 auto idx = regExp.indexIn(websiteData); 56 while(idx > 0) 57 { 58 const auto caption = regExp.cap(1); 59 ret << caption; 60 idx = regExp.indexIn(websiteData, idx + caption.size()); 61 } 62 63 return ret; 64 } 65 artistAddress(const QString & artist) const66QString Discogs::artistAddress(const QString& artist) const 67 { 68 return basicUrl(artist) + "&type=artist"; 69 } 70 albumAddress(const QString & artist,const QString & album) const71QString Discogs::albumAddress(const QString& artist, const QString& album) const 72 { 73 return basicUrl(artist + "+" + album) + "&type=all"; 74 } 75 fulltextSearchAddress(const QString & str) const76QString Discogs::fulltextSearchAddress(const QString& str) const 77 { 78 return basicUrl(str) + "&type=all"; 79 } 80 estimatedSize() const81int Discogs::estimatedSize() const 82 { 83 return 350; 84 } 85 privateIdentifier() const86QString Discogs::privateIdentifier() const 87 { 88 return "discogs"; 89 } 90