TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickgquerytoplistrequest.cpp
Go to the documentation of this file.
2 
5 {
8 }
9 
11 {
12  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
13 
14  deleteAll();
15  m_totalSize = 0;
17 
18  QNetworkRequest request;
19  request.setUrl(TTK::Algorithm::mdII(KG_TOPLIST_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
21 
22  m_reply = m_manager.get(request);
23  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
25 }
26 
28 {
29  MusicQueryToplistRequest::startToSearch(value.isEmpty() ? "6666" : value);
30 }
31 
33 {
34  TTK_INFO_STREAM(className() << __FUNCTION__ << info->m_songId << bitrate << "kbps");
35 
40 
43 }
44 
46 {
47  TTK_INFO_STREAM(className() << __FUNCTION__);
48 
50  if(m_reply && m_reply->error() == QNetworkReply::NoError)
51  {
52  QJson::Parser json;
53  bool ok = false;
54  const QVariant &data = json.parse(m_reply->readAll(), &ok);
55  if(ok)
56  {
57  QVariantMap value = data.toMap();
58  if(value.contains("data"))
59  {
60  value = value["data"].toMap();
61  m_totalSize = value["total"].toInt();
62 
63  queryToplistInfo(value);
64 
65  const QVariantList &datas = value["info"].toList();
66  for(const QVariant &var : qAsConst(datas))
67  {
68  if(var.isNull())
69  {
70  continue;
71  }
72 
73  value = var.toMap();
75 
77  info.m_songId = value["hash"].toString();
78 
79  info.m_albumId = value["album_id"].toString();
80 
81  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
82  info.m_year.clear();
83  info.m_trackNumber = "0";
84 
88  ReqKGInterface::parseFromSongAlbumInfo(&info, value["album_audio_id"].toString());
92 
93  Q_EMIT createResultItem({info, serverToString()});
94  m_items << info;
95  }
96  }
97  }
98  }
99 
100  Q_EMIT downLoadDataChanged({});
101  deleteAll();
102 }
103 
104 void MusicKGQueryToplistRequest::queryToplistInfo(const QVariantMap &input)
105 {
106  Q_UNUSED(input);
107 
108  QNetworkRequest request;
109  request.setUrl(TTK::Algorithm::mdII(KG_TOPLIST_INFO_URL, false));
111 
112  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
113  if(bytes.isEmpty())
114  {
115  return;
116  }
117 
118  QJson::Parser json;
119  bool ok = false;
120  const QVariant &data = json.parse(bytes, &ok);
121  if(ok)
122  {
123  QVariantMap value = data.toMap();
124  if(value.contains("data"))
125  {
126  value = value["data"].toMap();
127  MusicResultDataItem item;
128  item.m_time = TTKDateTime::format(value["timestamp"].toLongLong() * TTK_DN_S2MS, TTK_DATE_FORMAT);
129 
130  const QVariantList &datas = value["info"].toList();
131  for(const QVariant &var : qAsConst(datas))
132  {
133  if(var.isNull())
134  {
135  continue;
136  }
137 
138  value = var.toMap();
140 
141  if(m_queryValue != value["rankid"])
142  {
143  continue;
144  }
145 
146  item.m_name = value["rankname"].toString();
147  item.m_coverUrl = value["banner7url"].toString().replace("{size}", "400");
148  item.m_count = value["play_times"].toString();
149  item.m_description = value["intro"].toString();
150  Q_EMIT createToplistItem(item);
151  return;
152  }
153  }
154  }
155 }
The class of the query toplist download data from net.
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
#define TTK_NETWORK_QUERY_CHECK(VALUE)
The class of the search result data item.
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
static constexpr const char * KG_TOPLIST_INFO_URL
QNetworkReply * m_reply
static constexpr const char * QUERY_KG_INTERFACE
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
virtual void downLoadFinished()
void makeRequestRawHeader(QNetworkRequest *request)
virtual void startToPage(int offset) overridefinal
voidpf uLong offset
Definition: ioapi.h:142
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
TTK::MusicSongInformationList m_items
virtual void queryToplistInfo(const QVariantMap &input) overridefinal
#define qAsConst
Definition: ttkqtglobal.h:51
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:68
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
MusicKGQueryToplistRequest(QObject *parent=nullptr)
#define TOPLIST_PAGE_SIZE
virtual void startToSearch(const QString &value) override
bool fetchUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
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:181
#define TTK_DATE_FORMAT
Definition: ttkglobal.h:235
virtual void downLoadFinished() overridefinal
#define TTK_DN_S2MS
Definition: ttkglobal.h:281
TTK_MODULE_EXPORT QString toString(Record type)
void parseFromSongAlbumLrc(TTK::MusicSongInformation *info)
void createToplistItem(const MusicResultDataItem &item)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
void parseFromSongAlbumInfo(TTK::MusicSongInformation *info, const QString &album)
static QString format(const QString &time, const QString &format)
Definition: ttktime.cpp:254
virtual void startToSearch(const QString &value) overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
static constexpr const char * KG_TOPLIST_URL
toplist url
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the music song information.
Definition: musicobject.h:283
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123