TTKMusicPlayer  3.7.0.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() << "startToPage" << 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() << "startToQueryResult" << info->m_songId << bitrate << "kbps");
30 
36 }
37 
39 {
40  TTK_INFO_STREAM(className() << "downLoadFinished");
41 
43  if(m_reply && m_reply->error() == QNetworkReply::NoError)
44  {
45  QJson::Parser json;
46  bool ok = false;
47  const QVariant &data = json.parse(m_reply->readAll(), &ok);
48  if(ok)
49  {
50  QVariantMap value = data.toMap();
51  if(value.contains("data"))
52  {
53  QString albumName;
54  value = value["data"].toMap();
55  m_totalSize = value["total"].toInt();
56 
57  const QVariantList &datas = value["info"].toList();
58  for(const QVariant &var : qAsConst(datas))
59  {
60  if(var.isNull())
61  {
62  continue;
63  }
64 
65  value = var.toMap();
67 
69  info.m_songId = value["hash"].toString();
70 
71  info.m_albumId = value["album_id"].toString();
72 
73  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
74  info.m_year.clear();
75  info.m_trackNumber = "0";
76 
82 
83  if(!m_albumFound)
84  {
85  m_albumFound = true;
88  ReqKGInterface::parseFromSongAlbumInfo(&item, info.m_songId, value["album_audio_id"].toString());
90 
91  albumName = item.m_name;
92  item.m_count = item.m_name;
93  item.m_id = info.m_albumId;
94  item.m_name = info.m_artistName;
95  item.m_coverUrl = info.m_coverUrl;
96  Q_EMIT createAlbumItem(item);
97  }
98 
99  info.m_albumName = albumName;
100  Q_EMIT createResultItem({info, serverToString()});
101  m_items << info;
102  }
103  }
104  }
105  }
106 
107  Q_EMIT downLoadDataChanged({});
108  deleteAll();
109 }
110 
111 
112 
114  : MusicQueryAlbumRequest(parent)
115 {
118 }
119 
121 {
122  TTK_INFO_STREAM(className() << "startToPage" << offset);
123 
124  deleteAll();
125  m_totalSize = 0;
127 
128  QNetworkRequest request;
129  request.setUrl(TTK::Algorithm::mdII(KG_ARTIST_ALBUM_URL, false).arg(m_queryValue).arg(offset + 1).arg(m_pageSize));
131 
132  m_reply = m_manager.get(request);
133  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
135 }
136 
138 {
139  TTK_INFO_STREAM(className() << "downLoadFinished");
140 
142  if(m_reply && m_reply->error() == QNetworkReply::NoError)
143  {
144  QJson::Parser json;
145  bool ok = false;
146  const QVariant &data = json.parse(m_reply->readAll(), &ok);
147  if(ok)
148  {
149  QVariantMap value = data.toMap();
150  if(value["errcode"].toInt() == 0 && value.contains("data"))
151  {
152  value = value["data"].toMap();
153  m_totalSize = value["total"].toInt();
154 
155  const QVariantList &datas = value["info"].toList();
156  for(const QVariant &var : qAsConst(datas))
157  {
158  if(var.isNull())
159  {
160  continue;
161  }
162 
163  value = var.toMap();
165 
166  MusicResultDataItem item;
167  item.m_id = value["albumid"].toString();
168  item.m_coverUrl = value["imgurl"].toString().replace("{size}", "400");
169  item.m_name = value["albumname"].toString();
170  item.m_updateTime = TTK::String::split(value["publishtime"].toString().replace(TTK_DEFAULT_STR, TTK_DOT), " ").front();
171  Q_EMIT createAlbumItem(item);
172  }
173  }
174  }
175  }
176 
177  Q_EMIT downLoadDataChanged({});
178  deleteAll();
179 }
#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:200
static constexpr const char * QUERY_KG_INTERFACE
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:53
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
MusicKGQueryAlbumRequest(QObject *parent=nullptr)
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
virtual void startToPage(int offset) overridefinal
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
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:276
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)
The class of the music song information.
Definition: musicobject.h:281
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