Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat 添加文件序号 #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions B23Downloader/DownloadDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,15 @@ void DownloadDialog::setupUi()

if (contentType != ContentType::Live) {
auto selLayout = new QHBoxLayout;
selAllBtn = new QToolButton;
selAllBtn = new QToolButton(this);
selAllBtn->setText("全选");
selAllBtn->setAutoRaise(true);
selAllBtn->setCursor(Qt::PointingHandCursor);
selCountLabel = new QLabel;
addNumberPrefixBox = new QCheckBox(this);
addNumberPrefixBox->setText("文件添加序号");
selCountLabel = new QLabel(this);
selLayout->addWidget(selAllBtn);
selLayout->addWidget(addNumberPrefixBox);
selLayout->addStretch(1);
selLayout->addWidget(selCountLabel);
mainLayout->addLayout(selLayout);
Expand Down Expand Up @@ -828,6 +831,18 @@ QList<AbstractDownloadTask*> DownloadDialog::getDownloadTasks()
if (contentType == ContentType::Live) {
tasks.append(new LiveDownloadTask(contentId, qn, dir.filePath(title)));
} else {
// 添加文件序号
auto addNumberPrefix = addNumberPrefixBox->isChecked();
auto number = 1;
auto numberCount = 0;
if(addNumberPrefix) {
auto selSize = tree->selectedItems().size();
while(selSize > 0) {
selSize /= 10;
numberCount++;
}
}

QList<std::tuple<qint64, QString>> metaInfos;
for (auto item : tree->selectedItems()) {
auto videoItem = static_cast<ContentTreeItem*>(item);
Expand All @@ -837,9 +852,16 @@ QList<AbstractDownloadTask*> DownloadDialog::getDownloadTasks()
auto itemTitle = videoItem->longTitle();
metaInfos.emplaceBack(
videoItem->contentItemId(),
(itemTitle.isEmpty() ? title : title + " " + itemTitle)
QString("%1%2%3%4")
.arg(addNumberPrefix
? QString("%1.").arg(number++, numberCount, 10, QLatin1Char('0'))
: "")
.arg(title)
.arg(itemTitle.isEmpty() ? "" : " ")
.arg(itemTitle)
);
}

for (auto &[itemId, name] : metaInfos) {
AbstractDownloadTask *task = nullptr;
auto path = dir.filePath(name);
Expand Down
1 change: 1 addition & 0 deletions B23Downloader/DownloadDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private slots:
QLabel *titleLabel;

QToolButton *selAllBtn = nullptr;
QCheckBox *addNumberPrefixBox = nullptr;
QLabel *selCountLabel = nullptr;
ContentTreeWidget *tree = nullptr;
QComboBox *qnComboBox = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion B23Downloader/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::pair<QJsonObject, QString> Bili::parseReply(QNetworkReply *reply, const QSt
auto data = reply->readAll();
auto jsonDoc = QJsonDocument::fromJson(data);
auto jsonObj = jsonDoc.object();
qDebug() << "reply from" << reply->url(); // << QString::fromUtf8(data);
qDebug() << "reply from" << reply->url();

if (jsonObj.isEmpty()) {
return { QJsonObject(), "http请求错误" };
Expand Down