TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickgqueryartistrequest.cpp
Go to the documentation of this file.
2 
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_ARTIST_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  value = value["data"].toMap();
54  m_totalSize = value["total"].toInt();
55 
56  const QVariantList &datas = value["info"].toList();
57  for(const QVariant &var : qAsConst(datas))
58  {
59  if(var.isNull())
60  {
61  continue;
62  }
63 
64  value = var.toMap();
66 
68  info.m_songId = value["hash"].toString();
69 
70  info.m_artistId = m_queryValue;
71 
72  info.m_albumId = value["album_id"].toString();
73  info.m_albumName = TTK::String::charactersReplace(value["album_name"].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_artistFound)
86  {
87  m_artistFound = true;
90  queryArtistIntro(&item);
92 
93  item.m_id = info.m_artistId;
94  item.m_name = info.m_artistName;
95  item.m_coverUrl = info.m_coverUrl;
96  Q_EMIT createArtistItem(item);
97  }
98 
99  Q_EMIT createResultItem({info, serverToString()});
100  m_items << info;
101  }
102  }
103  }
104  }
105 
106  Q_EMIT downLoadDataChanged({});
107  deleteAll();
108 }
109 
111 {
112  QNetworkRequest request;
113  request.setUrl(TTK::Algorithm::mdII(KG_ARTIST_INFO_URL, false).arg(m_queryValue));
115 
116  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
117  if(bytes.isEmpty())
118  {
119  return;
120  }
121 
122  QJson::Parser json;
123  bool ok = false;
124  const QVariant &data = json.parse(bytes, &ok);
125  if(ok)
126  {
127  QVariantMap value = data.toMap();
128  if(value["errcode"].toInt() == 0)
129  {
130  value = value["data"].toMap();
131 
132  item->m_nickName = value["alias"].toString();
133  item->m_description = value["intro"].toString();
134 
135  if(item->m_nickName.isEmpty())
136  {
137  item->m_nickName = TTK_DEFAULT_STR;
138  }
139  }
140  }
141 }
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
#define ARTIST_PAGE_SIZE
static constexpr const char * QUERY_KG_INTERFACE
virtual void downLoadFinished() overridefinal
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
static constexpr const char * KG_ARTIST_INFO_URL
The class of the query artist download data from net.
virtual void downLoadFinished()
void makeRequestRawHeader(QNetworkRequest *request)
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) 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
QNetworkAccessManager m_manager
void createResultItem(const MusicResultInfoItem &songItem)
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
virtual void startToPage(int offset) overridefinal
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
static constexpr const char * KG_ARTIST_URL
artist url
MusicKGQueryArtistRequest(QObject *parent=nullptr)
TTK_MODULE_EXPORT QString toString(Record type)
void queryArtistIntro(MusicResultDataItem *item) const
void parseFromSongAlbumLrc(TTK::MusicSongInformation *info)
void createArtistItem(const MusicResultDataItem &item)
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
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
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123