TTKMusicPlayer  4.1.3.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 &key = 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(key.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 {
110  TTK_INFO_STREAM(className() << __FUNCTION__);
111 
113  if(m_reply && m_reply->error() == QNetworkReply::NoError)
114  {
115  QJson::Parser json;
116  bool ok = false;
117  const QVariant &data = json.parse(m_reply->readAll(), &ok);
118  if(ok)
119  {
120  QVariantMap value = data.toMap();
121  if(value.contains("data"))
122  {
123  bool contains = false;
124  for(const QVariant &var : value["data"].toList())
125  {
126  if(var.isNull())
127  {
128  continue;
129  }
130 
131  QVariantMap value = var.toMap();
133 
134  MusicResultDataItem item;
135  item.m_nickName = value["className"].toString();
136 
137  for(const QVariant &var : value["fm_list"].toList())
138  {
139  if(var.isNull())
140  {
141  continue;
142  }
143 
144  value = var.toMap();
146 
147  if(!contains && value["fmId"].toString() == m_queryValue)
148  {
149  contains = true;
150  item.m_name = value["fmName"].toString();
151  item.m_id = value["fmId"].toString();
152  item.m_coverUrl = value["imgUrlMv"].toString();
153  Q_EMIT createMVRadioItem(item);
154 
155  for(const QVariant &var : value["mvs"].toList())
156  {
157  if(var.isNull())
158  {
159  continue;
160  }
161 
162  value = var.toMap();
164 
166  info.m_songId = value["mvhash"].toString();
167  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
168 
169  info.m_artistName = info.m_songName;
170  if(info.m_artistName.contains(TTK_DEFAULT_STR))
171  {
172  const QStringList &ds = info.m_artistName.split(TTK_DEFAULT_STR);
173  if(ds.count() >= 2)
174  {
175  info.m_artistName = ds.front().trimmed();
176  info.m_songName = ds.back().trimmed();
177  }
178  }
179 
180  info.m_duration = TTKTime::formatDuration(value["time"].toInt());
181 
185 
186  if(info.m_songProps.isEmpty())
187  {
188  continue;
189  }
190 
191  Q_EMIT createResultItem({info});
192  m_items << info;
193  }
194  }
195  }
196  }
197  }
198  }
199  }
200 
201  Q_EMIT downLoadDataChanged({});
202  deleteAll();
203 }
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:203
The class of the music mv radio request abstract.
The class of the music song property.
Definition: musicobject.h:225
static constexpr wchar_t key[]
virtual void downLoadFinished() overridefinal
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
#define TTK_BN_1000
Definition: ttkglobal.h:359
The namespace of the kugou request interface.
void makeRequestRawHeader(QNetworkRequest *request)
#define TTK_BN_250
Definition: ttkglobal.h:355
#define TTK_BN_500
Definition: ttkglobal.h:357
TTK::MusicSongInformationList m_items
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:68
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:283
#define TTK_BN_750
Definition: ttkglobal.h:358
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123