TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicbpdownloadimagerequest.cpp
Go to the documentation of this file.
3 
4 static constexpr const char *ART_BACKGROUND_URL = "L2tVRE5IY2RSOVcyNysvc3RBNVNjS3pmUlNwNjlOTW8xYmlnT2sxNVJUc0VTQk1CTGtoL2Z3SG1nbDNiOWRaR1dPL1BxQ3ZOSmVUdG91TEZaUVJhNjVyb2Znd2xBYWtYYTV6bURubXFqdFFIV293cg==";
5 
6 MusicBPDownloadBackgroundRequest::MusicBPDownloadBackgroundRequest(const QString &name, const QString &path, QObject *parent)
7  : MusicAbstractDownloadImageRequest(name, path, parent)
8 {
9 
10 }
11 
13 {
14  TTK_INFO_STREAM(className() << "startToRequest");
15 
17 
18  QNetworkRequest request;
19  request.setUrl(TTK::Algorithm::mdII(ART_BACKGROUND_URL, false));
20  TTK::setSslConfiguration(&request);
22 
23  m_reply = m_manager.get(request);
24  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
26 }
27 
29 {
30  TTK_INFO_STREAM(className() << "downLoadFinished");
31 
33  if(m_reply && m_reply->error() == QNetworkReply::NoError)
34  {
35  QJson::Parser json;
36  bool ok = false;
37  const QVariant &data = json.parse(m_reply->readAll(), &ok);
38  if(ok)
39  {
40  QVariantMap value = data.toMap();
41  if(value.contains("data"))
42  {
43  value = value["data"].toMap();
44 
45  const QVariantList &datas = value["list"].toList();
46  for(const QVariant &var : qAsConst(datas))
47  {
48  if(var.isNull())
49  {
50  continue;
51  }
52 
53  value = var.toMap();
55 
56  const QString &name = value["tag"].toString();
57  if(m_counter < m_remainCount && !name.isEmpty() && (name.contains(m_name) || m_name.contains(name)))
58  {
59  const QString &url = value["url"].toString();
60  if(url.isEmpty())
61  {
62  continue;
63  }
64 
66  connect(d, SIGNAL(downLoadDataChanged(QString)), SLOT(downLoadDataFinished()));
67  d->startToRequest();
68  }
69  }
70  }
71  }
72  }
73 
74  TTK_INFO_STREAM(className() << "download image size" << m_counter);
75  Q_EMIT downLoadDataChanged(QString::number(m_counter));
76  //
77  if(m_counter == 0)
78  {
79  deleteAll();
80  }
81 }
#define TTK_NETWORK_QUERY_CHECK(VALUE)
virtual void downLoadFinished() overridefinal
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
QNetworkReply * m_reply
The class of the download the type of data.
TTK_MODULE_EXPORT void setSslConfiguration(QNetworkRequest *request, QSslSocket::PeerVerifyMode mode=QSslSocket::VerifyNone)
virtual void downLoadFinished()
MusicBPDownloadBackgroundRequest(const QString &name, const QString &path, QObject *parent=nullptr)
#define qAsConst
Definition: ttkqtglobal.h:53
const char * name
Definition: http_parser.c:458
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
QNetworkAccessManager m_manager
#define BACKGROUND_DIR_FULL
Definition: musicobject.h:129
virtual void replyError(QNetworkReply::NetworkError error) override
QVariant parse(QIODevice *io, bool *ok=0)
Read JSON string from the I/O Device and converts it to a QVariant object.
Definition: parser.cpp:69
#define TTK_SLOT
Definition: ttkqtglobal.h:165
The class of the download art background image.
virtual void startToRequest() overridefinal
TTK_MODULE_EXPORT void makeContentTypeHeader(QNetworkRequest *request, const QByteArray &data={})
static constexpr const char * ART_BACKGROUND_URL
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
#define SKN_FILE
Definition: musicobject.h:61
virtual void startToRequest() override
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59