TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickwqueryalbumrequest.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(KW_ALBUM_URL, false).arg(m_queryValue));
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 
35 
36  findUrlPathSize(&info->m_songProps, info->m_duration);
38 }
39 
41 {
42  TTK_INFO_STREAM(className() << "downLoadFinished");
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().replace("'", "\""), &ok);
50  if(ok)
51  {
52  QVariantMap value = data.toMap();
53  if(value.contains("musiclist"))
54  {
56  item.m_id = value["albumid"].toString();
57  item.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["pic"].toString(), {});
58  const QString &albumName = value["name"].toString();
59  item.m_count = albumName;
60  item.m_description = value["company"].toString();
61  item.m_updateTime = value["pub"].toString();
62  item.m_category = value["lang"].toString();
63 
64  m_totalSize = value["songnum"].toInt();
65 
66  const QVariantList &datas = value["musiclist"].toList();
67  for(const QVariant &var : qAsConst(datas))
68  {
69  if(var.isNull())
70  {
71  continue;
72  }
73 
74  value = var.toMap();
76 
78  info.m_songId = value["id"].toString();
79  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
80 
81  info.m_artistId = value["artistid"].toString();
82  info.m_artistName = ReqKWInterface::makeSongArtist(value["artist"].toString());
83 
84  info.m_albumId = item.m_id;
86 
87  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
88  info.m_lrcUrl = TTK::Algorithm::mdII(KW_SONG_LRC_URL, false).arg(info.m_songId);
90  info.m_year.clear();
91  info.m_trackNumber = "0";
92 
94  ReqKWInterface::parseFromSongProperty(&info, value["formats"].toString());
96 
97  if(!m_albumFound)
98  {
99  m_albumFound = true;
100  item.m_id = info.m_albumId;
101  item.m_name = info.m_artistName;
102  Q_EMIT createAlbumItem(item);
103  }
104 
105  Q_EMIT createResultItem({info, serverToString()});
106  m_items << info;
107  }
108  }
109  }
110  }
111 
112  Q_EMIT downLoadDataChanged({});
113  deleteAll();
114 }
115 
116 
117 
119  : MusicQueryAlbumRequest(parent)
120 {
123 }
124 
126 {
127  TTK_INFO_STREAM(className() << "startToPage" << offset);
128 
129  deleteAll();
130  m_totalSize = 0;
132 
133  QNetworkRequest request;
134  request.setUrl(TTK::Algorithm::mdII(KW_ARTIST_ALBUM_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
136 
137  m_reply = m_manager.get(request);
138  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
140 }
141 
143 {
144  TTK_INFO_STREAM(className() << "downLoadFinished");
145 
147  if(m_reply && m_reply->error() == QNetworkReply::NoError)
148  {
149  QJson::Parser json;
150  bool ok = false;
151  const QVariant &data = json.parse(m_reply->readAll().replace("'", "\""), &ok);
152  if(ok)
153  {
154  QVariantMap value = data.toMap();
155  if(value.contains("albumlist"))
156  {
157  m_totalSize = value["total"].toInt();
158 
159  const QVariantList &datas = value["albumlist"].toList();
160  for(const QVariant &var : qAsConst(datas))
161  {
162  if(var.isNull())
163  {
164  continue;
165  }
166 
167  value = var.toMap();
169 
170  MusicResultDataItem item;
171  item.m_id = value["albumid"].toString();
172  item.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["pic"].toString(), {});
173  item.m_name = value["name"].toString();
174  item.m_updateTime = value["pub"].toString().replace(TTK_DEFAULT_STR, TTK_DOT);
175  Q_EMIT createAlbumItem(item);
176  }
177  }
178  }
179  }
180 
181  Q_EMIT downLoadDataChanged({});
182  deleteAll();
183 }
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
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
MusicKWQueryAlbumRequest(QObject *parent=nullptr)
static constexpr const char * KW_ARTIST_ALBUM_URL
MusicKWQueryArtistAlbumRequest(QObject *parent=nullptr)
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
QString makeCoverPixmapUrl(const QString &url, const QString &id)
void makeRequestRawHeader(QNetworkRequest *request)
virtual void downLoadFinished()
#define TTK_DOT
Definition: ttkglobal.h:193
The class of the query album download data from net.
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
virtual void startToPage(int offset) overridefinal
static constexpr const char * KW_SONG_LRC_URL
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
QNetworkAccessManager m_manager
virtual void startToPage(int offset) overridefinal
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
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
static constexpr const char * QUERY_KW_INTERFACE
#define TTK_SLOT
Definition: ttkqtglobal.h:165
QString makeSongArtist(const QString &name)
#define ARTIST_ATTR_PAGE_SIZE
virtual void downLoadFinished() overridefinal
static constexpr const char * KW_ALBUM_URL
album url
#define SONG_PAGE_SIZE
virtual void downLoadFinished() overridefinal
TTK_MODULE_EXPORT QString toString(Record type)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
bool findUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
void parseFromSongProperty(TTK::MusicSongInformation *info, int bitrate)
The class of the music song information.
Definition: musicobject.h:281
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59