TTKMusicPlayer  4.2.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() << __FUNCTION__ << 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() << __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  QJsonParseError ok;
48  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll().replace("'", "\""), &ok);
50  {
51  QVariantMap value = json.toVariant().toMap();
52  if(value.contains("musiclist"))
53  {
55  item.m_id = value["albumid"].toString();
56  item.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["pic"].toString(), {});
57  const QString &albumName = value["name"].toString();
58  item.m_count = albumName;
59  item.m_description = value["company"].toString();
60  item.m_time = value["pub"].toString();
61  item.m_category = value["lang"].toString();
62 
63  m_totalSize = value["songnum"].toInt();
64 
65  const QVariantList &datas = value["musiclist"].toList();
66  for(const QVariant &var : qAsConst(datas))
67  {
68  if(var.isNull())
69  {
70  continue;
71  }
72 
73  value = var.toMap();
75 
77  info.m_songId = value["id"].toString();
78  info.m_songName = TTK::String::charactersReplace(value["name"].toString());
79 
80  info.m_artistId = value["artistid"].toString();
81  info.m_artistName = ReqKWInterface::makeSongArtist(value["artist"].toString());
82 
83  info.m_albumId = item.m_id;
85 
86  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
87  info.m_lrcUrl = TTK::Algorithm::mdII(KW_SONG_LRC_URL, false).arg(info.m_songId);
89  info.m_year.clear();
90  info.m_trackNumber = "0";
91 
93  ReqKWInterface::parseFromSongProperty(&info, value["formats"].toString());
95 
96  if(!m_albumFound)
97  {
98  m_albumFound = true;
99  item.m_id = info.m_albumId;
100  item.m_name = info.m_artistName;
101  Q_EMIT createAlbumItem(item);
102  }
103 
104  Q_EMIT createResultItem({info, serverToString()});
105  m_items << info;
106  }
107  }
108  }
109  }
110 
111  Q_EMIT downLoadDataChanged({});
112  deleteAll();
113 }
114 
115 
116 
118  : MusicQueryAlbumRequest(parent)
119 {
122 }
123 
125 {
126  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
127 
128  deleteAll();
129  m_totalSize = 0;
131 
132  QNetworkRequest request;
133  request.setUrl(TTK::Algorithm::mdII(KW_ARTIST_ALBUM_URL, false).arg(m_queryValue).arg(offset).arg(m_pageSize));
135 
136  m_reply = m_manager.get(request);
137  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
139 }
140 
142 {
143  TTK_INFO_STREAM(className() << __FUNCTION__);
144 
146  if(m_reply && m_reply->error() == QNetworkReply::NoError)
147  {
148  QJsonParseError ok;
149  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll().replace("'", "\""), &ok);
151  {
152  QVariantMap value = json.toVariant().toMap();
153  if(value.contains("albumlist"))
154  {
155  m_totalSize = value["total"].toInt();
156 
157  const QVariantList &datas = value["albumlist"].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 = ReqKWInterface::makeCoverPixmapUrl(value["pic"].toString(), {});
171  item.m_name = value["name"].toString();
172  item.m_time = value["pub"].toString().replace(TTK_DEFAULT_STR, TTK_DOT);
173  Q_EMIT createAlbumItem(item);
174  }
175  }
176  }
177  }
178 
179  Q_EMIT downLoadDataChanged({});
180  deleteAll();
181 }
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:276
MusicKWQueryAlbumRequest(QObject *parent=nullptr)
QVariant toVariant() const
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
static constexpr const char * KW_ARTIST_ALBUM_URL
MusicKWQueryArtistAlbumRequest(QObject *parent=nullptr)
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
QString makeCoverPixmapUrl(const QString &url, const QString &id)
void createResultItem(const MusicResultInfoItem &result)
virtual void downLoadFinished()
#define TTK_DOT
Definition: ttkglobal.h:266
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)
ParseError error
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:57
virtual void startToPage(int offset) overridefinal
static constexpr const char * KW_SONG_LRC_URL
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
QNetworkAccessManager m_manager
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
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
static constexpr const char * QUERY_KW_INTERFACE
#define TTK_SLOT
Definition: ttkqtglobal.h:177
QString makeSongArtist(const QString &name)
#define ARTIST_ATTR_PAGE_SIZE
virtual void downLoadFinished() overridefinal
TTK_MODULE_EXPORT QString toString(Record type) noexcept
static constexpr const char * KW_ALBUM_URL
album url
#define SONG_PAGE_SIZE
virtual void downLoadFinished() overridefinal
void makeRequestRawHeader(QNetworkRequest *request) noexcept
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:295
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59