TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickgqueryalbumrequest.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  request.setUrl(TTK::Algorithm::mdII(KG_ALBUM_URL, false).arg(m_queryValue).arg(offset + 1).arg(m_pageSize));
21 
22  m_reply = m_manager.get(request);
23  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
25 }
26 
28 {
29  TTK_INFO_STREAM(className() << __FUNCTION__ << info->m_songId << bitrate << "kbps");
30 
35 
38 }
39 
41 {
42  TTK_INFO_STREAM(className() << __FUNCTION__);
43 
45  if(m_reply && m_reply->error() == QNetworkReply::NoError)
46  {
47  QJson::Parser json;
48  bool ok = false;
49  const QVariant &data = json.parse(m_reply->readAll(), &ok);
50  if(ok)
51  {
52  QVariantMap value = data.toMap();
53  if(value.contains("data"))
54  {
55  QString albumName;
56  value = value["data"].toMap();
57  m_totalSize = value["total"].toInt();
58 
59  const QVariantList &datas = value["info"].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["hash"].toString();
72 
73  info.m_albumId = value["album_id"].toString();
74 
75  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
76  info.m_year.clear();
77  info.m_trackNumber = "0";
78 
84 
85  if(!m_albumFound)
86  {
87  m_albumFound = true;
90  ReqKGInterface::parseFromSongAlbumInfo(&item, info.m_songId, value["album_audio_id"].toString());
92 
93  albumName = item.m_name;
94  item.m_count = item.m_name;
95  item.m_id = info.m_albumId;
96  item.m_name = info.m_artistName;
97  item.m_coverUrl = info.m_coverUrl;
98  Q_EMIT createAlbumItem(item);
99  }
100 
101  info.m_albumName = albumName;
102  Q_EMIT createResultItem({info, serverToString()});
103  m_items << info;
104  }
105  }
106  }
107  }
108 
109  Q_EMIT downLoadDataChanged({});
110  deleteAll();
111 }
112 
113 
114 
116  : MusicQueryAlbumRequest(parent)
117 {
120 }
121 
123 {
124  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
125 
126  deleteAll();
127  m_totalSize = 0;
129 
130  QNetworkRequest request;
131  request.setUrl(TTK::Algorithm::mdII(KG_ARTIST_ALBUM_URL, false).arg(m_queryValue).arg(offset + 1).arg(m_pageSize));
133 
134  m_reply = m_manager.get(request);
135  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
137 }
138 
140 {
141  TTK_INFO_STREAM(className() << __FUNCTION__);
142 
144  if(m_reply && m_reply->error() == QNetworkReply::NoError)
145  {
146  QJson::Parser json;
147  bool ok = false;
148  const QVariant &data = json.parse(m_reply->readAll(), &ok);
149  if(ok)
150  {
151  QVariantMap value = data.toMap();
152  if(value["errcode"].toInt() == 0 && value.contains("data"))
153  {
154  value = value["data"].toMap();
155  m_totalSize = value["total"].toInt();
156 
157  const QVariantList &datas = value["info"].toList();
158  for(const QVariant &var : qAsConst(datas))
159  {
160  if(var.isNull())
161  {
162  continue;
163  }
164 
165  value = var.toMap();
167 
168  MusicResultDataItem item;
169  item.m_id = value["albumid"].toString();
170  item.m_coverUrl = value["imgurl"].toString().replace("{size}", "400");
171  item.m_name = value["albumname"].toString();
172  item.m_time = TTK::String::split(value["publishtime"].toString().replace(TTK_DEFAULT_STR, TTK_DOT), TTK_SPACE).front();
173  Q_EMIT createAlbumItem(item);
174  }
175  }
176  }
177  }
178 
179  Q_EMIT downLoadDataChanged({});
180  deleteAll();
181 }
#define TTK_NETWORK_QUERY_CHECK(VALUE)
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
virtual void downLoadFinished() overridefinal
The class of the search result data item.
static constexpr const char * KG_ALBUM_URL
album url
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
virtual void downLoadFinished() overridefinal
QNetworkReply * m_reply
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:203
static constexpr const char * QUERY_KG_INTERFACE
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
virtual void downLoadFinished()
void makeRequestRawHeader(QNetworkRequest *request)
#define TTK_DOT
Definition: ttkglobal.h:193
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
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:68
MusicKGQueryAlbumRequest(QObject *parent=nullptr)
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
virtual void startToPage(int offset) overridefinal
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
TTK_MODULE_EXPORT QStringList split(const QString &value, const QString &key=TTK_DEFAULT_STR)
MusicKGQueryArtistAlbumRequest(QObject *parent=nullptr)
#define ARTIST_ATTR_PAGE_SIZE
#define SONG_PAGE_SIZE
#define TTK_DN_S2MS
Definition: ttkglobal.h:281
TTK_MODULE_EXPORT QString toString(Record type)
void parseFromSongAlbumLrc(TTK::MusicSongInformation *info)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
void parseFromSongAlbumInfo(TTK::MusicSongInformation *info, const QString &album)
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
#define TTK_SPACE
Definition: ttkglobal.h:195
The class of the music song information.
Definition: musicobject.h:283
static constexpr const char * KG_ARTIST_ALBUM_URL
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123