TTKMusicPlayer  4.2.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() << __FUNCTION__ << 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() << __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  QJsonParseError ok;
53  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
55  {
56  QVariantMap value = json.toVariant().toMap();
57  if(value.contains("musiclist"))
58  {
59  m_totalSize = value["num"].toInt();
60 
61  queryToplistInfo(value);
62 
63  const QVariantList &datas = value["musiclist"].toList();
64  for(const QVariant &var : qAsConst(datas))
65  {
66  if(var.isNull())
67  {
68  continue;
69  }
70 
71  value = var.toMap();
73 
75  info.m_songId = value["id"].toString();
76  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
77 
78  info.m_artistId = value["artistid"].toString();
79  info.m_artistName = ReqKWInterface::makeSongArtist(value["artist"].toString());
80 
81  info.m_albumId = value["albumid"].toString();
82  info.m_albumName = TTK::String::charactersReplace(value["album"].toString());
83 
84  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
85  info.m_lrcUrl = TTK::Algorithm::mdII(KW_SONG_LRC_URL, false).arg(info.m_songId);
86  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
87  info.m_year.clear();
88  info.m_trackNumber = "0";
89 
91  ReqKWInterface::parseFromSongProperty(&info, value["formats"].toString());
93 
94  Q_EMIT createResultItem({info, serverToString()});
95  m_items << info;
96  }
97  }
98  }
99  }
100 
101  Q_EMIT downLoadDataChanged({});
102  deleteAll();
103 }
104 
105 void MusicKWQueryToplistRequest::queryToplistInfo(const QVariantMap &input)
106 {
107  Q_UNUSED(input);
108 
109  QNetworkRequest request;
110  request.setUrl(TTK::Algorithm::mdII(KW_TOPLIST_INFO_URL, false));
112 
113  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
114  if(bytes.isEmpty())
115  {
116  return;
117  }
118 
119  QJsonParseError ok;
120  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
122  {
123  QVariantMap value = json.toVariant().toMap();
124  if(value.contains("data"))
125  {
126  const QVariantList &datas = value["data"].toList();
127  for(const QVariant &var : qAsConst(datas))
128  {
129  if(var.isNull())
130  {
131  continue;
132  }
133 
134  value = var.toMap();
136 
137  const QVariantList &ranks = value["list"].toList();
138  for(const QVariant &rank : qAsConst(ranks))
139  {
140  if(rank.isNull())
141  {
142  continue;
143  }
144 
145  value = rank.toMap();
147 
148  if(m_queryValue != value["sourceid"])
149  {
150  continue;
151  }
152 
153  MusicResultDataItem item;
154  item.m_name = value["name"].toString();
155  item.m_coverUrl = value["pic"].toString();
156  item.m_count = value["id"].toString();
157  item.m_description = value["intro"].toString();
158  item.m_time = value["pub"].toString();
159  Q_EMIT createToplistItem(item);
160  return;
161  }
162  }
163  }
164  }
165 }
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
QVariant toVariant() const
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
QString makeCoverPixmapUrl(const QString &url, const QString &id)
void createResultItem(const MusicResultInfoItem &result)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(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)
ParseError error
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:57
static constexpr const char * KW_SONG_LRC_URL
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
QNetworkAccessManager m_manager
#define TOPLIST_PAGE_SIZE
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
static constexpr const char * KW_TOPLIST_INFO_URL
QString makeSongArtist(const QString &name)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
virtual void downLoadFinished() overridefinal
void makeRequestRawHeader(QNetworkRequest *request) noexcept
void createToplistItem(const MusicResultDataItem &item)
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:295
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123