TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwyqueryartistlistrequest.cpp
Go to the documentation of this file.
2 
5 {
8 }
9 
11 {
12  TTK_INFO_STREAM(className() << "startToPage" << offset);
13 
14  deleteAll();
15  m_totalSize = m_pageSize; // 0
17 
18  QString catId = "1001", initial = "-1";
19  const QStringList &dds = m_queryValue.split(TTK_SPLITER);
20 
21  if(dds.count() == 2)
22  {
23  catId = dds[0];
24  if(catId.isEmpty())
25  {
26  catId = "1001";
27  }
28 
29  int id = dds[1].toInt();
30  if(id <= 0)
31  {
32  id = -1;
33  }
34  else if(id > 0 && id <= 26)
35  {
36  id += 65 - 1;
37  }
38  else if(id > 26)
39  {
40  id = 0;
41  }
42 
43  initial = QString::number(id);
44  }
45 
46  QNetworkRequest request;
47  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
49  TTK::Algorithm::mdII(WY_ARTIST_LIST_DATA_URL, false).arg(catId, initial).arg(m_pageSize * offset).arg(m_pageSize));
50 
51  m_reply = m_manager.post(request, parameter);
52  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
54 }
55 
57 {
58  TTK_INFO_STREAM(className() << "downLoadFinished");
59 
61  if(m_reply && m_reply->error() == QNetworkReply::NoError)
62  {
63  QJson::Parser json;
64  bool ok = false;
65  const QVariant &data = json.parse(m_reply->readAll(), &ok);
66  if(ok)
67  {
68  QVariantMap value = data.toMap();
69  if(value["code"].toInt() == 200 && value.contains("artists"))
70  {
71  const QVariantList &datas = value["artists"].toList();
72  for(const QVariant &var : qAsConst(datas))
73  {
74  if(var.isNull())
75  {
76  continue;
77  }
78 
79  value = var.toMap();
81 
83  item.m_id = value["id"].toString();
84  item.m_name = value["name"].toString();
85  Q_EMIT createArtistListItem(item);
86  }
87  }
88  }
89  }
90 
91 // Q_EMIT downLoadDataChanged({});
92  deleteAll();
93 }
#define TTK_NETWORK_QUERY_CHECK(VALUE)
#define ARTIST_LIST_PAGE_SIZE
The class of the search result data item.
virtual void deleteAll()
QNetworkReply * m_reply
#define TTK_SPLITER
Definition: ttkglobal.h:199
The class of the query artist list download data from net.
MusicWYQueryArtistListRequest(QObject *parent=nullptr)
virtual void downLoadFinished() overridefinal
voidpf uLong offset
Definition: ioapi.h:142
#define qAsConst
Definition: ttkqtglobal.h:53
static constexpr const char * QUERY_WY_INTERFACE
virtual void startToPage(int offset) overridefinal
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
QNetworkAccessManager m_manager
static constexpr const char * WY_ARTIST_LIST_URL
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
virtual void downLoadFinished() override
QByteArray makeTokenRequest(QNetworkRequest *request, const QString &query, const QString &type)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
void createArtistListItem(const MusicResultDataItem &item)
static constexpr const char * WY_ARTIST_LIST_DATA_URL
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59