TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickwquerymovierequest.cpp
Go to the documentation of this file.
2 
4 
5 namespace ReqKWInterface
6 {
14  static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format);
18  static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format, int bitrate);
19 
20 }
21 
23 {
24  if(info->m_songId.isEmpty())
25  {
26  return;
27  }
28 
29  info->m_songName = "Not Found";
30  info->m_artistName = "Anonymous";
31 
32  QNetworkRequest request;
33  request.setUrl(TTK::Algorithm::mdII(KW_SONG_INFO_URL, false).arg(info->m_songId));
35 
36  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
37  if(bytes.isEmpty())
38  {
39  return;
40  }
41 
42  QJsonParseError ok;
43  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
45  {
46  QVariantMap value = json.toVariant().toMap();
47  if(value.contains("data"))
48  {
49  value = value["data"].toMap();
50  info->m_songName = TTK::String::charactersReplace(value["name"].toString());
51  info->m_artistName = ReqKWInterface::makeSongArtist(value["artist"].toString());
52  info->m_coverUrl = value["pic"].toString();
53  info->m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
54  }
55  }
56 }
57 
59 {
60  if(info->m_songId.isEmpty())
61  {
62  return;
63  }
64 
65  for(const QString &v : format.split("|"))
66  {
67  if(v.contains("MP4L"))
68  {
69  parseFromMovieProperty(info, "MP4L", TTK_BN_250);
70  }
71  else if(v.contains("MP4HV"))
72  {
73  parseFromMovieProperty(info, "MP4HV", TTK_BN_750);
74  }
75  else if(v.contains("MP4UL"))
76  {
77  parseFromMovieProperty(info, "MP4UL", TTK_BN_1000);
78  }
79  else if(v.contains("MP4"))
80  {
81  parseFromMovieProperty(info, "MP4", TTK_BN_500);
82  }
83  }
84 }
85 
86 void ReqKWInterface::parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format, int bitrate)
87 {
88  if(info->m_songId.isEmpty())
89  {
90  return;
91  }
92 
93  QAlgorithm::Des des;
94  const QByteArray &parameter = des.encrypt(TTK::Algorithm::mdII(KW_MOVIE_ATTR_URL, false).arg(info->m_songId, format).toUtf8(),
95  TTK::Algorithm::mdII("OGlVTjJWOEdlMkkzSkZIeg==", MDII_SHR_KEY, false).toUtf8());
96  QNetworkRequest request;
97  request.setUrl(TTK::Algorithm::mdII(KW_MOVIE_URL, false).arg(QString(parameter)));
99 
100  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
101  if(bytes.isEmpty())
102  {
103  return;
104  }
105 
106  if(!bytes.contains("res not found"))
107  {
108  const QString text(bytes);
109  const QRegExp regx(".*url=(.*)\r\nsig=");
110 
111  if(regx.indexIn(text) != -1)
112  {
114  prop.m_url = regx.cap(1);
115  prop.m_size = TTK_DEFAULT_STR;
116  prop.m_format = MP4_FILE_SUFFIX;
117  prop.m_bitrate = bitrate;
118 
119  if(prop.isEmpty() || info->m_songProps.contains(prop))
120  {
121  return;
122  }
123 
124  info->m_songProps.append(prop);
125  }
126  }
127 }
128 
129 
132 {
134 }
135 
137 {
138  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
139 
140  if(needToUnity())
141  {
143  return;
144  }
145 
146  deleteAll();
147  m_totalSize = 0;
149 
150  QNetworkRequest request;
151  request.setUrl(TTK::Algorithm::mdII(KW_SONG_SEARCH_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
153 
154  m_reply = m_manager.get(request);
155  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
157 }
158 
159 void MusicKWQueryMovieRequest::startToSearch(const QString &value)
160 {
161  resetUnity();
163 }
164 
166 {
167  TTK_INFO_STREAM(className() << __FUNCTION__ << value);
168 
169  deleteAll();
170  m_queryValue = value;
171 
173 }
174 
176 {
177  TTK_INFO_STREAM(className() << __FUNCTION__);
178 
180  if(m_reply && m_reply->error() == QNetworkReply::NoError)
181  {
182  QJsonParseError ok;
183  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll().replace("'", "\""), &ok);
185  {
186  QVariantMap value = json.toVariant().toMap();
187  if(value.contains("abslist"))
188  {
189  m_totalSize = value["TOTAL"].toInt();
190 
191  const QVariantList &datas = value["abslist"].toList();
192  for(const QVariant &var : qAsConst(datas))
193  {
194  if(var.isNull())
195  {
196  continue;
197  }
198 
199  value = var.toMap();
201 
203  info.m_songId = value["MUSICRID"].toString().remove("MUSIC_");
204  info.m_songName = TTK::String::charactersReplace(value["SONGNAME"].toString());
205 
206  info.m_artistName = ReqKWInterface::makeSongArtist(value["ARTIST"].toString());
207 
208  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
209  info.m_duration = TTKTime::formatDuration(value["DURATION"].toInt() * TTK_DN_S2MS);
210 
212  ReqKWInterface::parseFromMovieProperty(&info, value["FORMATS"].toString());
214 
215  if(info.m_songProps.isEmpty() || !fetchUrlPathSize(&info.m_songProps, info.m_duration))
216  {
217  continue;
218  }
219 
220  Q_EMIT createResultItem({info, serverToString()});
221  m_items << info;
222  }
223  }
224  }
225  }
226 
227  if(!pageValid())
228  {
229  setToUnity();
230  }
231 
232  Q_EMIT downLoadDataChanged({});
233  deleteAll();
234 }
235 
237 {
238  TTK_INFO_STREAM(className() << __FUNCTION__);
239 
241 
243  info.m_songId = m_queryValue;
244 
248  ReqKWInterface::parseFromMovieProperty(&info, "MP4UL|MP4L|MP4HV|MP4");
250 
251  if(!info.m_songProps.isEmpty() && fetchUrlPathSize(&info.m_songProps, info.m_duration))
252  {
253  Q_EMIT createResultItem({info, serverToString()});
254  m_items << info;
255  }
256 
257  Q_EMIT downLoadDataChanged({});
258  deleteAll();
259 }
260 
261 
262 
264  : MusicQueryMovieRequest(parent)
265 {
268 }
269 
271 {
272  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
273 
274  deleteAll();
275  m_totalSize = 0;
277 
278  QNetworkRequest request;
279  request.setUrl(TTK::Algorithm::mdII(KW_ARTIST_MOVIE_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
281 
282  m_reply = m_manager.get(request);
283  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
285 }
286 
288 {
289  TTK_INFO_STREAM(className() << __FUNCTION__);
290 
292  if(m_reply && m_reply->error() == QNetworkReply::NoError)
293  {
294  QJsonParseError ok;
295  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll().replace("'", "\""), &ok);
297  {
298  QVariantMap value = json.toVariant().toMap();
299  if(value.contains("mvlist"))
300  {
301  m_totalSize = value["total"].toInt();
302 
303  const QVariantList &datas = value["mvlist"].toList();
304  for(const QVariant &var : qAsConst(datas))
305  {
306  if(var.isNull())
307  {
308  continue;
309  }
310 
311  value = var.toMap();
313 
314  MusicResultDataItem item;
315  item.m_id = value["musicid"].toString();
316  item.m_coverUrl = value["pic"].toString();
318  {
320  }
321  item.m_name = value["name"].toString();
322  item.m_time.clear();
323  Q_EMIT createMovieItem(item);
324  }
325  }
326  }
327  }
328 
329  Q_EMIT downLoadDataChanged({});
330  deleteAll();
331 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
bool pageValid() const noexcept
#define TTK_NETWORK_QUERY_CHECK(VALUE)
virtual void startToSearch(const QString &value) overridefinal
static void parseFromMovieInfo(TTK::MusicSongInformation *info)
The class of the search result data item.
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
QNetworkReply * m_reply
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:276
MusicKWQueryArtistMovieRequest(QObject *parent=nullptr)
static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format)
The class of the unity query mv download data from net.
QVariant toVariant() const
The class of the music song property.
Definition: musicobject.h:237
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
virtual void downLoadFinished() overridefinal
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
QString makeCoverPixmapUrl(const QString &url, const QString &id)
void createResultItem(const MusicResultInfoItem &result)
QByteArray encrypt(const QByteArray &in, const QByteArray &key)
Definition: deswrapper.cpp:349
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
#define TTK_BN_1000
Definition: ttkglobal.h:434
virtual void downLoadFinished()
void createMovieItem(const MusicResultDataItem &item)
#define TTK_BN_250
Definition: ttkglobal.h:430
virtual void downLoadFinished() overridefinal
static constexpr const char * KW_ARTIST_MOVIE_URL
#define TTK_BN_500
Definition: ttkglobal.h:432
voidpf uLong offset
Definition: ioapi.h:142
ParseError error
TTK::MusicSongInformationList m_items
#define MP4_FILE_SUFFIX
Definition: musicobject.h:60
#define qAsConst
Definition: ttkqtglobal.h:57
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path) noexcept
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:189
The class of the query movie download data from net.
QNetworkAccessManager m_manager
The class of the des wrapper.
Definition: deswrapper.h:34
virtual void startToSearchByID(const QString &value) overridefinal
bool isEmpty() const noexcept
Definition: musicobject.h:250
static constexpr const char * KW_MOVIE_ATTR_URL
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
virtual void downLoadFinished() override
QString makeSongArtist(const QString &name)
#define ARTIST_ATTR_PAGE_SIZE
virtual void startToPage(int offset) overridefinal
MusicKWQueryMovieRequest(QObject *parent=nullptr)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
void makeRequestRawHeader(QNetworkRequest *request) noexcept
virtual void startToSearch(const QString &value) override
The namespace of the kuwo request interface.
virtual void startToPage(int offset) overridefinal
virtual void startToPage(int offset) override
static constexpr const char * KW_SONG_SEARCH_URL
song url
static constexpr const char * KW_MOVIE_URL
movie url
static constexpr const char * KW_SONG_INFO_URL
static constexpr const char * MDII_SHR_KEY
static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format, int bitrate)
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
static constexpr const char * KW_MOVIE_COVER_URL
The class of the music song information.
Definition: musicobject.h:295
#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