TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwyquerytoplistrequest.cpp
Go to the documentation of this file.
2 
5 {
6  m_pageSize = TTK_HIGH_LEVEL; // TOPLIST_PAGE_SIZE
8 }
9 
11 {
12  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
13 
14  deleteAll();
15  m_totalSize = m_pageSize; // 0
17 
18  QNetworkRequest request;
19  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
22 
23  m_reply = m_manager.post(request, parameter);
24  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
26 }
27 
29 {
30  MusicQueryToplistRequest::startToSearch(value.isEmpty() ? "19723756" : value);
31 }
32 
34 {
35  TTK_INFO_STREAM(className() << __FUNCTION__ << info->m_songId << bitrate << "kbps");
36 
41 
44 }
45 
47 {
48  TTK_INFO_STREAM(className() << __FUNCTION__);
49 
51  if(m_reply && m_reply->error() == QNetworkReply::NoError)
52  {
53  QJsonParseError ok;
54  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
56  {
57  QVariantMap value = json.toVariant().toMap();
58  if(value["code"].toInt() == 200 && value.contains("playlist"))
59  {
60  value = value["playlist"].toMap();
61 // m_totalSize = value["trackCount"].toInt();
62 
63  queryToplistInfo(value);
64 
65  const QVariantList &datas = value["tracks"].toList();
66  for(const QVariant &var : qAsConst(datas))
67  {
68  if(var.isNull())
69  {
70  continue;
71  }
72 
73  value = var.toMap();
75 
77  info.m_songId = value["id"].toString();
78  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
79 
80  const QVariantList &artistsArray = value["ar"].toList();
81  for(const QVariant &artistValue : qAsConst(artistsArray))
82  {
83  if(artistValue.isNull())
84  {
85  continue;
86  }
87 
88  const QVariantMap &artistObject = artistValue.toMap();
89  if(info.m_artistId.isEmpty())
90  {
91  info.m_artistId = artistObject["id"].toString();
92  }
93 
94  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["name"].toString());
95  }
96 
97  const QVariantMap &albumObject = value["al"].toMap();
98  info.m_albumId = albumObject["id"].toString();
99  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
100 
101  info.m_coverUrl = albumObject["picUrl"].toString();
103  info.m_duration = TTKTime::formatDuration(value["dt"].toInt());
104  info.m_year.clear();
105  info.m_trackNumber = value["no"].toString();
106 
110 
111  Q_EMIT createResultItem({info, serverToString()});
112  m_items << info;
113  }
114  }
115  }
116  }
117 
118  Q_EMIT downLoadDataChanged({});
119  deleteAll();
120 }
121 
122 void MusicWYQueryToplistRequest::queryToplistInfo(const QVariantMap &input)
123 {
124  MusicResultDataItem item;
125  item.m_name = input["name"].toString();
126  item.m_coverUrl = input["coverImgUrl"].toString();
127  item.m_count = input["playCount"].toString();
128  item.m_description = input["description"].toString();
129  item.m_time = TTKDateTime::format(input["updateTime"].toULongLong(), TTK_DATE_FORMAT);
130  Q_EMIT createToplistItem(item);
131 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
virtual void queryToplistInfo(const QVariantMap &input) overridefinal
The class of the query toplist download data from net.
#define TTK_NETWORK_QUERY_CHECK(VALUE)
The class of the search result data item.
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
void createResultItem(const MusicResultInfoItem &result)
MusicWYQueryToplistRequest(QObject *parent=nullptr)
virtual void downLoadFinished()
static constexpr const char * WY_TOPLIST_DATA_URL
static constexpr const char * WY_TOPLIST_URL
toplist url
virtual void downLoadFinished() overridefinal
voidpf uLong offset
Definition: ioapi.h:142
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
ParseError error
virtual void startToPage(int offset) overridefinal
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:57
static constexpr const char * QUERY_WY_INTERFACE
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
static constexpr const char * WY_SONG_LRC_OLD_URL
QNetworkAccessManager m_manager
virtual void startToSearch(const QString &value) override
bool fetchUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
virtual void replyError(QNetworkReply::NetworkError error) override
#define TTK_SLOT
Definition: ttkqtglobal.h:177
#define TTK_DATE_FORMAT
Definition: ttkglobal.h:309
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
virtual void startToSearch(const QString &value) overridefinal
#define TTK_HIGH_LEVEL
Definition: ttkglobal.h:334
void createToplistItem(const MusicResultDataItem &item)
static QString format(const QString &time, const QString &format)
Definition: ttktime.cpp:254
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 QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123