TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwyquerymovierequest.cpp
Go to the documentation of this file.
2 
3 namespace ReqWYInterface
4 {
8  static void parseFromMovieProperty(QString &url, const QString &id, int bitrate);
9 
10 }
11 
12 void ReqWYInterface::parseFromMovieProperty(QString &url, const QString &id, int bitrate)
13 {
14  QNetworkRequest request;
15  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
17  TTK::Algorithm::mdII(WY_VIDEO_PATH_DATA_URL, false).arg(id).arg(bitrate));
18 
19  const QByteArray &bytes = TTK::syncNetworkQueryForPost(&request, parameter);
20  if(bytes.isEmpty())
21  {
22  return;
23  }
24 
25  QJson::Parser json;
26  bool ok = false;
27  const QVariant &data = json.parse(bytes, &ok);
28  if(ok)
29  {
30  QVariantMap value = data.toMap();
31  if(value["code"].toInt() == 200)
32  {
33  const QVariantList &datas = value["urls"].toList();
34  for(const QVariant &var : qAsConst(datas))
35  {
36  if(var.isNull())
37  {
38  continue;
39  }
40 
41  value = var.toMap();
42  url = value["url"].toString();
43 
44  if(!url.isEmpty())
45  {
46  return;
47  }
48  }
49  }
50  }
51 }
52 
53 
56 {
58 }
59 
61 {
62  TTK_INFO_STREAM(className() << "startToPage" << offset);
63 
64  if(needToUnity())
65  {
67  return;
68  }
69 
70  deleteAll();
71  m_totalSize = 0;
73 
74  QNetworkRequest request;
75  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
77  TTK::Algorithm::mdII(WY_SONG_SEARCH_DATA_URL, false).arg(1014).arg(m_queryValue).arg(m_pageSize * offset).arg(m_pageSize).toUtf8());
78 
79  m_reply = m_manager.post(request, parameter);
80  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
82 }
83 
84 void MusicWYQueryMovieRequest::startToSearch(const QString &value)
85 {
86  resetUnity();
88 }
89 
91 {
92  TTK_INFO_STREAM(className() << "startToSearchByID" << value);
93 
94  deleteAll();
95  m_queryValue = value;
96 
98 }
99 
101 {
102  TTK_INFO_STREAM(className() << "downLoadFinished");
103 
105  if(m_reply && m_reply->error() == QNetworkReply::NoError)
106  {
107  QJson::Parser json;
108  bool ok = false;
109  const QVariant &data = json.parse(m_reply->readAll(), &ok);
110  if(ok)
111  {
112  QVariantMap value = data.toMap();
113  if(value["code"].toInt() == 200)
114  {
115  value = value["result"].toMap();
116  m_totalSize = value["videoCount"].toInt();
117 
118  const QVariantList &datas = value["videos"].toList();
119  for(const QVariant &var : qAsConst(datas))
120  {
121  if(var.isNull())
122  {
123  continue;
124  }
125 
126  value = var.toMap();
128 
129  const int type = value["type"].toInt();
130  if(type == 0)
131  {
132  const qint64 vid = value["vid"].toLongLong();
133  if(vid == 0)
134  {
135  continue;
136  }
137 
139  parseFromMovieList(vid);
141  }
142  else if(type == 1)
143  {
145  parseFromVideoList(value["vid"].toString());
147  }
148  }
149  }
150  }
151  }
152 
153  if(!pageValid())
154  {
155  setToUnity();
156  }
157 
158  Q_EMIT downLoadDataChanged({});
159  deleteAll();
160 }
161 
163 {
164  TTK_INFO_STREAM(className() << "downLoadSingleFinished");
165 
167 
168  const qint64 vid = m_queryValue.toLongLong();
169  if(vid != 0)
170  {
172  parseFromMovieList(vid);
174  }
175 
176  Q_EMIT downLoadDataChanged({});
177  deleteAll();
178 }
179 
181 {
182  QNetworkRequest request;
183  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
185  TTK::Algorithm::mdII(WY_MOVIE_DATA_URL, false).arg(id));
186 
187  const QByteArray &bytes = TTK::syncNetworkQueryForPost(&request, parameter);
188  if(bytes.isEmpty())
189  {
190  return;
191  }
192 
193  QJson::Parser json;
194  bool ok = false;
195  const QVariant &data = json.parse(bytes, &ok);
196  if(ok)
197  {
198  QVariantMap value = data.toMap();
199  if(value["code"].toInt() == 200)
200  {
201  value = value["data"].toMap();
203 
205  info.m_songId = QString::number(id);
206  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
207 
208  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, value["artistName"].toString());
209 
210  info.m_coverUrl = value["cover"].toString();
211  info.m_duration = TTKTime::formatDuration(value["duration"].toInt());
212 
213  value = value["brs"].toMap();
214  for(const QString &key : value.keys())
215  {
216  const int bitrate = key.toInt();
218  if(bitrate <= 375)
219  {
220  prop.m_bitrate = TTK_BN_250;
221  }
222  else if(bitrate > 375 && bitrate <= 625)
223  {
224  prop.m_bitrate = TTK_BN_500;
225  }
226  else if(bitrate > 625 && bitrate <= 875)
227  {
228  prop.m_bitrate = TTK_BN_750;
229  }
230  else if(bitrate > 875)
231  {
232  prop.m_bitrate = TTK_BN_1000;
233  }
234 
235  prop.m_url = value[key].toString();
237 
238  if(!findUrlPathSize(&prop, info.m_duration))
239  {
240  continue;
241  }
242 
243  info.m_songProps.append(prop);
244  }
245 
246  if(info.m_songProps.isEmpty())
247  {
248  return;
249  }
250 
251  Q_EMIT createResultItem({info, serverToString()});
252  m_items << info;
253  }
254  }
255 }
256 
258 {
259  QNetworkRequest request;
260  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
263 
264  const QByteArray &bytes = TTK::syncNetworkQueryForPost(&request, parameter);
265  if(bytes.isEmpty())
266  {
267  return;
268  }
269 
270  QJson::Parser json;
271  bool ok = false;
272  const QVariant &data = json.parse(bytes, &ok);
273  if(ok)
274  {
275  QVariantMap value = data.toMap();
276  if(value["code"].toInt() == 200)
277  {
278  value = value["data"].toMap();
280 
282  info.m_songId = id;
283  info.m_songName = TTK::String::charactersReplace(value["title"].toString());
284 
285  const QVariantMap &artistObject = value["creator"].toMap();
286  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["nickname"].toString());
287 
288  info.m_coverUrl = value["cover"].toString();
289  info.m_duration = TTKTime::formatDuration(value["durationms"].toInt());
290 
291  const QVariantList &datas = value["resolutions"].toList();
292  for(const QVariant &var : qAsConst(datas))
293  {
294  if(var.isNull())
295  {
296  continue;
297  }
298 
299  value = var.toMap();
301 
302  const int bitrate = value["resolution"].toInt();
306 
307  if(prop.isEmpty())
308  {
309  continue;
310  }
311 
312  if(bitrate <= 375)
313  {
314  prop.m_bitrate = TTK_BN_250;
315  }
316  else if(bitrate > 375 && bitrate <= 625)
317  {
318  prop.m_bitrate = TTK_BN_500;
319  }
320  else if(bitrate > 625 && bitrate <= 875)
321  {
322  prop.m_bitrate = TTK_BN_750;
323  }
324  else if(bitrate > 875)
325  {
326  prop.m_bitrate = TTK_BN_1000;
327  }
328 
329  prop.m_size = TTK::Number::sizeByteToLabel(value["size"].toInt());
331  info.m_songProps.append(prop);
332  }
333 
334  if(info.m_songProps.isEmpty())
335  {
336  return;
337  }
338 
339  Q_EMIT createResultItem({info, serverToString()});
340  m_items << info;
341  }
342  }
343 }
344 
345 
346 
348  : MusicQueryMovieRequest(parent)
349 {
352 }
353 
355 {
356  TTK_INFO_STREAM(className() << "startToPage" << offset);
357 
358  deleteAll();
359  m_totalSize = 0;
361 
362  QNetworkRequest request;
363  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
366 
367  m_reply = m_manager.post(request, parameter);
368  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
370 }
371 
373 {
374  TTK_INFO_STREAM(className() << "downLoadFinished");
375 
377  if(m_reply && m_reply->error() == QNetworkReply::NoError)
378  {
379  QJson::Parser json;
380  bool ok = false;
381  const QVariant &data = json.parse(m_reply->readAll(), &ok);
382  if(ok)
383  {
384  QVariantMap value = data.toMap();
385  if(value["code"].toInt() == 200 && value.contains("mvs"))
386  {
390 
391  const QVariantList &datas = value["mvs"].toList();
392  for(const QVariant &var : qAsConst(datas))
393  {
394  if(var.isNull())
395  {
396  continue;
397  }
398 
399  value = var.toMap();
401 
402  MusicResultDataItem item;
403  item.m_id = value["id"].toString();
404  item.m_coverUrl = value["imgurl"].toString();
405  item.m_name = value["name"].toString();
406  item.m_updateTime.clear();
407  Q_EMIT createMovieItem(item);
408  }
409  }
410  }
411  }
412 
413  Q_EMIT downLoadDataChanged({});
414  deleteAll();
415 }
416 
418 {
420 
421  QNetworkRequest request;
422  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
424  TTK::Algorithm::mdII(WY_ARTIST_MOVIE_DATA_URL, false).arg(id).arg(0).arg(m_totalSize));
425 
426  const QByteArray &bytes = TTK::syncNetworkQueryForPost(&request, parameter);
427  if(bytes.isEmpty())
428  {
429  return;
430  }
431 
432  QJson::Parser json;
433  bool ok = false;
434  const QVariant &data = json.parse(bytes, &ok);
435  if(ok)
436  {
437  const QVariantMap &value = data.toMap();
438  if(value["code"].toInt() == 200 && value.contains("mvs"))
439  {
440  m_totalSize = value["mvs"].toList().count();
441  }
442  }
443 }
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForPost(QNetworkRequest *request, const QByteArray &data)
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
bool pageValid() const noexcept
#define TTK_NETWORK_QUERY_CHECK(VALUE)
static constexpr const char * WY_SONG_SEARCH_URL
song url
The class of the search result data item.
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
static constexpr const char * WY_ARTIST_MOVIE_DATA_URL
QNetworkReply * m_reply
The class of the unity query mv download data from net.
The class of the music song property.
Definition: musicobject.h:223
static constexpr wchar_t key[]
QString makeSongArtist(const QString &in, const QString &name)
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
virtual void downLoadFinished() overridefinal
#define TTK_BN_1000
Definition: ttkglobal.h:354
static constexpr const char * WY_MOVIE_URL
movie url
virtual void startToSearchByID(const QString &value) overridefinal
virtual void downLoadFinished()
void createMovieItem(const MusicResultDataItem &item)
#define TTK_BN_250
Definition: ttkglobal.h:350
void parseFromVideoList(const QString &id)
static constexpr const char * WY_VIDEO_INFO_DATA_URL
#define TTK_BN_500
Definition: ttkglobal.h:352
voidpf uLong offset
Definition: ioapi.h:142
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:53
static constexpr const char * QUERY_WY_INTERFACE
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:177
The class of the query movie download data from net.
QNetworkAccessManager m_manager
MusicWYQueryArtistMovieRequest(QObject *parent=nullptr)
void createResultItem(const MusicResultInfoItem &songItem)
static constexpr const char * WY_VIDEO_PATH_DATA_URL
bool isEmpty() const noexcept
Definition: musicobject.h:236
The namespace of the wangyi request interface.
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 startToPage(int offset) overridefinal
virtual void downLoadFinished() override
#define ARTIST_ATTR_PAGE_SIZE
TTK_MODULE_EXPORT QString splitToken(const QString &name)
static constexpr const char * WY_SONG_SEARCH_DATA_URL
MusicWYQueryMovieRequest(QObject *parent=nullptr)
#define TTK_HIGH_LEVEL
Definition: ttkglobal.h:255
virtual void downLoadFinished() overridefinal
QByteArray makeTokenRequest(QNetworkRequest *request, const QString &query, const QString &type)
virtual void startToPage(int offset) overridefinal
virtual void startToSearch(const QString &value) override
TTK_MODULE_EXPORT QString toString(Record type)
static void parseFromMovieProperty(QString &url, const QString &id, int bitrate)
virtual void startToPage(int offset) override
static constexpr const char * WY_ARTIST_MOVIE_URL
virtual void startToSearch(const QString &value) overridefinal
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 * WY_VIDEO_PATH_URL
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the music song information.
Definition: musicobject.h:281
#define TTK_BN_750
Definition: ttkglobal.h:353
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123
static constexpr const char * WY_VIDEO_INFO_URL
static constexpr const char * WY_MOVIE_DATA_URL