TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwyqueryartistrequest.cpp
Go to the documentation of this file.
2 
5 {
6  m_pageSize = TTK_HIGH_LEVEL; // ARTIST_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,
21  QString("{}"));
22 
23  m_reply = m_manager.post(request, parameter);
24  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
26 }
27 
29 {
30  TTK_INFO_STREAM(className() << "startToQueryResult" << info->m_songId << bitrate << "kbps");
31 
37 }
38 
40 {
41  TTK_INFO_STREAM(className() << "downLoadFinished");
42 
44  if(m_reply && m_reply->error() == QNetworkReply::NoError)
45  {
46  QJson::Parser json;
47  bool ok = false;
48  const QVariant &data = json.parse(m_reply->readAll(), &ok);
49  if(ok)
50  {
51  QVariantMap value = data.toMap();
52  if(value["code"].toInt() == 200 && value.contains("hotSongs"))
53  {
54  const QVariantMap &artistObject = value["artist"].toMap();
55  const QString &coverUrl = artistObject["picUrl"].toString();
56  const QString &artistName = TTK::String::charactersReplace(artistObject["name"].toString());
57 
58  const QVariantList &datas = value["hotSongs"].toList();
59  for(const QVariant &var : qAsConst(datas))
60  {
61  if(var.isNull())
62  {
63  continue;
64  }
65 
66  value = var.toMap();
68 
70  info.m_songId = value["id"].toString();
71  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
72 
73  info.m_artistName = artistName;
74  const QVariantList &artistsArray = value["ar"].toList();
75  for(const QVariant &artistValue : qAsConst(artistsArray))
76  {
77  if(artistValue.isNull())
78  {
79  continue;
80  }
81 
82  const QVariantMap &artistObject = artistValue.toMap();
83  info.m_artistId = artistObject["id"].toString();
84  break;
85  }
86 
87  const QVariantMap &albumObject = value["al"].toMap();
88  info.m_albumId = albumObject["id"].toString();
89  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
90 
91  info.m_coverUrl = coverUrl;
93  info.m_duration = TTKTime::formatDuration(value["dt"].toInt());
94  info.m_year.clear();
95  info.m_trackNumber = value["no"].toString();
96 
100 
101  if(!m_artistFound)
102  {
103  m_artistFound = true;
104  MusicResultDataItem item;
106  queryArtistIntro(&item);
108 
109  item.m_nickName.clear();
110  const QVariantList &aliasArray = artistObject["alias"].toList();
111  for(const QVariant &aliasValue : qAsConst(aliasArray))
112  {
113  if(aliasValue.isNull())
114  {
115  continue;
116  }
117 
118  item.m_nickName += aliasValue.toString() + ",";
119  }
120 
121  if(!item.m_nickName.isEmpty())
122  {
123  item.m_nickName.chop(1);
124  }
125  else
126  {
128  }
129 
130  item.m_id = info.m_artistId;
131  item.m_name = info.m_artistName;
132  item.m_coverUrl = info.m_coverUrl;
133  item.m_updateTime = TTKDateTime::format(artistObject["publishTime"].toLongLong(), TTK_DATE_FORMAT);
134  Q_EMIT createArtistItem(item);
135  }
136 
137  Q_EMIT createResultItem({info, serverToString()});
138  m_items << info;
139  }
140  }
141  }
142  }
143 
144  Q_EMIT downLoadDataChanged({});
145  deleteAll();
146 }
147 
149 {
150  QNetworkRequest request;
151  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
154 
155  const QByteArray &bytes = TTK::syncNetworkQueryForPost(&request, parameter);
156  if(bytes.isEmpty())
157  {
158  return;
159  }
160 
161  QJson::Parser json;
162  bool ok = false;
163  const QVariant &data = json.parse(bytes, &ok);
164  if(ok)
165  {
166  QVariantMap value = data.toMap();
167  if(value["code"].toInt() == 200)
168  {
169  item->m_description = value["briefDesc"].toString();
170  if(!item->m_description.isEmpty())
171  {
172  item->m_description = QString("%1\r\n\r\n").arg(item->m_description);
173  }
174 
175  const QVariantList &datas = value["introduction"].toList();
176  for(const QVariant &var : qAsConst(datas))
177  {
178  if(var.isNull())
179  {
180  continue;
181  }
182 
183  value = var.toMap();
185 
186  item->m_description += QString("**%1**\r\n").arg(value["ti"].toString());
187  item->m_description += value["txt"].toString() + "\r\n\r\n";
188  }
189  }
190  }
191 }
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForPost(QNetworkRequest *request, const QByteArray &data)
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
#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
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
virtual void startToPage(int offset) overridefinal
The class of the query artist download data from net.
virtual void downLoadFinished()
MusicWYQueryArtistRequest(QObject *parent=nullptr)
static constexpr const char * WY_ARTIST_INFO_URL
voidpf uLong offset
Definition: ioapi.h:142
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
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 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 downLoadFinished() overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
#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)
static constexpr const char * WY_ARTIST_URL
artist url
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
void queryArtistIntro(MusicResultDataItem *item) const
void createArtistItem(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
static constexpr const char * WY_ARTIST_INFO_DATA_URL
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