-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
283 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
## simply工具箱 | ||
|
||
一个简单易用的跨平台工具箱,基于Qt开发 | ||
## V1.0 准备实现的功能 | ||
|
||
 | ||
|
||
 | ||
|
||
 | ||
## V1.0 准备实现的功能 | ||
|
||
- [x] 集成简单翻译 | ||
- [x] 屏幕截图和取色器 | ||
- [ ] B站实时数据 | ||
- [x] B站实时数据 | ||
- [ ] 还有些许bug | ||
## License | ||
|
||
See the [LICENSE](LICENSE) file for license rights and limitations (MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// Created by mhduiy on 2023/7/13. | ||
// | ||
|
||
#include "BiliBiliDataTool.h" | ||
#include <QDebug> | ||
#include <QFile> | ||
#include <QJsonDocument> | ||
#include <QJsonObject> | ||
#include <QJsonArray> | ||
#include <QJsonValue> | ||
#include <QNetworkAccessManager> | ||
#include <QNetworkReply> | ||
#include <QPixmap> | ||
|
||
const QString sessdata = "af2f29c8%2C1704762516%2Cad7cf%2A71qWs1EFcs2cskQdRym9fATqazZDQRLVb5DWQR6mbx7U0DNonWhfd0yG6O2FAXcYEC_7xqigAAJgA"; | ||
const QString bili_jct = "0a036ea1780e61be41b010e2fb7085ac"; | ||
|
||
BiliBiliDataTool::BiliBiliDataTool(QObject *parent) : QObject(parent) { | ||
jsonFilePath = qApp->applicationDirPath() + "/bilibili.json"; | ||
manager = new QNetworkAccessManager; | ||
} | ||
|
||
QMap<int, QString> BiliBiliDataTool::getData() { | ||
QMap<int, QString> result; | ||
QString command = QString("python3") + | ||
" D:\\code\\simplyTools\\src\\customComponents\\res\\getBiliBiliData.py" | ||
+ " " + sessdata + " " + bili_jct + " " + jsonFilePath; | ||
int ret = system(command.toLocal8Bit()); | ||
|
||
// 读取json数据文件 | ||
QFile file(jsonFilePath); | ||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
emit readError("JSON file opening failed"); | ||
return result; | ||
} | ||
QByteArray jsonData = file.readAll(); | ||
QJsonDocument document = QJsonDocument::fromJson(jsonData); | ||
if (document.isNull()) { | ||
emit readError("json document is null"); | ||
return result; | ||
} | ||
QJsonObject jsonObject = document.object(); | ||
for(int i = 0; i < BL_TOTAL; i++) { | ||
if(jsonObject.contains(jsonKey.value(i))) { | ||
if(i == BL_iconUrl || i == BL_userName) { | ||
result.insert(i, jsonObject[jsonKey.value(i)].toString()); | ||
} | ||
else if(i == BL_coinCount) { | ||
result.insert(i, QString::number(jsonObject[jsonKey.value(i)].toDouble())); | ||
} | ||
else { | ||
result.insert(i, QString::number(jsonObject[jsonKey.value(i)].toInt())); | ||
} | ||
} | ||
} | ||
emit readFinish(result); // 发送成功读取的消息 | ||
return result; | ||
} | ||
|
||
void BiliBiliDataTool::getImageFromUrl(const QString &url) { | ||
// 设置要获取的图片链接 | ||
QUrl imageUrl(url); | ||
|
||
// 发送网络请求获取图片 | ||
QNetworkReply *reply = manager->get(QNetworkRequest(imageUrl)); | ||
|
||
// 连接信号和槽,当请求完成时触发 | ||
QObject::connect(reply, &QNetworkReply::finished, [=]() { | ||
if (reply->error() == QNetworkReply::NoError) { | ||
// 读取图片数据 | ||
QByteArray imageData = reply->readAll(); | ||
|
||
// 将图片数据加载到 QPixmap | ||
QPixmap pixmap; | ||
pixmap.loadFromData(imageData); | ||
readUserImageFinish(pixmap); | ||
} else { | ||
// 处理请求错误 | ||
qDebug() << "请求错误: " << reply->errorString(); | ||
} | ||
|
||
// 清理资源 | ||
reply->deleteLater(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Created by mhduiy on 2023/7/13. | ||
// | ||
|
||
#ifndef SIMPLYTOOLS_BILIBILIDATATOOL_H | ||
#define SIMPLYTOOLS_BILIBILIDATATOOL_H | ||
|
||
#include <QObject> | ||
#include <QMap> | ||
#include <QGuiApplication> | ||
#include <QNetworkAccessManager> | ||
|
||
const QString pythonFileName = ":/getBiliBiliData.py"; | ||
|
||
enum bilibiliDataEnum { | ||
BL_iconUrl = 0, | ||
BL_userName, | ||
BL_uid, | ||
BL_level, | ||
BL_coinCount, | ||
BL_followCount, | ||
BL_fansCount, | ||
BL_likeCount, | ||
BL_playCount, | ||
BL_readCount, | ||
BL_TOTAL | ||
}; | ||
|
||
const QStringList jsonKey { | ||
"iconUrl", | ||
"userName", | ||
"uid", | ||
"level", | ||
"coinCount", | ||
"followCount", | ||
"fansCount", | ||
"likeCount", | ||
"playCount", | ||
"readCount" | ||
}; | ||
|
||
class BiliBiliDataTool : public QObject{ | ||
Q_OBJECT | ||
public: | ||
explicit BiliBiliDataTool(QObject *parent = nullptr); | ||
QMap<int, QString> getData(); | ||
void getImageFromUrl(const QString &url); | ||
|
||
signals: | ||
|
||
void readFinish(const QMap<int, QString>& map); | ||
void readError(const QString& errorInfo); | ||
void readUserImageFinish(const QPixmap &pixmap); | ||
|
||
private: | ||
QString jsonFilePath; | ||
QNetworkAccessManager *manager = nullptr; | ||
}; | ||
|
||
|
||
#endif //SIMPLYTOOLS_BILIBILIDATATOOL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.