TTKMusicPlayer  4.3.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 static constexpr const char *KW_MOVIE_URL = "TjhtdUUydHowZVp1d2RsUVl1UGg0QWkzTjhqZ1NGTWVLNmxqZytTQzV5T291VytwcUpSczNPMGdQV1U9";
6 static constexpr const char *KW_MOVIE_COVER_URL = "c0IyUURSczNib2MzV0w5b3FEZ1dQTEZOeHliNWtWMVh0RWo1MFhoeHF3MjdUbThqb0Rta0JBPT0=";
7 static constexpr const char *KW_MOVIE_ATTR_URL = "cnkyNURUa0E0RkpHdVZWamlOZDRVaGVNcVViSHUrSnNZZjBLZWIveGF5bkVEMldMeXFITk1NaVYvNGNkZFYwaURlelNUQzRvQTdRaklLeUNTLzZJMngxYWJha1ZxY1hLQmFtb2ZRenBsSlViZ05DZmpza0YwZ0pCRjMvSVh1RkNFN094NkZaNWY5TjRHK2NNU1pNQ1E3MGxENWpQRXVYb1pKNjRkRW9CbzlxRTBYYWZXRlFzMW52Um11U2J0M3EvdHRFR0pONGtMeDY2Zm16ME92akNZL2QxL2RZY2lXZGFuRk4raTBjSWx0emc0b2R2bG9LTFVMMCtKQThsTzZzS0NSdzArOWQxanNnY2pkTERxYkd0YXc9PQ==";
8 static constexpr const char *KW_ARTIST_MOVIE_URL = "ODRPczVoSnVTb2dObm12Ujd5b3VsMGEvcDR0SDRXbXRLQVpqZW5NT2Voazh2YnRGK0N4eUxYL2xkNnFyWDZJNG9IK0tnbHhWUUdpNGlHbldtMjhYRFRtdGVXeFYxQjlUWHd5V1B2Y1lwbERlTnlmaGZTQzRNQXB3VkdsemhDWWcrbUs2dy9SWUJQb0tRY29rMGhpWk9HalZ6QlUzMjZtdw==";
9 
10 namespace ReqKWInterface
11 {
19  static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format);
23  static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format, int bitrate);
24 
25 }
26 
28 {
29  if(info->m_songId.isEmpty())
30  {
31  return;
32  }
33 
34  info->m_songName = "Not Found";
35  info->m_artistName = "Anonymous";
36 
37  QNetworkRequest request;
38  request.setUrl(TTK::Algorithm::mdII(KW_SONG_INFO_URL, false).arg(info->m_songId));
40 
41  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
42  if(bytes.isEmpty())
43  {
44  return;
45  }
46 
47  QJsonParseError ok;
48  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
50  {
51  QVariantMap value = json.toVariant().toMap();
52  if(value.contains("data"))
53  {
54  value = value["data"].toMap();
55  info->m_songName = TTK::String::charactersReplace(value["name"].toString());
56  info->m_artistName = ReqKWInterface::makeSongArtist(value["artist"].toString());
57  info->m_coverUrl = value["pic"].toString();
58  info->m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
59  }
60  }
61 }
62 
64 {
65  if(info->m_songId.isEmpty())
66  {
67  return;
68  }
69 
70  for(const QString &v : format.split("|"))
71  {
72  if(v.contains("MP4L"))
73  {
74  parseFromMovieProperty(info, "MP4L", TTK_BN_250);
75  }
76  else if(v.contains("MP4HV"))
77  {
78  parseFromMovieProperty(info, "MP4HV", TTK_BN_750);
79  }
80  else if(v.contains("MP4UL"))
81  {
82  parseFromMovieProperty(info, "MP4UL", TTK_BN_1000);
83  }
84  else if(v.contains("MP4"))
85  {
86  parseFromMovieProperty(info, "MP4", TTK_BN_500);
87  }
88  }
89 }
90 
91 void ReqKWInterface::parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format, int bitrate)
92 {
93  if(info->m_songId.isEmpty())
94  {
95  return;
96  }
97 
98  QAlgorithm::Des des;
99  const QByteArray &parameter = des.encrypt(TTK::Algorithm::mdII(KW_MOVIE_ATTR_URL, false).arg(info->m_songId, format).toUtf8(),
100  TTK::Algorithm::mdII("OGlVTjJWOEdlMkkzSkZIeg==", MDII_SHR_KEY, false).toUtf8());
101  QNetworkRequest request;
102  request.setUrl(TTK::Algorithm::mdII(KW_MOVIE_URL, false).arg(QString(parameter)));
104 
105  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
106  if(bytes.isEmpty())
107  {
108  return;
109  }
110 
111  if(!bytes.contains("res not found"))
112  {
113  const QString text(bytes);
114  static TTKRegularExpression regx(".*url=(.*)\r\nsig=");
115 
116  if(regx.match(text) != -1)
117  {
119  prop.m_url = regx.captured(1);
120  prop.m_size = TTK_DEFAULT_STR;
121  prop.m_format = MP4_FILE_SUFFIX;
122  prop.m_bitrate = bitrate;
123 
124  if(prop.isEmpty() || info->m_songProps.contains(prop))
125  {
126  return;
127  }
128 
129  info->m_songProps.append(prop);
130  }
131  }
132 }
133 
134 
137 {
139 }
140 
142 {
143  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__ << offset);
144 
145  if(needToUnity())
146  {
148  return;
149  }
150 
151  deleteAll();
152  m_totalSize = 0;
154 
155  QNetworkRequest request;
156  request.setUrl(TTK::Algorithm::mdII(KW_SEARCH_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
158 
159  m_reply = m_manager.get(request);
160  connect(m_reply, SIGNAL(finished()), SLOT(downloadFinished()));
162 }
163 
164 void MusicKWQueryMovieRequest::startToSearch(const QString &value)
165 {
166  resetUnity();
168 }
169 
171 {
172  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__ << value);
173 
174  deleteAll();
175  m_queryValue = value;
176 
178 }
179 
181 {
182  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__);
183 
185  if(m_reply && m_reply->error() == QNetworkReply::NoError)
186  {
187  QJsonParseError ok;
188  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll().replace("'", "\""), &ok);
190  {
191  QVariantMap value = json.toVariant().toMap();
192  if(value.contains("abslist"))
193  {
194  m_totalSize = value["TOTAL"].toInt();
195 
196  const QVariantList &datas = value["abslist"].toList();
197  for(const QVariant &var : qAsConst(datas))
198  {
199  if(var.isNull())
200  {
201  continue;
202  }
203 
204  value = var.toMap();
206 
208  info.m_songId = value["MUSICRID"].toString().remove("MUSIC_");
209  info.m_songName = TTK::String::charactersReplace(value["SONGNAME"].toString());
210 
211  info.m_artistName = ReqKWInterface::makeSongArtist(value["ARTIST"].toString());
212 
213  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
214  info.m_duration = TTKTime::formatDuration(value["DURATION"].toInt() * TTK_DN_S2MS);
215 
217  ReqKWInterface::parseFromMovieProperty(&info, value["FORMATS"].toString());
219 
220  if(info.m_songProps.isEmpty() || !fetchUrlPathSize(&info.m_songProps, info.m_duration))
221  {
222  continue;
223  }
224 
225  Q_EMIT createResultItem({info, serverToString()});
226  m_items << info;
227  }
228  }
229  }
230  }
231 
232  if(!pageValid())
233  {
234  setToUnity();
235  }
236 
237  Q_EMIT downloadDataChanged({});
238  deleteAll();
239 }
240 
242 {
243  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__);
244 
246 
248  info.m_songId = m_queryValue;
249 
253  ReqKWInterface::parseFromMovieProperty(&info, "MP4UL|MP4L|MP4HV|MP4");
255 
256  if(!info.m_songProps.isEmpty() && fetchUrlPathSize(&info.m_songProps, info.m_duration))
257  {
258  Q_EMIT createResultItem({info, serverToString()});
259  m_items << info;
260  }
261 
262  Q_EMIT downloadDataChanged({});
263  deleteAll();
264 }
265 
266 
267 
269  : MusicQueryMovieRequest(parent)
270 {
273 }
274 
276 {
277  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__ << offset);
278 
279  deleteAll();
280  m_totalSize = 0;
282 
283  QNetworkRequest request;
284  request.setUrl(TTK::Algorithm::mdII(KW_ARTIST_MOVIE_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
286 
287  m_reply = m_manager.get(request);
288  connect(m_reply, SIGNAL(finished()), SLOT(downloadFinished()));
290 }
291 
293 {
294  TTK_INFO_STREAM(metaObject()->className() << __FUNCTION__);
295 
297  if(m_reply && m_reply->error() == QNetworkReply::NoError)
298  {
299  QJsonParseError ok;
300  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll().replace("'", "\""), &ok);
302  {
303  QVariantMap value = json.toVariant().toMap();
304  if(value.contains("mvlist"))
305  {
306  m_totalSize = value["total"].toInt();
307 
308  const QVariantList &datas = value["mvlist"].toList();
309  for(const QVariant &var : qAsConst(datas))
310  {
311  if(var.isNull())
312  {
313  continue;
314  }
315 
316  value = var.toMap();
318 
319  MusicResultDataItem item;
320  item.m_id = value["musicid"].toString();
321  item.m_name = value["name"].toString();
322  item.m_coverUrl = value["pic"].toString();
324  {
326  }
327  item.m_time.clear();
328  Q_EMIT createMovieItem(item);
329  }
330  }
331  }
332  }
333 
334  Q_EMIT downloadDataChanged({});
335  deleteAll();
336 }
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()
QString captured(int index) const
QNetworkReply * m_reply
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:276
MusicKWQueryArtistMovieRequest(QObject *parent=nullptr)
static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &format)
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)
MusicSongPropertyList m_songProps
Definition: musicobject.h:314
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
void createMovieItem(const MusicResultDataItem &item)
#define TTK_BN_250
Definition: ttkglobal.h:430
#define TTK_BN_500
Definition: ttkglobal.h:432
voidpf uLong offset
Definition: ioapi.h:142
ParseError error
static constexpr const char * KW_SEARCH_URL
TTK::MusicSongInformationList m_items
#define MP4_FILE_SUFFIX
Definition: musicobject.h:61
#define qAsConst
Definition: ttkqtglobal.h:57
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path) noexcept
virtual void downloadFinished() overridefinal
#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
The class of the des wrapper.
Definition: deswrapper.h:34
virtual void startToSearchByID(const QString &value) overridefinal
bool isEmpty() const noexcept
Definition: musicobject.h:255
bool fetchUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
virtual void replyError(QNetworkReply::NetworkError error) override
static constexpr const char * KW_MOVIE_URL
static constexpr const char * QUERY_KW_INTERFACE
#define TTK_SLOT
Definition: ttkqtglobal.h:177
QString makeSongArtist(const QString &name)
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
The class of the regular expression.
virtual void downloadFinished()
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 downloadFinished() overridefinal
virtual void startToPage(int offset) override
static constexpr const char * KW_MOVIE_COVER_URL
#define TTK_PAGE_SIZE_12
virtual void downloadFinished() override
int match(const QString &str, int pos=0)
static constexpr const char * KW_ARTIST_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)
The class of the music song information.
Definition: musicobject.h:300
static constexpr const char * KW_MOVIE_ATTR_URL
#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