TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickwqueryartistrequest.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(KW_ARTIST_URL, false).arg(m_queryValue).arg(offset).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 
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("abslist"))
54  {
55  m_totalSize = value["TOTAL"].toInt();
56 
57  const QVariantList &datas = value["abslist"].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["MUSICRID"].toString().remove("MUSIC_");
70  info.m_songName = TTK::String::charactersReplace(value["SONGNAME"].toString());
71 
72  info.m_artistId = value["ARTISTID"].toString();
73  info.m_artistName = ReqKWInterface::makeSongArtist(value["ARTIST"].toString());
74 
75  info.m_albumId = value["ALBUMID"].toString();
76  info.m_albumName = TTK::String::charactersReplace(value["ALBUM"].toString());
77 
78  info.m_coverUrl = ReqKWInterface::makeCoverPixmapUrl(value["web_albumpic_short"].toString(), info.m_songId);
79  info.m_lrcUrl = TTK::Algorithm::mdII(KW_SONG_LRC_URL, false).arg(info.m_songId);
80  info.m_duration = TTKTime::formatDuration(value["DURATION"].toInt() * TTK_DN_S2MS);
81  info.m_year = value["RELEASEDATE"].toString();
82  info.m_trackNumber = "0";
83 
85  ReqKWInterface::parseFromSongProperty(&info, value["FORMATS"].toString());
87 
88  if(!m_artistFound)
89  {
90  m_artistFound = true;
93  queryArtistIntro(&item);
95 
96  item.m_id = info.m_artistId;
97  item.m_name = info.m_artistName;
98  Q_EMIT createArtistItem(item);
99  }
100 
101  Q_EMIT createResultItem({info, serverToString()});
102  m_items << info;
103  }
104  }
105  }
106  }
107 
108  Q_EMIT downLoadDataChanged({});
109  deleteAll();
110 }
111 
113 {
114  QNetworkRequest request;
115  request.setUrl(TTK::Algorithm::mdII(KW_ARTIST_INFO_URL, false).arg(m_queryValue));
117 
118  QByteArray bytes = TTK::syncNetworkQueryForGet(&request);
119  if(bytes.isEmpty())
120  {
121  return;
122  }
123 
124  QJson::Parser json;
125  bool ok = false;
126  const QVariant &data = json.parse(bytes.replace("'", "\""), &ok);
127  if(ok)
128  {
129  const QVariantMap &value = data.toMap();
130  item->m_updateTime = value["birthday"].toString();
131  item->m_nickName = value["aartist"].toString();
132  item->m_coverUrl = value["hts_pic"].toString();
133  item->m_description = TTK::String::convertHtmlToPlain(value["info"].toString());
134 
135  if(item->m_nickName.isEmpty())
136  {
137  item->m_nickName = TTK_DEFAULT_STR;
138  }
139  }
140 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
TTK_MODULE_EXPORT QString convertHtmlToPlain(const QString &value)
#define TTK_NETWORK_QUERY_CHECK(VALUE)
MusicKWQueryArtistRequest(QObject *parent=nullptr)
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
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
QString makeCoverPixmapUrl(const QString &url, const QString &id)
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
void makeRequestRawHeader(QNetworkRequest *request)
The class of the query artist download data from net.
virtual void downLoadFinished()
voidpf uLong offset
Definition: ioapi.h:142
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
TTK::MusicSongInformationList m_items
static constexpr const char * KW_ARTIST_INFO_URL
#define qAsConst
Definition: ttkqtglobal.h:53
static constexpr const char * KW_SONG_LRC_URL
#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
static constexpr const char * QUERY_KW_INTERFACE
#define TTK_SLOT
Definition: ttkqtglobal.h:165
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate) overridefinal
QString makeSongArtist(const QString &name)
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
virtual void downLoadFinished() overridefinal
TTK_MODULE_EXPORT QString toString(Record type)
virtual void startToPage(int offset) overridefinal
static constexpr const char * KW_ARTIST_URL
artist url
void createArtistItem(const MusicResultDataItem &item)
void queryArtistIntro(MusicResultDataItem *item) const
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
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123