TTKMusicPlayer  4.3.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 static constexpr const char *KG_MOVIE_URL = "SXBFRzlFelBDNXoybnRvamNoc2R3QTdlZ0syWXN3MjY3N1puUHZIZjJXRGYxUzBkS2xEKzdCR1NkTTA9";
4 static constexpr const char *KG_ARTIST_MOVIE_URL = "M3E4VGoxSkNEWXh4WjJSY1FRRTdGb3RJOUQ2MXI0M3hDS0Mvd1BzeFBzS3VFNGlqU0pQei9KTzhBU1VkZHZ6WUc4dDFyclhDZG55Q2Y2d1Z1YnA0QzIrYnl2d3ZKMnlQZEp5ajlnPT0=";
5 
6 namespace ReqKGInterface
7 {
15  static void parseFromMovieProperty(TTK::MusicSongInformation *info, bool more);
19  static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QVariantMap &key);
20 
21 }
22 
24 {
25  if(info->m_songId.isEmpty())
26  {
27  return;
28  }
29 
30  QNetworkRequest request;
31  request.setUrl(TTK::Algorithm::mdII(KG_MOVIE_URL, false).arg(info->m_songId));
33 
34  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
35  if(bytes.isEmpty())
36  {
37  return;
38  }
39 
40  const QString text(bytes);
41 
42  static TTKRegularExpression regx1("mv_hash\\s?=\\s?\"([^\"]+)");
43  if(regx1.match(text) != -1)
44  {
45  info->m_songId = regx1.captured(1);
46  }
47 
48  static TTKRegularExpression regx2("mv_pic\\s?=\\s?\"([^\"]+)");
49  if(regx2.match(text) != -1)
50  {
51  info->m_coverUrl = regx2.captured(1);
52  }
53 }
54 
56 {
57  if(info->m_songId.isEmpty())
58  {
59  return;
60  }
61 
62  const QByteArray &key = TTK::Algorithm::md5(QString("%1kugoumvcloud").arg(info->m_songId).toUtf8());
63 
64  QNetworkRequest request;
65  request.setUrl(TTK::Algorithm::mdII(KG_MOVIE_INFO_URL, false).arg(key, info->m_songId));
67 
68  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
69  if(bytes.isEmpty())
70  {
71  return;
72  }
73 
74  QJsonParseError ok;
75  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
77  {
78  QVariantMap value = json.toVariant().toMap();
79  if(value.contains("mvdata"))
80  {
81  if(more)
82  {
83  info->m_songName = TTK::String::charactersReplace(value["songname"].toString());
84  info->m_artistName = ReqKGInterface::makeSongArtist(value["singer"].toString());
85  }
86 
87  value = value["mvdata"].toMap();
88 
89  QVariantMap mv = value["sd"].toMap();
90  if(!mv.isEmpty())
91  {
92  parseFromMovieProperty(info, mv);
93  }
94 
95  mv = value["hd"].toMap();
96  if(!mv.isEmpty())
97  {
98  parseFromMovieProperty(info, mv);
99  }
100 
101  mv = value["sq"].toMap();
102  if(!mv.isEmpty())
103  {
104  parseFromMovieProperty(info, mv);
105  }
106 
107  mv = value["rq"].toMap();
108  if(!mv.isEmpty())
109  {
110  parseFromMovieProperty(info, mv);
111  }
112  }
113  }
114 }
115 
117 {
119  prop.m_url = key["downurl"].toString();
120  prop.m_size = TTK::Number::sizeByteToLabel(key["filesize"].toInt());
122 
123  const int bitrate = key["bitrate"].toInt() / 1000;
124  if(bitrate <= 375)
125  {
126  prop.m_bitrate = TTK_BN_250;
127  }
128  else if(bitrate > 375 && bitrate <= 625)
129  {
130  prop.m_bitrate = TTK_BN_500;
131  }
132  else if(bitrate > 625 && bitrate <= 875)
133  {
134  prop.m_bitrate = TTK_BN_750;
135  }
136  else if(bitrate > 875)
137  {
138  prop.m_bitrate = TTK_BN_1000;
139  }
140 
141  if(info->m_duration.isEmpty())
142  {
143  info->m_duration = TTKTime::formatDuration(key["timelength"].toInt());
144  }
145  info->m_songProps.append(prop);
146 }
147 
148 
151 {
153 }
154 
156 {
157  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__ << offset);
158 
159  if(needToUnity())
160  {
162  return;
163  }
164 
165  deleteAll();
166  m_totalSize = 0;
168 
169  QNetworkRequest request;
170  request.setUrl(TTK::Algorithm::mdII(KG_SEARCH_URL, false).arg(m_queryValue).arg(offset + 1).arg(m_pageSize));
172 
173  m_reply = m_manager.get(request);
174  connect(m_reply, SIGNAL(finished()), SLOT(downloadFinished()));
176 }
177 
178 void MusicKGQueryMovieRequest::startToSearch(const QString &value)
179 {
180  resetUnity();
182 }
183 
185 {
186  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__ << value);
187 
188  deleteAll();
189  m_queryValue = value;
190 
192 }
193 
195 {
196  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__);
197 
199  if(m_reply && m_reply->error() == QNetworkReply::NoError)
200  {
201  QJsonParseError ok;
202  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
204  {
205  QVariantMap value = json.toVariant().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(metaObject()->className() << __FUNCTION__);
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(metaObject()->className() << __FUNCTION__ << 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(metaObject()->className() << __FUNCTION__);
309 
311  if(m_reply && m_reply->error() == QNetworkReply::NoError)
312  {
313  QJsonParseError ok;
314  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
316  {
317  QVariantMap value = json.toVariant().toMap();
318  if(value["errcode"].toInt() == 0 && value.contains("data"))
319  {
320  value = value["data"].toMap();
321  m_totalSize = value["total"].toInt();
322 
323  const QVariantList &datas = value["info"].toList();
324  for(const QVariant &var : qAsConst(datas))
325  {
326  if(var.isNull())
327  {
328  continue;
329  }
330 
331  value = var.toMap();
333 
334  MusicResultDataItem item;
335  item.m_id = value["hash"].toString();
336  item.m_name = value["filename"].toString();
337  item.m_coverUrl = value["imgurl"].toString();
338  item.m_time.clear();
339  Q_EMIT createMovieItem(item);
340  }
341  }
342  }
343  }
344 
345  Q_EMIT downloadDataChanged({});
346  deleteAll();
347 }
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)
The class of the search result data item.
static void parseFromMovieProperty(TTK::MusicSongInformation *info, bool more)
virtual void deleteAll()
QString captured(int index) const
QNetworkReply * m_reply
void downloadDataChanged(const QString &bytes)
The class of the unity query mv data from net.
QVariant toVariant() const
The class of the music song property.
Definition: musicobject.h:242
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
static constexpr const char * QUERY_KG_INTERFACE
MusicKGQueryArtistMovieRequest(QObject *parent=nullptr)
MusicSongPropertyList m_songProps
Definition: musicobject.h:314
virtual void startToSearch(const QString &value) overridefinal
void createResultItem(const MusicResultInfoItem &result)
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:434
static constexpr const char * KG_SEARCH_URL
void createMovieItem(const MusicResultDataItem &item)
The namespace of the kugou request interface.
#define TTK_BN_250
Definition: ttkglobal.h:430
TTK_MODULE_EXPORT QByteArray md5(const QByteArray &data, bool base64=false)
static constexpr const char * KG_MOVIE_URL
#define TTK_BN_500
Definition: ttkglobal.h:432
voidpf uLong offset
Definition: ioapi.h:142
ParseError error
TTK::MusicSongInformationList m_items
virtual void startToSearchByID(const QString &value) overridefinal
#define qAsConst
Definition: ttkqtglobal.h:57
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:189
The class of the query movie data from net.
QNetworkAccessManager m_manager
static constexpr wchar_t key[]
virtual void downloadFinished() overridefinal
virtual void replyError(QNetworkReply::NetworkError error) override
#define TTK_SLOT
Definition: ttkqtglobal.h:177
static void parseFromMovieInfo(TTK::MusicSongInformation *info)
TTK_MODULE_EXPORT QString splitToken(const QString &name)
static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QVariantMap &key)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
The class of the regular expression.
virtual void downloadFinished()
virtual void startToSearch(const QString &value) override
virtual void startToPage(int offset) override
MusicKGQueryMovieRequest(QObject *parent=nullptr)
static constexpr const char * KG_ARTIST_MOVIE_URL
static constexpr const char * KG_MOVIE_INFO_URL
#define TTK_PAGE_SIZE_12
virtual void downloadFinished() override
int match(const QString &str, int pos=0)
void makeRequestRawHeader(QNetworkRequest *request) noexcept
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the music song information.
Definition: musicobject.h:300
#define TTK_BN_750
Definition: ttkglobal.h:433
#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