TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickgqueryplaylistrequest.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(KG_PLAYLIST_URL, false).arg(m_queryValue).arg(offset + 1).arg(m_pageSize));
21 
22  m_reply = m_manager.get(request);
23  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
25 }
26 
28 {
29  TTK_INFO_STREAM(className() << "startToSearch" << value);
30 
31  deleteAll();
32 
33  QNetworkRequest request;
34  request.setUrl(TTK::Algorithm::mdII(KG_PLAYLIST_INFO_URL, false).arg(value));
36 
37  QNetworkReply *reply = m_manager.get(request);
38  connect(reply, SIGNAL(finished()), SLOT(downloadDetailsFinished()));
40 }
41 
43 {
44  TTK_INFO_STREAM(className() << "startToQueryResult" << info->m_songId << bitrate << "kbps");
45 
51 }
52 
54 {
55  TTK_INFO_STREAM(className() << "startToQueryInfo" << item.m_id);
56 
58 
59  QNetworkRequest request;
60  request.setUrl(TTK::Algorithm::mdII(KG_PLAYLIST_DETAIL_URL, false).arg(item.m_id));
62 
63  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
64  if(bytes.isEmpty())
65  {
66  return;
67  }
68 
69  QJson::Parser json;
70  bool ok = false;
71  const QVariant &data = json.parse(bytes, &ok);
72  if(ok)
73  {
74  QVariantMap value = data.toMap();
75  if(value["errcode"].toInt() == 0 && value.contains("data"))
76  {
77  value = value["data"].toMap();
78  item.m_coverUrl = value["imgurl"].toString().replace("{size}", "400");
79  item.m_name = value["specialname"].toString();
80  item.m_count = value["playcount"].toString();
81  item.m_description = value["intro"].toString();
82  item.m_updateTime = value["publishtime"].toString();
83  item.m_nickName = value["nickname"].toString();
84  item.m_category.clear();
85 
86  const QVariantList &tags = value["tags"].toList();
87  for(const QVariant &var : qAsConst(tags))
88  {
89  if(var.isNull())
90  {
91  continue;
92  }
93 
94  value = var.toMap();
95 
96  item.m_category.append(value["tagname"].toString() + "|");
97  }
98 
99  if(!item.m_category.isEmpty())
100  {
101  item.m_category.insert(0, "|");
102  }
103  }
104  }
105 }
106 
108 {
109  TTK_INFO_STREAM(className() << "downLoadFinished");
110 
112  if(m_reply && m_reply->error() == QNetworkReply::NoError)
113  {
114  QJson::Parser json;
115  bool ok = false;
116  const QVariant &data = json.parse(m_reply->readAll(), &ok);
117  if(ok)
118  {
119  QVariantMap value = data.toMap();
120  if(value["errcode"].toInt() == 0)
121  {
122  value = value["data"].toMap();
123  m_totalSize = value["total"].toInt();
124 
125  const QVariantList &datas = value["info"].toList();
126  for(const QVariant &var : qAsConst(datas))
127  {
128  if(var.isNull())
129  {
130  continue;
131  }
132 
133  value = var.toMap();
135 
136  MusicResultDataItem item;
137  item.m_coverUrl = value["imgurl"].toString().replace("{size}", "400");
138  item.m_id = value["specialid"].toString();
139  item.m_name = value["specialname"].toString();
140  item.m_count = value["playcount"].toString();
141  item.m_description = value["intro"].toString();
142  item.m_updateTime = value["publishtime"].toString();
143  item.m_nickName = value["username"].toString();
144  Q_EMIT createPlaylistItem(item);
145  }
146  }
147  }
148  }
149 
150 // Q_EMIT downLoadDataChanged({});
151  deleteAll();
152 }
153 
155 {
156  TTK_INFO_STREAM(className() << "downloadDetailsFinished");
157 
159  QNetworkReply *reply = TTKObjectCast(QNetworkReply*, sender());
160  if(reply && reply->error() == QNetworkReply::NoError)
161  {
162  QJson::Parser json;
163  bool ok = false;
164  const QVariant &data = json.parse(reply->readAll(), &ok);
165  if(ok)
166  {
167  QVariantMap value = data.toMap();
168  if(value["errcode"].toInt() == 0 && value.contains("data"))
169  {
170  value = value["data"].toMap();
171 
172  const QVariantList &datas = value["info"].toList();
173  for(const QVariant &var : qAsConst(datas))
174  {
175  if(var.isNull())
176  {
177  continue;
178  }
179 
180  value = var.toMap();
182 
184  info.m_songId = value["hash"].toString();
185 
186  info.m_albumId = value["album_id"].toString();
187 
188  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
189  info.m_year.clear();
190  info.m_trackNumber = "0";
191 
195  ReqKGInterface::parseFromSongAlbumInfo(&info, value["album_audio_id"].toString());
199 
200  Q_EMIT createResultItem({info, serverToString()});
201  m_items << info;
202  }
203  }
204  }
205  }
206 
207  Q_EMIT downLoadDataChanged({});
208 }
#define TTK_NETWORK_QUERY_CHECK(VALUE)
virtual void startToPage(int offset) overridefinal
The class of the search result data item.
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
QNetworkReply * m_reply
virtual void downLoadFinished() overridefinal
static constexpr const char * QUERY_KG_INTERFACE
static constexpr const char * KG_PLAYLIST_URL
playlist url
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
The class of the query playlist download data from net.
virtual void downLoadFinished()
void makeRequestRawHeader(QNetworkRequest *request)
void createPlaylistItem(const MusicResultDataItem &item)
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
virtual void startToSearch(const QString &value) overridefinal
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
virtual void startToQueryInfo(MusicResultDataItem &item) overridefinal
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
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
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
static constexpr const char * KG_PLAYLIST_INFO_URL
#define SONG_PAGE_SIZE
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
static constexpr const char * KG_PLAYLIST_DETAIL_URL
MusicKGQueryPlaylistRequest(QObject *parent=nullptr)
TTK_MODULE_EXPORT QString toString(Record type)
void parseFromSongAlbumLrc(TTK::MusicSongInformation *info)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
void parseFromSongAlbumInfo(TTK::MusicSongInformation *info, const QString &album)
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
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
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60