TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicfmradiosongrequest.cpp
Go to the documentation of this file.
3 
4 static constexpr const char *FM_DETAIL_URL = "M1htRHNMTFJzSGJPVzFUbUV5MFQxM3E1NDhUalAzdkNUUnNNVm5UVGt6YUtMbWUwZlhwRFV5TnZUdVE9";
5 
7  : MusicAbstractNetwork(parent)
8 {
9 
10 }
11 
13 {
14  deleteAll();
16 
17  QNetworkRequest request;
18  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
20  "{}");
21 
22  m_reply = m_manager.post(request, parameter);
23  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
25 }
26 
28 {
30  if(m_reply && m_reply->error() == QNetworkReply::NoError)
31  {
32  QJson::Parser json;
33  bool ok = false;
34  const QVariant &data = json.parse(m_reply->readAll(), &ok);
35  if(ok)
36  {
37  QVariantMap value = data.toMap();
38  if(value["code"].toInt() == 200 && value.contains("data"))
39  {
40  const QVariantList &datas = value["data"].toList();
41  for(const QVariant &var : qAsConst(datas))
42  {
43  if(var.isNull())
44  {
45  continue;
46  }
47 
48  value = var.toMap();
50 
52  info.m_songId = value["id"].toString();
53  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
54 
55  const QVariantList &artistsArray = value["artists"].toList();
56  for(const QVariant &artistValue : qAsConst(artistsArray))
57  {
58  if(artistValue.isNull())
59  {
60  continue;
61  }
62 
63  const QVariantMap &artistObject = artistValue.toMap();
64  if(info.m_artistId.isEmpty())
65  {
66  info.m_artistId = artistObject["id"].toString();
67  }
68 
69  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["name"].toString());
70  }
71 
72  const QVariantMap &albumObject = value["album"].toMap();
73  info.m_albumId = albumObject["id"].toString();
74  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
75 
76  info.m_coverUrl = albumObject["picUrl"].toString();
78  info.m_duration = TTKTime::formatDuration(value["duration"].toInt());
79  info.m_year.clear();
80  info.m_trackNumber = value["no"].toString();
81 
85 
86  if(!info.m_songProps.isEmpty())
87  {
88  m_item = info;
89  break;
90  }
91  }
92  }
93  }
94  }
95 
96  Q_EMIT downLoadDataChanged({});
97  deleteAll();
98 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
static constexpr const char * FM_DETAIL_URL
#define TTK_NETWORK_QUERY_CHECK(VALUE)
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
QNetworkReply * m_reply
QString makeSongArtist(const QString &in, const QString &name)
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
virtual void downLoadFinished()
#define qAsConst
Definition: ttkqtglobal.h:53
static constexpr const char * WY_SONG_LRC_OLD_URL
QNetworkAccessManager m_manager
MusicFMRadioSongRequest(QObject *parent=nullptr)
virtual void replyError(QNetworkReply::NetworkError error) override
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
#define TTK_SLOT
Definition: ttkqtglobal.h:165
The class of the abstract network.
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
QByteArray makeTokenRequest(QNetworkRequest *request, const QString &query, const QString &type)
TTK_MODULE_EXPORT QString toString(Record type)
virtual void downLoadFinished() overridefinal
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
TTK::MusicSongInformation m_item
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the music song information.
Definition: musicobject.h:281
#define TTK_BN_128
Definition: ttkglobal.h:348
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123