TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicunityquerymovierequest.cpp
Go to the documentation of this file.
3 
7 namespace ReqYYTInterface
8 {
9  static constexpr const char *MODULE = "YYT";
10  static constexpr const char *MOVIE_URL = "aHFyKzJ2V2gvdWVrdzEyWlBmUFdHbys5RGM3STRrY25uQ2xCRDdXeldPV0pXMWtNVmN1di9CRndFeDNqbExEdjA5dC9qcWEzMWFxc3NnRWkrcFcrZlBReC90bz0=";
11  static constexpr const char *MOVIE_DATA_URL = "emxYODBYb2dkQUVzcFcxVFZJS29kbzIwMzhybDVJRk1aNDFab1l3ellaM2pEdEFTVHFvN3RRV2ZNOXM4QkFkVXcrNWNzamFzc2ducEs2NXVyU1RmaVM2VlJtSmlSVUt5MUJmSE9WS2lxc3A5bVh0TXNBRzBEeWd2R29yNVZkUzJLbVBVbGdQSFZOemdQUGkxWFN5TllweHdDNnA3ZStUclVIUE1zYmpwNkVaSC96RHY5eXdTVWdoTVhsK2tidGhmOGcvcFpLejA5NlVLaUlxZko5Ni9ucEJRSUJyZVJGUW5YQlpLQzBGdm44SklDVDh5T0xmTWZoRWpoU3pWTFRtby9mYWQ0QlpJNjk4Q3dzczA=";
12 }
13 
17 namespace ReqBLInterface
18 {
19  static constexpr const char *MODULE = "BL";
20 }
21 
22 
23 
25  : MusicQueryMovieRequest(parent),
26  m_isUnity(false),
27  m_pluginSelector(0),
28  m_value("0")
29 {
31 }
32 
34 {
35  TTK_INFO_STREAM(className() << __FUNCTION__ << offset);
36 
37  deleteAll();
38  m_totalSize = 0;
40 
41  switch(m_pluginSelector)
42  {
43  case 0:
44  {
45  QNetworkRequest request;
46  request.setUrl(TTK::Algorithm::mdII(ReqYYTInterface::MOVIE_URL, false));
47  TTK::setSslConfiguration(&request);
48  TTK::makeContentTypeHeader(&request, "application/json");
49 
50  TTK_INFO_STREAM("parse song property in yyt module");
51 
54  break;
55  }
56  case 1:
57  {
58  QNetworkRequest request;
59  request.setUrl(TTK::Algorithm::mdII(BL_MOVIE_URL, false).arg(m_queryValue).arg(m_pageIndex));
61 
62  TTK_INFO_STREAM("parse song property in bl module");
63 
65  m_reply = m_manager.get(request);
66  break;
67  }
68  default: return;
69  }
70 
71  connect(m_reply, SIGNAL(finished()), SLOT(downLoadUnityFinished()));
73 }
74 
76 {
77  TTK_INFO_STREAM(className() << __FUNCTION__);
78 
80  if(m_reply && m_reply->error() == QNetworkReply::NoError)
81  {
82  QJsonParseError ok;
83  const QJsonDocument &json = QJsonDocument::fromJson(m_reply->readAll(), &ok);
85  {
86  QVariantMap value = json.toVariant().toMap();
87  const int lastCount = m_items.count();
88 
89  switch(m_pluginSelector)
90  {
91  case 0:
92  {
93  if(value["code"].toInt() == 0 && value.contains("data"))
94  {
95  const QVariantList &datas = value["data"].toList();
96  for(const QVariant &var : qAsConst(datas))
97  {
98  if(var.isNull())
99  {
100  continue;
101  }
102 
103  value = var.toMap();
105 
107 
109  info.m_songId = value["id"].toString();
110  info.m_songName = TTK::String::charactersReplace(value["title"].toString());
111 
112  const QVariantList &artistsArray = value["artists"].toList();
113  for(const QVariant &artistValue : qAsConst(artistsArray))
114  {
115  if(artistValue.isNull())
116  {
117  continue;
118  }
119 
120  const QVariantMap &artistObject = artistValue.toMap();
121  const QString &artistName = TTK::String::charactersReplace(artistObject["name"].toString());
122  info.m_artistName = info.m_artistName.isEmpty() ? artistName : (info.m_artistName + ";" + artistName);
123  }
124 
125  value = value["fullClip"].toMap();
126  info.m_coverUrl = value["cover"].toString();
127  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
128 
129  const QVariantList &urlsArray = value["urls"].toList();
130  for(const QVariant &urlValue : qAsConst(urlsArray))
131  {
132  if(urlValue.isNull())
133  {
134  continue;
135  }
136 
137  value = urlValue.toMap();
138 
140  prop.m_url = value["url"].toString();
141  prop.m_bitrate = value["streamType"].toInt() == 1 ? TTK_BN_250 : TTK_BN_750;
143  info.m_songProps.append(prop);
144  }
145 
146  if(info.m_songProps.isEmpty() || !fetchUrlPathSize(&info.m_songProps, info.m_duration))
147  {
148  continue;
149  }
150 
151  m_value = info.m_songId;
152  Q_EMIT createResultItem({info, serverToString()});
153  m_items << info;
154  }
155  }
156 
157  findAllPlugins(lastCount);
158  break;
159  }
160  case 1:
161  {
162  if(value["code"].toInt() == 0 && value.contains("data"))
163  {
164  value = value["data"].toMap();
165  m_totalSize = value["numResults"].toInt();
166 
167  const QVariantList &datas = value["result"].toList();
168  for(const QVariant &var : qAsConst(datas))
169  {
170  if(var.isNull())
171  {
172  continue;
173  }
174 
175  value = var.toMap();
177 
179  info.m_songId = value["bvid"].toString();
180  info.m_songName = TTK::String::charactersReplace(value["title"].toString());
181 
182  info.m_artistName = TTK::String::charactersReplace(value["author"].toString());
183 
184  info.m_coverUrl = value["pic"].toString();
185  if(info.m_coverUrl.startsWith("//"))
186  {
188  }
189  else if(!TTK::String::isNetworkUrl(info.m_coverUrl))
190  {
191  info.m_coverUrl = HTTP_PROTOCOL + info.m_coverUrl;
192  }
193 
194  QString cid;
196 
197  if(!cid.isEmpty())
198  {
200  }
201 
202  if(info.m_songProps.isEmpty())
203  {
204  continue;
205  }
206 
207  Q_EMIT createResultItem({info, serverToString()});
208  m_items << info;
209  }
210  }
211  break;
212  }
213  default: break;
214  }
215  }
216  }
217 
218  Q_EMIT downLoadDataChanged({});
219  deleteAll();
220 }
221 
223 {
224  if(count + m_pageSize > m_items.count())
225  {
226  setToUnity();
228  }
229 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
#define TTK_NETWORK_QUERY_CHECK(VALUE)
#define HTTP_PROTOCOL_PREFIX
Definition: ttkglobal.h:282
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
TTK_MODULE_EXPORT void setSslConfiguration(QNetworkRequest *request, QSslSocket::PeerVerifyMode mode=QSslSocket::VerifyNone) noexcept
QNetworkReply * m_reply
#define HTTP_PROTOCOL
Definition: ttkglobal.h:285
QVariant toVariant() const
The class of the music song property.
Definition: musicobject.h:237
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
static constexpr const char * MOVIE_DATA_URL
void createResultItem(const MusicResultInfoItem &result)
static constexpr const char * BL_MOVIE_URL
song url
static constexpr const char * MOVIE_URL
virtual void downLoadFinished()
#define TTK_BN_250
Definition: ttkglobal.h:430
MusicUnityQueryMovieRequest(QObject *parent=nullptr)
voidpf uLong offset
Definition: ioapi.h:142
ParseError error
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:57
TTK_MODULE_EXPORT void makeContentTypeHeader(QNetworkRequest *request, const QByteArray &data={}) noexcept
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path) noexcept
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
static constexpr const char * MODULE
The class of the query movie download data from net.
QNetworkAccessManager m_manager
The namespace of the bl request interface.
void parseFromMovieInfo(TTK::MusicSongInformation *info, QString &cid)
bool fetchUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
virtual void replyError(QNetworkReply::NetworkError error) override
#define TTK_SLOT
Definition: ttkqtglobal.h:177
TTK_MODULE_EXPORT QString splitToken(const QString &name)
TTK_MODULE_EXPORT QString toString(Record type) noexcept
#define TTK_HIGH_LEVEL
Definition: ttkglobal.h:334
#define SONG_PAGE_SIZE
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
static constexpr const char * MODULE
The namespace of the yyt request interface.
virtual void startToPage(int offset) override
#define TTK_STR_CAT(...)
Definition: ttkglobal.h:240
void makeRequestRawHeader(QNetworkRequest *request) noexcept
void parseFromMovieProperty(TTK::MusicSongInformation *info, const QString &cid)
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
The class of the music song information.
Definition: musicobject.h:295
#define TTK_BN_750
Definition: ttkglobal.h:433
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123