TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickgquerymovierequest.cpp
Go to the documentation of this file.
2 
3 namespace ReqKGInterface
4 {
12  static void parseFromMovieProperty(TTK::MusicSongInformation *info, bool more);
16  static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QVariantMap &key);
17 
18 }
19 
21 {
22  if(info->m_songId.isEmpty())
23  {
24  return;
25  }
26 
27  QNetworkRequest request;
28  request.setUrl(TTK::Algorithm::mdII(KG_MOVIE_URL, false).arg(info->m_songId));
30 
31  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
32  if(bytes.isEmpty())
33  {
34  return;
35  }
36 
37  QRegExp regx;
38  const QString text(bytes);
39 
40  regx.setPattern("mv_hash\\s?=\\s?\"([^\"]+)");
41  if(regx.indexIn(text) != -1)
42  {
43  info->m_songId = regx.cap(1);
44  }
45 
46  regx.setPattern("mv_pic\\s?=\\s?\"([^\"]+)");
47  if(regx.indexIn(text) != -1)
48  {
49  info->m_coverUrl = regx.cap(1);
50  }
51 }
52 
54 {
55  if(info->m_songId.isEmpty())
56  {
57  return;
58  }
59 
60  const QByteArray &encodedData = TTK::Algorithm::md5(QString("%1kugoumvcloud").arg(info->m_songId).toUtf8());
61 
62  QNetworkRequest request;
63  request.setUrl(TTK::Algorithm::mdII(KG_MOVIE_INFO_URL, false).arg(encodedData, info->m_songId));
65 
66  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
67  if(bytes.isEmpty())
68  {
69  return;
70  }
71 
72  QJson::Parser json;
73  bool ok = false;
74  const QVariant &data = json.parse(bytes, &ok);
75  if(ok)
76  {
77  QVariantMap value = data.toMap();
78  if(value.contains("mvdata"))
79  {
80  if(more)
81  {
82  info->m_songName = TTK::String::charactersReplace(value["songname"].toString());
83  info->m_artistName = ReqKGInterface::makeSongArtist(value["singer"].toString());
84  }
85 
86  value = value["mvdata"].toMap();
87 
88  QVariantMap mv = value["sd"].toMap();
89  if(!mv.isEmpty())
90  {
91  parseFromMovieProperty(info, mv);
92  }
93 
94  mv = value["hd"].toMap();
95  if(!mv.isEmpty())
96  {
97  parseFromMovieProperty(info, mv);
98  }
99 
100  mv = value["sq"].toMap();
101  if(!mv.isEmpty())
102  {
103  parseFromMovieProperty(info, mv);
104  }
105 
106  mv = value["rq"].toMap();
107  if(!mv.isEmpty())
108  {
109  parseFromMovieProperty(info, mv);
110  }
111  }
112  }
113 }
114 
116 {
118  prop.m_url = key["downurl"].toString();
119  prop.m_size = TTK::Number::sizeByteToLabel(key["filesize"].toInt());
121 
122  const int bitrate = key["bitrate"].toInt() / 1000;
123  if(bitrate <= 375)
124  {
125  prop.m_bitrate = TTK_BN_250;
126  }
127  else if(bitrate > 375 && bitrate <= 625)
128  {
129  prop.m_bitrate = TTK_BN_500;
130  }
131  else if(bitrate > 625 && bitrate <= 875)
132  {
133  prop.m_bitrate = TTK_BN_750;
134  }
135  else if(bitrate > 875)
136  {
137  prop.m_bitrate = TTK_BN_1000;
138  }
139 
140  if(info->m_duration.isEmpty())
141  {
142  info->m_duration = TTKTime::formatDuration(key["timelength"].toInt());
143  }
144  info->m_songProps.append(prop);
145 }
146 
147 
150 {
152 }
153 
155 {
156  TTK_INFO_STREAM(className() << "startToPage" << offset);
157 
158  if(needToUnity())
159  {
161  return;
162  }
163 
164  deleteAll();
165  m_totalSize = 0;
167 
168  QNetworkRequest request;
169  request.setUrl(TTK::Algorithm::mdII(KG_SONG_SEARCH_URL, false).arg(m_queryValue).arg(offset + 1).arg(m_pageSize));
171 
172  m_reply = m_manager.get(request);
173  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
175 }
176 
177 void MusicKGQueryMovieRequest::startToSearch(const QString &value)
178 {
179  resetUnity();
181 }
182 
184 {
185  TTK_INFO_STREAM(className() << "startToSearchByID" << value);
186 
187  deleteAll();
188  m_queryValue = value;
189 
191 }
192 
194 {
195  TTK_INFO_STREAM(className() << "downLoadFinished");
196 
198  if(m_reply && m_reply->error() == QNetworkReply::NoError)
199  {
200  QJson::Parser json;
201  bool ok = false;
202  const QVariant &data = json.parse(m_reply->readAll(), &ok);
203  if(ok)
204  {
205  QVariantMap value = data.toMap();
206  if(value.contains("data"))
207  {
208  value = value["data"].toMap();
209  m_totalSize = value["total"].toInt();
210 
211  const QVariantList &datas = value["info"].toList();
212  for(const QVariant &var : qAsConst(datas))
213  {
214  if(var.isNull())
215  {
216  continue;
217  }
218 
219  value = var.toMap();
221 
223  info.m_songId = value["mvhash"].toString();
224  info.m_songName = TTK::String::charactersReplace(value["songname"].toString());
225 
226  info.m_artistName = ReqKGInterface::makeSongArtist(value["singername"].toString());
227 
228  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
229 
233 
234  if(info.m_songProps.isEmpty())
235  {
236  continue;
237  }
238 
239  Q_EMIT createResultItem({info, serverToString()});
240  m_items << info;
241  }
242  }
243  }
244  }
245 
246  if(!pageValid())
247  {
248  setToUnity();
249  }
250 
251  Q_EMIT downLoadDataChanged({});
252  deleteAll();
253 }
254 
256 {
257  TTK_INFO_STREAM(className() << "downLoadSingleFinished");
258 
260 
262  info.m_songId = m_queryValue;
263 
269 
270  if(!info.m_songProps.isEmpty())
271  {
272  Q_EMIT createResultItem({info, serverToString()});
273  m_items << info;
274  }
275 
276  Q_EMIT downLoadDataChanged({});
277  deleteAll();
278 }
279 
280 
281 
283  : MusicQueryMovieRequest(parent)
284 {
287 }
288 
290 {
291  TTK_INFO_STREAM(className() << "startToPage" << offset);
292 
293  deleteAll();
294  m_totalSize = 0;
296 
297  QNetworkRequest request;
298  request.setUrl(TTK::Algorithm::mdII(KG_ARTIST_MOVIE_URL, false).arg(m_queryValue).arg(offset + 1).arg(m_pageSize));
300 
301  m_reply = m_manager.get(request);
302  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
304 }
305 
307 {
308  TTK_INFO_STREAM(className() << "downLoadFinished");
309 
311  if(m_reply && m_reply->error() == QNetworkReply::NoError)
312  {
313  QJson::Parser json;
314  bool ok = false;
315  const QVariant &data = json.parse(m_reply->readAll(), &ok);
316  if(ok)
317  {
318  QVariantMap value = data.toMap();
319  if(value.contains("data") && value["errcode"].toInt() == 0)
320  {
321  value = value["data"].toMap();
322  m_totalSize = value["total"].toInt();
323 
324  const QVariantList &datas = value["info"].toList();
325  for(const QVariant &var : qAsConst(datas))
326  {
327  if(var.isNull())
328  {
329  continue;
330  }
331 
332  value = var.toMap();
334 
335  MusicResultDataItem item;
336  item.m_id = value["hash"].toString();
337  item.m_coverUrl = value["imgurl"].toString();
338  item.m_name = value["filename"].toString();
339  item.m_updateTime.clear();
340  Q_EMIT createMovieItem(item);
341  }
342  }
343  }
344  }
345 
346  Q_EMIT downLoadDataChanged({});
347  deleteAll();
348 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
virtual void startToPage(int offset) overridefinal
virtual void downLoadFinished() overridefinal
bool pageValid() const noexcept
#define TTK_NETWORK_QUERY_CHECK(VALUE)
TTK_MODULE_EXPORT QByteArray md5(const QByteArray &data)
The class of the search result data item.
static void parseFromMovieProperty(TTK::MusicSongInformation *info, bool more)
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
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 const char * QUERY_KG_INTERFACE
static constexpr wchar_t key[]
MusicKGQueryArtistMovieRequest(QObject *parent=nullptr)
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
virtual void startToSearch(const QString &value) overridefinal
QString makeSongArtist(const QString &name)
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
#define TTK_BN_1000
Definition: ttkglobal.h:354
virtual void downLoadFinished()
void createMovieItem(const MusicResultDataItem &item)
The namespace of the kugou request interface.
void makeRequestRawHeader(QNetworkRequest *request)
#define TTK_BN_250
Definition: ttkglobal.h:350
#define TTK_BN_500
Definition: ttkglobal.h:352
voidpf uLong offset
Definition: ioapi.h:142
TTK::MusicSongInformationList m_items
virtual void startToSearchByID(const QString &value) overridefinal
#define qAsConst
Definition: ttkqtglobal.h:53
#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
void createResultItem(const MusicResultInfoItem &songItem)
static constexpr const char * KG_SONG_SEARCH_URL
song url
virtual void downLoadFinished() overridefinal
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
static void parseFromMovieInfo(TTK::MusicSongInformation *info)
virtual void downLoadFinished() override
#define ARTIST_ATTR_PAGE_SIZE
TTK_MODULE_EXPORT QString splitToken(const QString &name)
static constexpr const char * KG_MOVIE_URL
movie url
static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QVariantMap &key)
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
virtual void startToSearch(const QString &value) override
TTK_MODULE_EXPORT QString toString(Record type)
virtual void startToPage(int offset) override
MusicKGQueryMovieRequest(QObject *parent=nullptr)
static constexpr const char * KG_MOVIE_INFO_URL
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
static constexpr const char * KG_ARTIST_MOVIE_URL
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
virtual void startToPage(int offset) overridefinal