TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickwquerytoplistrequest.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 = 0;
17 
18  QNetworkRequest request;
19  request.setUrl(TTK::Algorithm::mdII(KW_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() ? "16" : value);
30 }
31 
33 {
34  TTK_INFO_STREAM(className() << "startToQueryResult" << info->m_songId << bitrate << "kbps");
35 
40 
41  findUrlPathSize(&info->m_songProps, info->m_duration);
43 }
44 
46 {
47  TTK_INFO_STREAM(className() << "downLoadFinished");
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("musiclist"))
59  {
60  m_totalSize = value["num"].toInt();
61 
62  queryToplistInfo(value);
63 
64  const QVariantList &datas = value["musiclist"].toList();
65  for(const QVariant &var : qAsConst(datas))
66  {
67  if(var.isNull())
68  {
69  continue;
70  }
71 
72  value = var.toMap();
74 
76  info.m_songId = value["id"].toString();
77  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
78 
79  info.m_artistId = value["artistid"].toString();
80  info.m_artistName = ReqKWInterface::makeSongArtist(value["artist"].toString());
81 
82  info.m_albumId = value["albumid"].toString();
83  info.m_albumName = TTK::String::charactersReplace(value["album"].toString());
84 
85  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
86  info.m_lrcUrl = TTK::Algorithm::mdII(KW_SONG_LRC_URL, false).arg(info.m_songId);
87  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
88  info.m_year.clear();
89  info.m_trackNumber = "0";
90 
92  ReqKWInterface::parseFromSongProperty(&info, value["formats"].toString());
94 
95  Q_EMIT createResultItem({info, serverToString()});
96  m_items << info;
97  }
98  }
99  }
100  }
101 
102  Q_EMIT downLoadDataChanged({});
103  deleteAll();
104 }
105 
106 void MusicKWQueryToplistRequest::queryToplistInfo(const QVariantMap &input)
107 {
108  Q_UNUSED(input);
109 
110  QNetworkRequest request;
111  request.setUrl(TTK::Algorithm::mdII(KW_TOPLIST_INFO_URL, false));
113 
114  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
115  if(bytes.isEmpty())
116  {
117  return;
118  }
119 
120  QJson::Parser json;
121  bool ok = false;
122  const QVariant &data = json.parse(bytes, &ok);
123  if(ok)
124  {
125  QVariantMap value = data.toMap();
126  if(value.contains("data"))
127  {
128  const QVariantList &datas = value["data"].toList();
129  for(const QVariant &var : qAsConst(datas))
130  {
131  if(var.isNull())
132  {
133  continue;
134  }
135 
136  value = var.toMap();
138 
139  const QVariantList &ranks = value["list"].toList();
140  for(const QVariant &rank : qAsConst(ranks))
141  {
142  if(rank.isNull())
143  {
144  continue;
145  }
146 
147  value = rank.toMap();
149 
150  if(m_queryValue != value["sourceid"])
151  {
152  continue;
153  }
154 
155  MusicResultDataItem item;
156  item.m_name = value["name"].toString();
157  item.m_coverUrl = value["pic"].toString();
158  item.m_count = value["id"].toString();
159  item.m_description = value["intro"].toString();
160  item.m_updateTime = value["pub"].toString();
161  Q_EMIT createToplistItem(item);
162  return;
163  }
164  }
165  }
166  }
167 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
The class of the query toplist download data from net.
virtual void startToPage(int offset) overridefinal
virtual void startToSearch(const QString &value) overridefinal
#define TTK_NETWORK_QUERY_CHECK(VALUE)
The class of the search result data item.
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
QNetworkReply * m_reply
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
QString makeCoverPixmapUrl(const QString &url, const QString &id)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
void makeRequestRawHeader(QNetworkRequest *request)
virtual void downLoadFinished()
virtual void queryToplistInfo(const QVariantMap &input) overridefinal
voidpf uLong offset
Definition: ioapi.h:142
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:53
static constexpr const char * KW_SONG_LRC_URL
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
#define TOPLIST_PAGE_SIZE
virtual void startToSearch(const QString &value) override
MusicKWQueryToplistRequest(QObject *parent=nullptr)
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
static constexpr const char * QUERY_KW_INTERFACE
#define TTK_SLOT
Definition: ttkqtglobal.h:165
static constexpr const char * KW_TOPLIST_INFO_URL
QString makeSongArtist(const QString &name)
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
virtual void downLoadFinished() overridefinal
TTK_MODULE_EXPORT QString toString(Record type)
void createToplistItem(const MusicResultDataItem &item)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
bool findUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
static constexpr const char * KW_TOPLIST_URL
toplist url
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
The class of the music song information.
Definition: musicobject.h:281
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123