TTKMusicPlayer  4.2.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 {
29  TTK_INFO_STREAM(className() << __FUNCTION__);
30 
32  if(m_reply && m_reply->error() == QNetworkReply::NoError)
33  {
34  QJsonParseError ok;
35  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
37  {
38  QVariantMap value = json.toVariant().toMap();
39  if(value["code"].toInt() == 200 && value.contains("data"))
40  {
41  const QVariantList &datas = value["data"].toList();
42  for(const QVariant &var : qAsConst(datas))
43  {
44  if(var.isNull())
45  {
46  continue;
47  }
48 
49  value = var.toMap();
51 
53  info.m_songId = value["id"].toString();
54  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
55 
56  const QVariantList &artistsArray = value["artists"].toList();
57  for(const QVariant &artistValue : qAsConst(artistsArray))
58  {
59  if(artistValue.isNull())
60  {
61  continue;
62  }
63 
64  const QVariantMap &artistObject = artistValue.toMap();
65  if(info.m_artistId.isEmpty())
66  {
67  info.m_artistId = artistObject["id"].toString();
68  }
69 
70  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["name"].toString());
71  }
72 
73  const QVariantMap &albumObject = value["album"].toMap();
74  info.m_albumId = albumObject["id"].toString();
75  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
76 
77  info.m_coverUrl = albumObject["picUrl"].toString();
79  info.m_duration = TTKTime::formatDuration(value["duration"].toInt());
80  info.m_year.clear();
81  info.m_trackNumber = value["no"].toString();
82 
86 
87  if(!info.m_songProps.isEmpty())
88  {
89  m_item = info;
90  break;
91  }
92  }
93  }
94  }
95  }
96 
97  Q_EMIT downLoadDataChanged({});
98  deleteAll();
99 }
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
QVariant toVariant() const
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
QString makeSongArtist(const QString &in, const QString &name)
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
virtual void downLoadFinished()
ParseError error
#define qAsConst
Definition: ttkqtglobal.h:57
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
static constexpr const char * WY_SONG_LRC_OLD_URL
QNetworkAccessManager m_manager
MusicFMRadioSongRequest(QObject *parent=nullptr)
virtual void replyError(QNetworkReply::NetworkError error) override
#define TTK_SLOT
Definition: ttkqtglobal.h:177
The class of the abstract network.
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
virtual void downLoadFinished() overridefinal
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:295
#define TTK_BN_128
Definition: ttkglobal.h:428
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123