TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickwdownloadimagerequest.cpp
Go to the documentation of this file.
3 
4 static constexpr const char *ART_BACKGROUND_URL = "NUJnNFVlSHprVzdaMWxMdXRvbEp5a3lldU51Um9GeU5RKzRDWFNER2FHL3pSRE1uK1VNRzVhVk53Y1JBUTlMbnhjeFBvRFMySnpUSldlY21xQjBkWE5GTWVkVXFsa0lNa1RKSnE3VHEwMDFPdVRDbXhUSThhWkM4TFI4RUZqbHFzVFFnQkpOY2hUR2c2YWdzb3U2cjBKSUdMYnpnZktucEJpbDVBTDlzMGF0QVMwcEtLR2JWVnc9PQ==";
5 
6 MusicKWDownloadBackgroundRequest::MusicKWDownloadBackgroundRequest(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).arg(m_name));
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  const QByteArray &bytes = m_reply->readAll();
36  if(bytes != "NO_PIC")
37  {
38  QJson::Parser json;
39  bool ok = false;
40  const QVariant &data = json.parse(bytes, &ok);
41  if(ok)
42  {
43  QString lastUrl;
44  QVariantMap value = data.toMap();
45 
46  const QVariantList &datas = value["array"].toList();
47  for(const QVariant &var : qAsConst(datas))
48  {
49  if(var.isNull())
50  {
51  continue;
52  }
53 
54  value = var.toMap();
56 
57  if(m_counter < m_remainCount && !value.isEmpty())
58  {
59  const QString &url = value.values().front().toString();
60  if(url.isEmpty() || url == lastUrl)
61  {
62  continue;
63  }
64 
65  lastUrl = url;
67  connect(d, SIGNAL(downLoadDataChanged(QString)), SLOT(downLoadDataFinished()));
68  d->startToRequest();
69  }
70  }
71  }
72  }
73  }
74 
75  TTK_INFO_STREAM(className() << "download image size" << m_counter);
76  Q_EMIT downLoadDataChanged(QString::number(m_counter));
77  //
78  if(m_counter == 0)
79  {
80  deleteAll();
81  }
82 }
#define TTK_NETWORK_QUERY_CHECK(VALUE)
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()
#define qAsConst
Definition: ttkqtglobal.h:53
const char * name
Definition: http_parser.c:458
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
virtual void downLoadFinished() overridefinal
QNetworkAccessManager m_manager
MusicKWDownloadBackgroundRequest(const QString &name, const QString &path, QObject *parent=nullptr)
#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