TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickwqueryinterface.cpp
Go to the documentation of this file.
3 
5 
6 void ReqKWInterface::makeRequestRawHeader(QNetworkRequest *request) noexcept
7 {
11 }
12 
13 QString ReqKWInterface::makeSongArtist(const QString &name)
14 {
15  return TTK::String::charactersReplace(name).replace("&", ";").replace("+", ";");
16 }
17 
18 QString ReqKWInterface::makeCoverPixmapUrl(const QString &url, const QString &id)
19 {
20  if(url.isEmpty() && !id.isEmpty())
21  {
22  return TTK::Algorithm::mdII(KW_ALBUM_COVER_INFO_URL, false).arg(id);
23  }
24  else if(!TTK::String::isNetworkUrl(url))
25  {
26  return TTK::Algorithm::mdII(KW_ALBUM_COVER_URL, false) + url.section('/', 1);
27  }
28  else
29  {
30  return url;
31  }
32 }
33 
34 static void parseSongPropertyV1(TTK::MusicSongInformation *info, const QString &suffix, const QString &format, int bitrate)
35 {
36  for(const TTK::MusicSongProperty &prop : qAsConst(info->m_songProps))
37  {
38  if(prop.m_bitrate == bitrate)
39  {
40  return;
41  }
42  }
43 
44  TTK_INFO_STREAM("parse song" << bitrate << "kbps property in v1 module");
45 
46  QString quality;
47  if((format.contains("MP3128") || format.contains("128kmp3")) && bitrate == TTK_BN_128)
48  {
49  quality = "128kmp3";
50  }
51  else if((format.contains("MP3192") || format.contains("192kmp3")) && bitrate == TTK_BN_192)
52  {
53  quality = "192kmp3";
54  }
55  else if((format.contains("MP3H") || format.contains("320kmp3")) && bitrate == TTK_BN_320)
56  {
57  quality = "320kmp3";
58  }
59  else if((format.contains("FLAC") || format.contains("2000kflac")) && bitrate == TTK_BN_1000)
60  {
61  quality = "2000kflac";
62  }
63  else
64  {
65  return;
66  }
67 
68  QNetworkRequest request;
69  request.setUrl(TTK::Algorithm::mdII(KW_SONG_PATH_V1_URL, false).arg(info->m_songId, quality));
71 
72  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
73  if(bytes.isEmpty())
74  {
75  return;
76  }
77 
78  QJsonParseError ok;
79  const QJsonDocument &json = QJsonDocument::fromJson(bytes, &ok);
81  {
82  QVariantMap value = json.toVariant().toMap();
83  if(value["code"].toInt() == 200 && value.contains("data"))
84  {
85  value = value["data"].toMap();
86  if(value.isEmpty())
87  {
88  return;
89  }
90 
91  const QString &format = value["format"].toString();
92  if(format == suffix)
93  {
95  prop.m_url = value["url"].toString();
96  prop.m_size = TTK_DEFAULT_STR;
97  prop.m_format = suffix;
98  prop.m_bitrate = bitrate;
99  info->m_songProps.append(prop);
100  }
101  }
102  }
103 }
104 
105 static void parseSongPropertyV2(TTK::MusicSongInformation *info, const QString &suffix, const QString &format, int bitrate)
106 {
107  for(const TTK::MusicSongProperty &prop : qAsConst(info->m_songProps))
108  {
109  if(prop.m_bitrate == bitrate)
110  {
111  return;
112  }
113  }
114 
115  TTK_INFO_STREAM("parse song" << bitrate << "kbps property in v2 module");
116 
117  QString quality;
118  if((format.contains("MP3128") || format.contains("128kmp3")) && bitrate == TTK_BN_128)
119  {
120  quality = "128kmp3";
121  }
122  else if((format.contains("MP3192") || format.contains("192kmp3")) && bitrate == TTK_BN_192)
123  {
124  quality = "192kmp3";
125  }
126  else if((format.contains("MP3H") || format.contains("320kmp3")) && bitrate == TTK_BN_320)
127  {
128  quality = "320kmp3";
129  }
130  else if((format.contains("FLAC") || format.contains("2000kflac")) && bitrate == TTK_BN_1000)
131  {
132  quality = "2000kflac";
133  }
134  else
135  {
136  return;
137  }
138 
139  QAlgorithm::Des des;
140  const QString &parameter = des.encrypt(TTK::Algorithm::mdII(KW_SONG_PATH_V2_DATA_URL, false).arg(quality).toUtf8(),
141  TTK::Algorithm::mdII("OGlVTjJWOEdlMkkzSkZIeg==", MDII_SHR_KEY, false).toUtf8());
142  QNetworkRequest request;
143  request.setUrl(TTK::Algorithm::mdII(KW_SONG_PATH_V2_URL, false).arg(parameter, info->m_songId));
145 
146  const QByteArray &bytes = TTK::syncNetworkQueryForGet(&request);
147  if(bytes.isEmpty())
148  {
149  return;
150  }
151 
152  if(!bytes.contains("res not found"))
153  {
154  const QString text(bytes);
155  const QRegExp regx(".*url=(.*)\r\nsig=");
156 
157  if(regx.indexIn(text) != -1)
158  {
160  prop.m_url = regx.cap(1);
161  prop.m_size = TTK_DEFAULT_STR;
162  prop.m_format = suffix;
163  prop.m_bitrate = bitrate;
164 
165  if(prop.m_url.isEmpty() || info->m_songProps.contains(prop))
166  {
167  return;
168  }
169 
170  info->m_songProps.append(prop);
171  }
172  }
173 }
174 
175 static void parseSongPropertyV3(TTK::MusicSongInformation *info, const QString &format, int bitrate)
176 {
177  for(const TTK::MusicSongProperty &prop : qAsConst(info->m_songProps))
178  {
179  if(prop.m_bitrate == bitrate)
180  {
181  return;
182  }
183  }
184 
185  TTK_INFO_STREAM("parse song" << bitrate << "kbps property in v3 module");
186 
187  if(((format.contains("MP3128") || format.contains("128kmp3")) && bitrate == TTK_BN_128) ||
188  ((format.contains("MP3H") || format.contains("320kmp3")) && bitrate == TTK_BN_320) ||
189  ((format.contains("FLAC") || format.contains("2000kflac")) && bitrate == TTK_BN_1000))
190  {
192  }
193 }
194 
195 static void parseSongProperty(TTK::MusicSongInformation *info, const QString &suffix, const QString &format, int bitrate)
196 {
197  parseSongPropertyV1(info, suffix, format, bitrate);
198  parseSongPropertyV2(info, suffix, format, bitrate);
199  parseSongPropertyV3(info, format, bitrate);
200 }
201 
203 {
204  if(info->m_songId.isEmpty())
205  {
206  return;
207  }
208 
209  if(info->m_formatProps.isEmpty())
210  {
211  parseSongProperty(info, MP3_FILE_SUFFIX, "128kmp3", TTK_BN_128);
212  return;
213  }
214 
215  if(bitrate == TTK_BN_0)
216  {
221  }
222  else
223  {
224  parseSongProperty(info, bitrate > TTK_BN_320 ? FLAC_FILE_SUFFIX : MP3_FILE_SUFFIX, info->m_formatProps, bitrate);
225  }
226 }
227 
229 {
230  info->m_formatProps = format;
231 }
TTK_MODULE_EXPORT QString charactersReplace(const QString &value)
static void parseSongPropertyV3(TTK::MusicSongInformation *info, const QString &format, int bitrate)
TTK_MODULE_EXPORT void setSslConfiguration(QNetworkRequest *request, QSslSocket::PeerVerifyMode mode=QSslSocket::VerifyNone) noexcept
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:276
static constexpr const char * KW_SONG_PATH_V1_URL
static void parseSongPropertyV1(TTK::MusicSongInformation *info, const QString &suffix, const QString &format, int bitrate)
QVariant toVariant() const
The class of the music song property.
Definition: musicobject.h:237
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=0)
static constexpr const char * KW_ALBUM_COVER_URL
static constexpr const char * KW_ALBUM_COVER_INFO_URL
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
QString makeCoverPixmapUrl(const QString &url, const QString &id)
QByteArray encrypt(const QByteArray &in, const QByteArray &key)
Definition: deswrapper.cpp:349
TTK_MODULE_EXPORT QByteArray syncNetworkQueryForGet(QNetworkRequest *request)
#define TTK_BN_1000
Definition: ttkglobal.h:434
#define MP3_FILE_SUFFIX
Definition: musicobject.h:57
TTK_MODULE_EXPORT void makeUserAgentHeader(QNetworkRequest *request, const QByteArray &data={}) noexcept
static void parseSongPropertyV2(TTK::MusicSongInformation *info, const QString &suffix, const QString &format, int bitrate)
static void parseSongProperty(TTK::MusicSongInformation *info, const QString &suffix, const QString &format, int bitrate)
ParseError error
#define qAsConst
Definition: ttkqtglobal.h:57
const char * name
Definition: http_parser.c:458
TTK_MODULE_EXPORT void makeContentTypeHeader(QNetworkRequest *request, const QByteArray &data={}) noexcept
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path) noexcept
TTK_MODULE_EXPORT QString suffix(const QString &name)
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
The class of the des wrapper.
Definition: deswrapper.h:34
#define TTK_BN_0
Definition: ttkglobal.h:424
static constexpr const char * KW_SONG_PATH_V2_URL
#define TTK_BN_320
Definition: ttkglobal.h:431
static constexpr const char * QUERY_KW_INTERFACE
static constexpr const char * KW_SONG_PATH_V2_DATA_URL
QString makeSongArtist(const QString &name)
void makeRequestRawHeader(QNetworkRequest *request) noexcept
#define TTK_BN_192
Definition: ttkglobal.h:429
#define FLAC_FILE_SUFFIX
Definition: musicobject.h:59
void parseFromSongProperty(TTK::MusicSongInformation *info, const QString &type, const QString &id, int bitrate)
static constexpr const char * MDII_SHR_KEY
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 TTK_BN_128
Definition: ttkglobal.h:428