TTKMusicPlayer  4.2.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() << __FUNCTION__ << 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() << __FUNCTION__ << info->m_songId << bitrate << "kbps");
31 
36 
39 }
40 
42 {
43  TTK_INFO_STREAM(className() << __FUNCTION__);
44 
46  if(m_reply && m_reply->error() == QNetworkReply::NoError)
47  {
48  QJsonParseError ok;
49  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
51  {
52  QVariantMap value = json.toVariant().toMap();
53  if(value["code"].toInt() == 200 && value.contains("hotSongs"))
54  {
55  const QVariantMap &artistObject = value["artist"].toMap();
56  const QString &coverUrl = artistObject["picUrl"].toString();
57  const QString &artistName = TTK::String::charactersReplace(artistObject["name"].toString());
58 
59  const QVariantList &datas = value["hotSongs"].toList();
60  for(const QVariant &var : qAsConst(datas))
61  {
62  if(var.isNull())
63  {
64  continue;
65  }
66 
67  value = var.toMap();
69 
71  info.m_songId = value["id"].toString();
72  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
73 
74  info.m_artistName = artistName;
75  const QVariantList &artistsArray = value["ar"].toList();
76  for(const QVariant &artistValue : qAsConst(artistsArray))
77  {
78  if(artistValue.isNull())
79  {
80  continue;
81  }
82 
83  const QVariantMap &artistObject = artistValue.toMap();
84  info.m_artistId = artistObject["id"].toString();
85  break;
86  }
87 
88  const QVariantMap &albumObject = value["al"].toMap();
89  info.m_albumId = albumObject["id"].toString();
90  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
91 
92  info.m_coverUrl = coverUrl;
94  info.m_duration = TTKTime::formatDuration(value["dt"].toInt());
95  info.m_year.clear();
96  info.m_trackNumber = value["no"].toString();
97 
101 
102  if(!m_artistFound)
103  {
104  m_artistFound = true;
105  MusicResultDataItem item;
107  queryArtistIntro(&item);
109 
110  item.m_nickName.clear();
111  const QVariantList &aliasArray = artistObject["alias"].toList();
112  for(const QVariant &aliasValue : qAsConst(aliasArray))
113  {
114  if(aliasValue.isNull())
115  {
116  continue;
117  }
118 
119  item.m_nickName += aliasValue.toString() + ",";
120  }
121 
122  if(!item.m_nickName.isEmpty())
123  {
124  item.m_nickName.chop(1);
125  }
126  else
127  {
129  }
130 
131  item.m_id = info.m_artistId;
132  item.m_name = info.m_artistName;
133  item.m_coverUrl = info.m_coverUrl;
134  item.m_time = TTKDateTime::format(artistObject["publishTime"].toLongLong(), TTK_DATE_FORMAT);
135  Q_EMIT createArtistItem(item);
136  }
137 
138  Q_EMIT createResultItem({info, serverToString()});
139  m_items << info;
140  }
141  }
142  }
143  }
144 
145  Q_EMIT downLoadDataChanged({});
146  deleteAll();
147 }
148 
150 {
151  QNetworkRequest request;
152  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
155 
156  const QByteArray &bytes = TTK::syncNetworkQueryForPost(&request, parameter);
157  if(bytes.isEmpty())
158  {
159  return;
160  }
161 
162  QJsonParseError ok;
163  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
165  {
166  QVariantMap value = json.toVariant().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:276
QVariant toVariant() const
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
virtual void startToPage(int offset) overridefinal
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
void createResultItem(const MusicResultInfoItem &result)
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)
ParseError error
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
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 downLoadFinished() overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
#define TTK_HIGH_LEVEL
Definition: ttkglobal.h:334
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)
static QString format(const QString &time, const QString &format)
Definition: ttktime.cpp:254
static constexpr const char * WY_ARTIST_INFO_DATA_URL
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