TTKMusicPlayer  4.1.3.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  QJson::Parser json;
83  bool ok = false;
84  const QVariant &data = json.parse(m_reply->readAll(), &ok);
85  if(ok)
86  {
87  QVariantMap value = data.toMap();
88  const int lastCount = m_items.count();
89 
90  switch(m_pluginSelector)
91  {
92  case 0:
93  {
94  if(value["code"].toInt() == 0 && value.contains("data"))
95  {
96  const QVariantList &datas = value["data"].toList();
97  for(const QVariant &var : qAsConst(datas))
98  {
99  if(var.isNull())
100  {
101  continue;
102  }
103 
104  value = var.toMap();
106 
108 
110  info.m_songId = value["id"].toString();
111  info.m_songName = TTK::String::charactersReplace(value["title"].toString());
112 
113  const QVariantList &artistsArray = value["artists"].toList();
114  for(const QVariant &artistValue : qAsConst(artistsArray))
115  {
116  if(artistValue.isNull())
117  {
118  continue;
119  }
120 
121  const QVariantMap &artistObject = artistValue.toMap();
122  const QString &artistName = TTK::String::charactersReplace(artistObject["name"].toString());
123  info.m_artistName = info.m_artistName.isEmpty() ? artistName : (info.m_artistName + ";" + artistName);
124  }
125 
126  value = value["fullClip"].toMap();
127  info.m_coverUrl = value["cover"].toString();
128  info.m_duration = TTKTime::formatDuration(value["duration"].toInt() * TTK_DN_S2MS);
129 
130  const QVariantList &urlsArray = value["urls"].toList();
131  for(const QVariant &urlValue : qAsConst(urlsArray))
132  {
133  if(urlValue.isNull())
134  {
135  continue;
136  }
137 
138  value = urlValue.toMap();
139 
141  prop.m_url = value["url"].toString();
142  prop.m_bitrate = value["streamType"].toInt() == 1 ? TTK_BN_250 : TTK_BN_750;
144  info.m_songProps.append(prop);
145  }
146 
147  if(info.m_songProps.isEmpty() || !fetchUrlPathSize(&info.m_songProps, info.m_duration))
148  {
149  continue;
150  }
151 
152  m_value = info.m_songId;
153  Q_EMIT createResultItem({info, serverToString()});
154  m_items << info;
155  }
156  }
157 
158  findAllPlugins(lastCount);
159  break;
160  }
161  case 1:
162  {
163  if(value["code"].toInt() == 0 && value.contains("data"))
164  {
165  value = value["data"].toMap();
166  m_totalSize = value["numResults"].toInt();
167 
168  const QVariantList &datas = value["result"].toList();
169  for(const QVariant &var : qAsConst(datas))
170  {
171  if(var.isNull())
172  {
173  continue;
174  }
175 
176  value = var.toMap();
178 
180  info.m_songId = value["bvid"].toString();
181  info.m_songName = TTK::String::charactersReplace(value["title"].toString());
182 
183  info.m_artistName = TTK::String::charactersReplace(value["author"].toString());
184 
185  info.m_coverUrl = value["pic"].toString();
186  if(info.m_coverUrl.startsWith("//"))
187  {
189  }
190  else if(!TTK::String::isNetworkUrl(info.m_coverUrl))
191  {
192  info.m_coverUrl = HTTP_PROTOCOL + info.m_coverUrl;
193  }
194 
195  QString cid;
197 
198  if(!cid.isEmpty())
199  {
201  }
202 
203  if(info.m_songProps.isEmpty())
204  {
205  continue;
206  }
207 
208  Q_EMIT createResultItem({info, serverToString()});
209  m_items << info;
210  }
211  }
212  break;
213  }
214  default: break;
215  }
216  }
217  }
218 
219  Q_EMIT downLoadDataChanged({});
220  deleteAll();
221 }
222 
224 {
225  if(count + m_pageSize > m_items.count())
226  {
227  setToUnity();
229  }
230 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
#define TTK_NETWORK_QUERY_CHECK(VALUE)
#define HTTP_PROTOCOL_PREFIX
Definition: ttkglobal.h:208
virtual void deleteAll()
void downLoadDataChanged(const QString &bytes)
QNetworkReply * m_reply
#define HTTP_PROTOCOL
Definition: ttkglobal.h:211
The class of the music song property.
Definition: musicobject.h:225
TTK_MODULE_EXPORT void setSslConfiguration(QNetworkRequest *request, QSslSocket::PeerVerifyMode mode=QSslSocket::VerifyNone)
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
static constexpr const char * MOVIE_DATA_URL
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:355
MusicUnityQueryMovieRequest(QObject *parent=nullptr)
voidpf uLong offset
Definition: ioapi.h:142
TTK::MusicSongInformationList m_items
#define qAsConst
Definition: ttkqtglobal.h:51
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:68
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 createResultItem(const MusicResultInfoItem &songItem)
void parseFromMovieInfo(TTK::MusicSongInformation *info, QString &cid)
bool fetchUrlPathSize(TTK::MusicSongProperty *prop, const QString &duration) const
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:181
TTK_MODULE_EXPORT QString splitToken(const QString &name)
#define TTK_HIGH_LEVEL
Definition: ttkglobal.h:260
TTK_MODULE_EXPORT void makeContentTypeHeader(QNetworkRequest *request, const QByteArray &data={})
#define SONG_PAGE_SIZE
#define TTK_DN_S2MS
Definition: ttkglobal.h:281
static constexpr const char * MODULE
The namespace of the yyt request interface.
TTK_MODULE_EXPORT QString toString(Record type)
virtual void startToPage(int offset) override
#define TTK_STR_CAT(...)
Definition: ttkglobal.h:167
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
void makeRequestRawHeader(QNetworkRequest *request)
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:283
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path)
#define TTK_BN_750
Definition: ttkglobal.h:358
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123