TTKMusicPlayer  4.2.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 &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  QJsonParseError ok;
37  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
39  {
40  QVariantMap value = json.toVariant().toMap();
41  if(value.contains("mvdata"))
42  {
43  value = value["mvdata"].toMap();
44 
45  QVariantMap mv = value["sd"].toMap();
46  if(!mv.isEmpty())
47  {
48  parseFromMovieProperty(info, mv);
49  }
50 
51  mv = value["hd"].toMap();
52  if(!mv.isEmpty())
53  {
54  parseFromMovieProperty(info, mv);
55  }
56 
57  mv = value["sq"].toMap();
58  if(!mv.isEmpty())
59  {
60  parseFromMovieProperty(info, mv);
61  }
62 
63  mv = value["rq"].toMap();
64  if(!mv.isEmpty())
65  {
66  parseFromMovieProperty(info, mv);
67  }
68  }
69  }
70 }
71 
73 {
75  prop.m_url = key["downurl"].toString();
76  prop.m_size = TTK::Number::sizeByteToLabel(key["filesize"].toInt());
78 
79  const int bitrate = key["bitrate"].toInt() / 1000;
80  if(bitrate <= 1000)
81  {
82  prop.m_bitrate = TTK_BN_250;
83  }
84  else if(bitrate > 1000 && bitrate <= 2000)
85  {
86  prop.m_bitrate = TTK_BN_500;
87  }
88  else if(bitrate > 2000 && bitrate <= 3000)
89  {
90  prop.m_bitrate = TTK_BN_750;
91  }
92  else if(bitrate > 3000)
93  {
94  prop.m_bitrate = TTK_BN_1000;
95  }
96 
97  info->m_songProps.append(prop);
98 }
99 
100 
103 {
104 
105 }
106 
108 {
109  TTK_INFO_STREAM(className() << __FUNCTION__);
110 
112  if(m_reply && m_reply->error() == QNetworkReply::NoError)
113  {
114  QJsonParseError ok;
115  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
117  {
118  QVariantMap value = json.toVariant().toMap();
119  if(value.contains("data"))
120  {
121  bool contains = false;
122  for(const QVariant &var : value["data"].toList())
123  {
124  if(var.isNull())
125  {
126  continue;
127  }
128 
129  QVariantMap value = var.toMap();
131 
132  MusicResultDataItem item;
133  item.m_nickName = value["className"].toString();
134 
135  for(const QVariant &var : value["fm_list"].toList())
136  {
137  if(var.isNull())
138  {
139  continue;
140  }
141 
142  value = var.toMap();
144 
145  if(!contains && value["fmId"].toString() == m_queryValue)
146  {
147  contains = true;
148  item.m_name = value["fmName"].toString();
149  item.m_id = value["fmId"].toString();
150  item.m_coverUrl = value["imgUrlMv"].toString();
151  Q_EMIT createMVRadioItem(item);
152 
153  for(const QVariant &var : value["mvs"].toList())
154  {
155  if(var.isNull())
156  {
157  continue;
158  }
159 
160  value = var.toMap();
162 
164  info.m_songId = value["mvhash"].toString();
165  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
166 
167  info.m_artistName = info.m_songName;
168  if(info.m_artistName.contains(TTK_DEFAULT_STR))
169  {
170  const QStringList &ds = info.m_artistName.split(TTK_DEFAULT_STR);
171  if(ds.count() >= 2)
172  {
173  info.m_artistName = ds.front().trimmed();
174  info.m_songName = ds.back().trimmed();
175  }
176  }
177 
178  info.m_duration = TTKTime::formatDuration(value["time"].toInt());
179 
183 
184  if(info.m_songProps.isEmpty())
185  {
186  continue;
187  }
188 
189  Q_EMIT createResultItem({info});
190  m_items << info;
191  }
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:276
The class of the music mv radio request abstract.
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
void createResultItem(const MusicResultInfoItem &result)
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
#define TTK_BN_1000
Definition: ttkglobal.h:434
The namespace of the kugou request interface.
#define TTK_BN_250
Definition: ttkglobal.h:430
#define TTK_BN_500
Definition: ttkglobal.h:432
ParseError error
TTK::MusicSongInformationList m_items
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
static constexpr wchar_t key[]
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)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
void createMVRadioItem(const MusicResultDataItem &item)
static constexpr const char * KG_MOVIE_INFO_URL
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:295
#define TTK_BN_750
Definition: ttkglobal.h:433
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123