TTKMusicPlayer  4.3.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 
3 static constexpr const char *KW_TOPLIST_INFO_URL = "Wkl6YXI0QWdzcXRyaUVCbzdLM2lhR3FZUDFZUVNLUDdvLzdpL1AwbjBlWGxrNWcxdGxBWVBiWjNlMldnNFB6cnBWT2ozOWJwZEQ4Q3dHM0RnVy9DSTVHL202RT0=";
4 
7 {
10 }
11 
13 {
14  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__ << offset);
15 
16  deleteAll();
17  m_totalSize = 0;
19 
20  QNetworkRequest request;
21  request.setUrl(TTK::Algorithm::mdII(KW_TOPLIST_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
23 
24  m_reply = m_manager.get(request);
25  connect(m_reply, SIGNAL(finished()), SLOT(downloadFinished()));
27 }
28 
30 {
31  MusicQueryToplistRequest::startToSearch(value.isEmpty() ? "16" : value);
32 }
33 
35 {
36  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__ << info->m_songId << bitrate << "kbps");
37 
42 
45 }
46 
48 {
49  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__);
50 
52  if(m_reply && m_reply->error() == QNetworkReply::NoError)
53  {
54  QJsonParseError ok;
55  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
57  {
58  QVariantMap value = json.toVariant().toMap();
59  if(value.contains("musiclist"))
60  {
61  m_totalSize = value["num"].toInt();
62 
63  queryToplistInfo(value);
64 
65  const QVariantList &datas = value["musiclist"].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["id"].toString();
78  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
79 
80  info.m_artistId = value["artistid"].toString();
81  info.m_artistName = ReqKWInterface::makeSongArtist(value["artist"].toString());
82 
83  info.m_albumId = value["albumid"].toString();
84  info.m_albumName = TTK::String::charactersReplace(value["album"].toString());
85 
86  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
87  info.m_lrcUrl = TTK::Algorithm::mdII(KW_SONG_LRC_URL, false).arg(info.m_songId);
88  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
89  info.m_year.clear();
90  info.m_trackNumber = "0";
91 
93  ReqKWInterface::parseFromSongProperty(&info, value["formats"].toString());
95 
96  Q_EMIT createResultItem({info, serverToString()});
97  m_items << info;
98  }
99  }
100  }
101  }
102 
103  Q_EMIT downloadDataChanged({});
104  deleteAll();
105 }
106 
107 void MusicKWQueryToplistRequest::queryToplistInfo(const QVariantMap &input)
108 {
109  Q_UNUSED(input);
110 
111  QNetworkRequest request;
112  request.setUrl(TTK::Algorithm::mdII(KW_TOPLIST_INFO_URL, false));
114 
115  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
116  if(bytes.isEmpty())
117  {
118  return;
119  }
120 
121  QJsonParseError ok;
122  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
124  {
125  QVariantMap value = json.toVariant().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_time = 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 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()
QNetworkReply * m_reply
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
void downloadDataChanged(const QString &bytes)
QVariant toVariant() const
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
#define TTK_PAGE_SIZE_30
MusicSongPropertyList m_songProps
Definition: musicobject.h:314
QString makeCoverPixmapUrl(const QString &url, const QString &id)
void createResultItem(const MusicResultInfoItem &result)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
virtual void queryToplistInfo(const QVariantMap &input) overridefinal
voidpf uLong offset
Definition: ioapi.h:142
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
ParseError error
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:57
static constexpr const char * KW_SONG_LRC_URL
static constexpr const char * KW_TOPLIST_INFO_URL
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
QNetworkAccessManager m_manager
virtual void startToSearch(const QString &value) override
MusicKWQueryToplistRequest(QObject *parent=nullptr)
bool fetchUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
virtual void replyError(QNetworkReply::NetworkError error) override
static constexpr const char * QUERY_KW_INTERFACE
#define TTK_SLOT
Definition: ttkqtglobal.h:177
QString makeSongArtist(const QString &name)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
virtual void downloadFinished()
void makeRequestRawHeader(QNetworkRequest *request) noexcept
void createToplistItem(const MusicResultDataItem &item)
static constexpr const char * KW_TOPLIST_URL
virtual void downloadFinished() overridefinal
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:300
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123