TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicmvradioprogramrequest.cpp
Go to the documentation of this file.
3 
4 namespace ReqKGInterface
5 {
13  static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QVariantMap &key);
14 
15 }
16 
18 {
19  if(info->m_songId.isEmpty())
20  {
21  return;
22  }
23 
24  const QByteArray &encodedData = TTK::Algorithm::md5(QString("%1kugoumvcloud").arg(info->m_songId).toUtf8());
25 
26  QNetworkRequest request;
27  request.setUrl(TTK::Algorithm::mdII(KG_MOVIE_INFO_URL, false).arg(encodedData.constData(), info->m_songId));
29 
30  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
31  if(bytes.isEmpty())
32  {
33  return;
34  }
35 
36  QJson::Parser json;
37  bool ok = false;
38  const QVariant &data = json.parse(bytes, &ok);
39  if(ok)
40  {
41  QVariantMap value = data.toMap();
42  if(value.contains("mvdata"))
43  {
44  value = value["mvdata"].toMap();
45 
46  QVariantMap mv = value["sd"].toMap();
47  if(!mv.isEmpty())
48  {
49  parseFromMovieProperty(info, mv);
50  }
51 
52  mv = value["hd"].toMap();
53  if(!mv.isEmpty())
54  {
55  parseFromMovieProperty(info, mv);
56  }
57 
58  mv = value["sq"].toMap();
59  if(!mv.isEmpty())
60  {
61  parseFromMovieProperty(info, mv);
62  }
63 
64  mv = value["rq"].toMap();
65  if(!mv.isEmpty())
66  {
67  parseFromMovieProperty(info, mv);
68  }
69  }
70  }
71 }
72 
74 {
76  prop.m_url = key["downurl"].toString();
77  prop.m_size = TTK::Number::sizeByteToLabel(key["filesize"].toInt());
79 
80  const int bitrate = key["bitrate"].toInt() / 1000;
81  if(bitrate <= 1000)
82  {
83  prop.m_bitrate = TTK_BN_250;
84  }
85  else if(bitrate > 1000 && bitrate <= 2000)
86  {
87  prop.m_bitrate = TTK_BN_500;
88  }
89  else if(bitrate > 2000 && bitrate <= 3000)
90  {
91  prop.m_bitrate = TTK_BN_750;
92  }
93  else if(bitrate > 3000)
94  {
95  prop.m_bitrate = TTK_BN_1000;
96  }
97 
98  info->m_songProps.append(prop);
99 }
100 
101 
104 {
105 
106 }
107 
109 {
111  if(m_reply && m_reply->error() == QNetworkReply::NoError)
112  {
113  QByteArray bytes = m_reply->readAll();
114  bytes = QString(bytes).split("var mvfmdata = ").back().split("$img = ").front().toUtf8();
115  bytes.chop(3);
116 
117  QJson::Parser json;
118  bool ok = false;
119  const QVariant &data = json.parse(bytes, &ok);
120  if(ok)
121  {
122  bool contains = false;
123  for(const QVariant &var : data.toList())
124  {
125  if(var.isNull())
126  {
127  continue;
128  }
129 
130  QVariantMap value = var.toMap();
132 
133  MusicResultDataItem item;
134  item.m_nickName = value["className"].toString();
135 
136  for(const QVariant &var : value["fm_list"].toList())
137  {
138  if(var.isNull())
139  {
140  continue;
141  }
142 
143  value = var.toMap();
145 
146  if(!contains && value["fmId"].toString() == m_queryValue)
147  {
148  contains = true;
149  item.m_name = value["fmName"].toString();
150  item.m_id = value["fmId"].toString();
151  item.m_coverUrl = value["imgUrlMv"].toString();
152  Q_EMIT createMVRadioItem(item);
153 
154  for(const QVariant &var : value["mvs"].toList())
155  {
156  if(var.isNull())
157  {
158  continue;
159  }
160 
161  value = var.toMap();
163 
165  info.m_songId = value["mvhash"].toString();
166  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
167 
168  info.m_artistName = info.m_songName;
169  if(info.m_artistName.contains(TTK_DEFAULT_STR))
170  {
171  const QStringList &ds = info.m_artistName.split(TTK_DEFAULT_STR);
172  if(ds.count() >= 2)
173  {
174  info.m_artistName = ds.front().trimmed();
175  info.m_songName = ds.back().trimmed();
176  }
177  }
178 
179  info.m_duration = TTKTime::formatDuration(value["time"].toInt());
180 
184 
185  if(info.m_songProps.isEmpty())
186  {
187  continue;
188  }
189 
190  Q_EMIT createResultItem({info});
191  m_items << info;
192  }
193  }
194  }
195  }
196  }
197  }
198 
199  Q_EMIT downLoadDataChanged({});
200  deleteAll();
201 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
#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
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
The class of the music mv radio request abstract.
The class of the music song property.
Definition: musicobject.h:223
static constexpr wchar_t key[]
virtual void downLoadFinished() overridefinal
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
#define TTK_BN_1000
Definition: ttkglobal.h:354
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
TTK::MusicSongInformationList m_items
void createResultItem(const MusicResultInfoItem &songItem)
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
virtual void downLoadFinished() override
TTK_MODULE_EXPORT QString splitToken(const QString &name)
MusicMVRadioProgramRequest(QObject *parent=nullptr)
static void parseFromMovieProperty(TTK::MusicSongInformation *info, const QVariantMap &key)
void createMVRadioItem(const MusicResultDataItem &item)
TTK_MODULE_EXPORT QString toString(Record type)
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)
The class of the music song information.
Definition: musicobject.h:281
#define TTK_BN_750
Definition: ttkglobal.h:353
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123