TTKMusicPlayer  4.2.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() << __FUNCTION__ << 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() << __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("album"))
54  {
56  const QVariantMap &albumValue = value["album"].toMap();
57  item.m_coverUrl = albumValue["picUrl"].toString();
58  item.m_count = albumValue["name"].toString();
59  item.m_description = albumValue["company"].toString();
60  item.m_time = TTKDateTime::format(albumValue["publishTime"].toULongLong(), TTK_DATE_FORMAT);
61  item.m_category = albumValue["language"].toString();
62 
63  const QVariantList &datas = value["songs"].toList();
64  for(const QVariant &var : qAsConst(datas))
65  {
66  if(var.isNull())
67  {
68  continue;
69  }
70 
71  value = var.toMap();
73 
75  info.m_songId = value["id"].toString();
76  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
77 
78  const QVariantList &artistsArray = value["ar"].toList();
79  for(const QVariant &artistValue : qAsConst(artistsArray))
80  {
81  if(artistValue.isNull())
82  {
83  continue;
84  }
85 
86  const QVariantMap &artistObject = artistValue.toMap();
87  if(info.m_artistId.isEmpty())
88  {
89  info.m_artistId = artistObject["id"].toString();
90  }
91 
92  info.m_artistName = ReqWYInterface::makeSongArtist(info.m_artistName, artistObject["name"].toString());
93  }
94 
95  const QVariantMap &albumObject = value["al"].toMap();
96  info.m_albumId = albumObject["id"].toString();
97  info.m_albumName = TTK::String::charactersReplace(albumObject["name"].toString());
98 
99  info.m_coverUrl = albumObject["picUrl"].toString();
101  info.m_duration = TTKTime::formatDuration(value["dt"].toInt());
102  info.m_year.clear();
103  info.m_trackNumber = value["no"].toString();
104 
108 
109  if(!m_albumFound)
110  {
111  m_albumFound = true;
112  item.m_id = info.m_albumId;
113  item.m_name = info.m_artistName;
114  Q_EMIT createAlbumItem(item);
115  }
116 
117  Q_EMIT createResultItem({info, serverToString()});
118  m_items << info;
119  }
120  }
121  }
122  }
123 
124  Q_EMIT downLoadDataChanged({});
125  deleteAll();
126 }
127 
128 
129 
131  : MusicQueryAlbumRequest(parent)
132 {
135 }
136 
138 {
139  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
140 
141  deleteAll();
142  m_totalSize = 0;
144 
145  QNetworkRequest request;
146  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
149 
150  m_reply = m_manager.post(request, parameter);
151  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
153 }
154 
156 {
157  TTK_INFO_STREAM(className() << __FUNCTION__);
158 
160  if(m_reply && m_reply->error() == QNetworkReply::NoError)
161  {
162  QJsonParseError ok;
163  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
165  {
166  QVariantMap value = json.toVariant().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_time = 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)
QVariant toVariant() const
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
QString makeSongArtist(const QString &in, const QString &name)
static constexpr const char * WY_ARTIST_ALBUM_URL
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
void createResultItem(const MusicResultInfoItem &result)
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)
ParseError error
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:57
static constexpr const char * QUERY_WY_INTERFACE
#define TTK_DATE2_FORMAT
Definition: ttkglobal.h:310
#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
void createAlbumItem(const MusicResultDataItem &item)
virtual void replyError(QNetworkReply::NetworkError error) override
#define TTK_SLOT
Definition: ttkqtglobal.h:177
#define TTK_DATE_FORMAT
Definition: ttkglobal.h:309
#define ARTIST_ATTR_PAGE_SIZE
virtual void downLoadFinished() overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
virtual void downLoadFinished() overridefinal
#define SONG_PAGE_SIZE
MusicWYQueryArtistAlbumRequest(QObject *parent=nullptr)
static constexpr const char * WY_ARTIST_ALBUM_DATA_URL
QString makeCoverPixmapUrl(const QString &url)
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
static constexpr const char * WY_ALBUM_URL
album url