TTKMusicPlayer  4.1.3.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 {
29  TTK_INFO_STREAM(className() << __FUNCTION__);
30 
32  if(m_reply && m_reply->error() == QNetworkReply::NoError)
33  {
34  QJson::Parser json;
35  bool ok = false;
36  const QVariant &data = json.parse(m_reply->readAll(), &ok);
37  if(ok)
38  {
39  QVariantMap value = data.toMap();
40  if(value["code"].toInt() == 200 && value.contains("data"))
41  {
42  const QVariantList &datas = value["data"].toList();
43  for(const QVariant &var : qAsConst(datas))
44  {
45  if(var.isNull())
46  {
47  continue;
48  }
49 
50  value = var.toMap();
52 
54  info.m_songId = value["id"].toString();
55  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
56 
57  const QVariantList &artistsArray = value["artists"].toList();
58  for(const QVariant &artistValue : qAsConst(artistsArray))
59  {
60  if(artistValue.isNull())
61  {
62  continue;
63  }
64 
65  const QVariantMap &artistObject = artistValue.toMap();
66  if(info.m_artistId.isEmpty())
67  {
68  info.m_artistId = artistObject["id"].toString();
69  }
70 
71  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["name"].toString());
72  }
73 
74  const QVariantMap &albumObject = value["album"].toMap();
75  info.m_albumId = albumObject["id"].toString();
76  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
77 
78  info.m_coverUrl = albumObject["picUrl"].toString();
80  info.m_duration = TTKTime::formatDuration(value["duration"].toInt());
81  info.m_year.clear();
82  info.m_trackNumber = value["no"].toString();
83 
87 
88  if(!info.m_songProps.isEmpty())
89  {
90  m_item = info;
91  break;
92  }
93  }
94  }
95  }
96  }
97 
98  Q_EMIT downLoadDataChanged({});
99  deleteAll();
100 }
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:297
virtual void downLoadFinished()
#define qAsConst
Definition: ttkqtglobal.h:51
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:68
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:181
The class of the abstract network.
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
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
QByteArray makeTokenRequest(QNetworkRequest *request, const QString &query, const QString &data)
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the music song information.
Definition: musicobject.h:283
#define TTK_BN_128
Definition: ttkglobal.h:353
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123