TTKMusicPlayer  3.7.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() << "startToPage" << 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() << "startToQueryResult" << info->m_songId << bitrate << "kbps");
36 
42 }
43 
45 {
46  TTK_INFO_STREAM(className() << "downLoadFinished");
47 
49  if(m_reply && m_reply->error() == QNetworkReply::NoError)
50  {
51  QJson::Parser json;
52  bool ok = false;
53  const QVariant &data = json.parse(m_reply->readAll(), &ok);
54  if(ok)
55  {
56  QVariantMap value = data.toMap();
57  if(value["code"].toInt() == 200 && value.contains("playlist"))
58  {
59  value = value["playlist"].toMap();
60 // m_totalSize = value["trackCount"].toInt();
61 
62  queryToplistInfo(value);
63 
64  const QVariantList &datas = value["tracks"].toList();
65  for(const QVariant &var : qAsConst(datas))
66  {
67  if(var.isNull())
68  {
69  continue;
70  }
71 
72  value = var.toMap();
74 
76  info.m_songId = value["id"].toString();
77  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
78 
79  const QVariantList &artistsArray = value["ar"].toList();
80  for(const QVariant &artistValue : qAsConst(artistsArray))
81  {
82  if(artistValue.isNull())
83  {
84  continue;
85  }
86 
87  const QVariantMap &artistObject = artistValue.toMap();
88  if(info.m_artistId.isEmpty())
89  {
90  info.m_artistId = artistObject["id"].toString();
91  }
92 
93  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["name"].toString());
94  }
95 
96  const QVariantMap &albumObject = value["al"].toMap();
97  info.m_albumId = albumObject["id"].toString();
98  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
99 
100  info.m_coverUrl = albumObject["picUrl"].toString();
102  info.m_duration = TTKTime::formatDuration(value["dt"].toInt());
103  info.m_year.clear();
104  info.m_trackNumber = value["no"].toString();
105 
109 
110  Q_EMIT createResultItem({info, serverToString()});
111  m_items << info;
112  }
113  }
114  }
115  }
116 
117  Q_EMIT downLoadDataChanged({});
118  deleteAll();
119 }
120 
121 void MusicWYQueryToplistRequest::queryToplistInfo(const QVariantMap &input)
122 {
123  MusicResultDataItem item;
124  item.m_name = input["name"].toString();
125  item.m_coverUrl = input["coverImgUrl"].toString();
126  item.m_count = input["playCount"].toString();
127  item.m_description = input["description"].toString();
128  item.m_updateTime = TTKDateTime::format(input["updateTime"].toULongLong(), TTK_DATE_FORMAT);
129  Q_EMIT createToplistItem(item);
130 }
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
QString makeSongArtist(const QString &in, const QString &name)
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)
virtual void startToPage(int offset) overridefinal
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:53
static constexpr const char * QUERY_WY_INTERFACE
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
static constexpr const char * WY_SONG_LRC_OLD_URL
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
virtual void startToSearch(const QString &value) override
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
#define TTK_DATE_FORMAT
Definition: ttkglobal.h:231
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
virtual void startToSearch(const QString &value) overridefinal
#define TTK_HIGH_LEVEL
Definition: ttkglobal.h:255
QByteArray makeTokenRequest(QNetworkRequest *request, const QString &query, const QString &type)
TTK_MODULE_EXPORT QString toString(Record type)
void createToplistItem(const MusicResultDataItem &item)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
static QString format(const QString &time, const QString &format)
Definition: ttktime.cpp:254
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the music song information.
Definition: musicobject.h:281
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123