TTKMusicPlayer  4.1.3.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  QJson::Parser json;
49  bool ok = false;
50  const QVariant &data = json.parse(m_reply->readAll(), &ok);
51  if(ok)
52  {
53  QVariantMap value = data.toMap();
54  if(value["code"].toInt() == 200 && value.contains("album"))
55  {
57  const QVariantMap &albumValue = value["album"].toMap();
58  item.m_coverUrl = albumValue["picUrl"].toString();
59  item.m_count = albumValue["name"].toString();
60  item.m_description = albumValue["company"].toString();
61  item.m_time = TTKDateTime::format(albumValue["publishTime"].toULongLong(), TTK_DATE_FORMAT);
62  item.m_category = albumValue["language"].toString();
63 
64  const QVariantList &datas = value["songs"].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  if(!m_albumFound)
111  {
112  m_albumFound = true;
113  item.m_id = info.m_albumId;
114  item.m_name = info.m_artistName;
115  Q_EMIT createAlbumItem(item);
116  }
117 
118  Q_EMIT createResultItem({info, serverToString()});
119  m_items << info;
120  }
121  }
122  }
123  }
124 
125  Q_EMIT downLoadDataChanged({});
126  deleteAll();
127 }
128 
129 
130 
132  : MusicQueryAlbumRequest(parent)
133 {
136 }
137 
139 {
140  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
141 
142  deleteAll();
143  m_totalSize = 0;
145 
146  QNetworkRequest request;
147  const QByteArray &parameter = ReqWYInterface::makeTokenRequest(&request,
150 
151  m_reply = m_manager.post(request, parameter);
152  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
154 }
155 
157 {
158  TTK_INFO_STREAM(className() << __FUNCTION__);
159 
161  if(m_reply && m_reply->error() == QNetworkReply::NoError)
162  {
163  QJson::Parser json;
164  bool ok = false;
165  const QVariant &data = json.parse(m_reply->readAll(), &ok);
166  if(ok)
167  {
168  QVariantMap value = data.toMap();
169  if(value["code"].toInt() == 200 && value.contains("hotAlbums"))
170  {
171  const QVariantMap &artistValue = value["artist"].toMap();
172  m_totalSize = artistValue["albumSize"].toInt();
173 
174  const QVariantList &datas = value["hotAlbums"].toList();
175  for(const QVariant &var : qAsConst(datas))
176  {
177  if(var.isNull())
178  {
179  continue;
180  }
181 
182  value = var.toMap();
184 
185  MusicResultDataItem item;
186  item.m_id = value["id"].toString();
187  item.m_coverUrl = ReqWYInterface::makeCoverPixmapUrl(value["picUrl"].toString());
188  item.m_name = value["name"].toString();
189  item.m_time = TTKDateTime::format(value["publishTime"].toULongLong(), TTK_DATE2_FORMAT);
190  Q_EMIT createAlbumItem(item);
191  }
192  }
193  }
194  }
195 
196  Q_EMIT downLoadDataChanged({});
197  deleteAll();
198 }
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
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
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:51
static constexpr const char * QUERY_WY_INTERFACE
#define TTK_DATE2_FORMAT
Definition: ttkglobal.h:236
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:68
static constexpr const char * WY_SONG_LRC_OLD_URL
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
bool fetchUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
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:181
#define TTK_DATE_FORMAT
Definition: ttkglobal.h:235
#define ARTIST_ATTR_PAGE_SIZE
virtual void downLoadFinished() overridefinal
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
virtual void downLoadFinished() overridefinal
#define SONG_PAGE_SIZE
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
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:283
#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