TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwyqueryalbumrequest.cpp
Go to the documentation of this file.
2 
4  : MusicQueryAlbumRequest(parent)
5 {
8 }
9 
11 {
12  TTK_INFO_STREAM(className() << "startToPage" << offset);
13 
14  deleteAll();
15  m_totalSize = 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("album"))
53  {
55  const QVariantMap &albumValue = value["album"].toMap();
56  item.m_coverUrl = albumValue["picUrl"].toString();
57  item.m_count = albumValue["name"].toString();
58  item.m_description = albumValue["company"].toString();
59  item.m_updateTime = TTKDateTime::format(albumValue["publishTime"].toULongLong(), TTK_DATE_FORMAT);
60  item.m_category = albumValue["language"].toString();
61 
62  const QVariantList &datas = value["songs"].toList();
63  for(const QVariant &var : qAsConst(datas))
64  {
65  if(var.isNull())
66  {
67  continue;
68  }
69 
70  value = var.toMap();
72 
74  info.m_songId = value["id"].toString();
75  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
76 
77  const QVariantList &artistsArray = value["ar"].toList();
78  for(const QVariant &artistValue : qAsConst(artistsArray))
79  {
80  if(artistValue.isNull())
81  {
82  continue;
83  }
84 
85  const QVariantMap &artistObject = artistValue.toMap();
86  if(info.m_artistId.isEmpty())
87  {
88  info.m_artistId = artistObject["id"].toString();
89  }
90 
91  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["name"].toString());
92  }
93 
94  const QVariantMap &albumObject = value["al"].toMap();
95  info.m_albumId = albumObject["id"].toString();
96  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
97 
98  info.m_coverUrl = albumObject["picUrl"].toString();
100  info.m_duration = TTKTime::formatDuration(value["dt"].toInt());
101  info.m_year.clear();
102  info.m_trackNumber = value["no"].toString();
103 
107 
108  if(!m_albumFound)
109  {
110  m_albumFound = true;
111  item.m_id = info.m_albumId;
112  item.m_name = info.m_artistName;
113  Q_EMIT createAlbumItem(item);
114  }
115 
116  Q_EMIT createResultItem({info, serverToString()});
117  m_items << info;
118  }
119  }
120  }
121  }
122 
123  Q_EMIT downLoadDataChanged({});
124  deleteAll();
125 }
126 
127 
128 
130  : MusicQueryAlbumRequest(parent)
131 {
134 }
135 
137 {
138  TTK_INFO_STREAM(className() << "startToPage" << offset);
139 
140  deleteAll();
141  m_totalSize = 0;
143 
144  QNetworkRequest request;
145  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
148 
149  m_reply = m_manager.post(request, parameter);
150  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
152 }
153 
155 {
156  TTK_INFO_STREAM(className() << "downLoadFinished");
157 
159  if(m_reply && m_reply->error() == QNetworkReply::NoError)
160  {
161  QJson::Parser json;
162  bool ok = false;
163  const QVariant &data = json.parse(m_reply->readAll(), &ok);
164  if(ok)
165  {
166  QVariantMap value = data.toMap();
167  if(value["code"].toInt() == 200 && value.contains("hotAlbums"))
168  {
169  const QVariantMap &artistValue = value["artist"].toMap();
170  m_totalSize = artistValue["albumSize"].toInt();
171 
172  const QVariantList &datas = value["hotAlbums"].toList();
173  for(const QVariant &var : qAsConst(datas))
174  {
175  if(var.isNull())
176  {
177  continue;
178  }
179 
180  value = var.toMap();
182 
183  MusicResultDataItem item;
184  item.m_id = value["id"].toString();
185  item.m_coverUrl = ReqWYInterface::makeCoverPixmapUrl(value["picUrl"].toString());
186  item.m_name = value["name"].toString();
187  item.m_updateTime = TTKDateTime::format(value["publishTime"].toULongLong(), TTK_DATE2_FORMAT);
188  Q_EMIT createAlbumItem(item);
189  }
190  }
191  }
192  }
193 
194  Q_EMIT downLoadDataChanged({});
195  deleteAll();
196 }
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
virtual void startToPage(int offset) overridefinal
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
MusicWYQueryAlbumRequest(QObject *parent=nullptr)
QString makeSongArtist(const QString &in, const QString &name)
static constexpr const char * WY_ARTIST_ALBUM_URL
virtual void downLoadFinished()
The class of the query album download data from net.
virtual void startToPage(int offset) overridefinal
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_DATE2_FORMAT
Definition: ttkglobal.h:232
#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)
void createAlbumItem(const MusicResultDataItem &item)
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
#define ARTIST_ATTR_PAGE_SIZE
virtual void downLoadFinished() overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
virtual void downLoadFinished() overridefinal
#define SONG_PAGE_SIZE
QByteArray makeTokenRequest(QNetworkRequest *request, const QString &query, const QString &type)
TTK_MODULE_EXPORT QString toString(Record type)
MusicWYQueryArtistAlbumRequest(QObject *parent=nullptr)
static constexpr const char * WY_ARTIST_ALBUM_DATA_URL
QString makeCoverPixmapUrl(const QString &url)
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
static constexpr const char * WY_ALBUM_URL
album url