Skip to content

Commit 40f0097

Browse files
committed
Merge branch 'bugfix-crash-batch' into develop
2 parents 0e5324a + f9269f9 commit 40f0097

File tree

10 files changed

+41
-21
lines changed

10 files changed

+41
-21
lines changed

3rd/yt-dlp/bin/yt-dlp

32 KB
Binary file not shown.

3rd/yt-dlp/bin/yt-dlp.exe

19.5 KB
Binary file not shown.

3rd/yt-dlp/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025.02.19
1+
2025.03.21

src/constants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const std::chrono::milliseconds TIMEOUT_COUNT_DOWN(1000);
3939
const std::chrono::milliseconds TIMEOUT_INFO(150);
4040

4141
const int SELECTION_DISPLAY_LIMIT = 10;
42-
const int MSEC_SPEED_DISPLAY_TIME = 2000;
42+
const int METRICS_TIMEOUT_MSEC = 500;
43+
const int METRICS_LOOP_COUNTER = 4; // 2000 msec (4*500) is enough to read values
4344

4445
const int MSEC_AUTO_SAVE = 3000; ///< Autosave the queue every 3 seconds.
4546

src/core/scheduler.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ Scheduler::Scheduler(QObject *parent) : QObject(parent)
4949
, m_queueModel(new QueueModel(this))
5050
, m_networkManager(new NetworkManager(this))
5151
, m_snapshot(new Snapshot(this))
52-
, m_speedTimer(new QTimer(this))
52+
, m_metricsTimer(new QTimer(this))
5353
{
54-
connect(this, SIGNAL(jobFinished(AbstractJob*)),
55-
this, SLOT(startNext(AbstractJob*)));
54+
connect(this, SIGNAL(jobFinished(AbstractJob*)), this, SLOT(startNext(AbstractJob*)));
5655

57-
connect(m_speedTimer, SIGNAL(timeout()), this, SLOT(onSpeedTimerTimeout()));
56+
connect(m_metricsTimer, SIGNAL(timeout()), this, SLOT(onMetricsTimerTimeout()));
57+
m_metricsTimer->setSingleShot(false);
58+
m_metricsTimer->start(METRICS_TIMEOUT_MSEC);
5859
}
5960

6061
Scheduler::~Scheduler()
@@ -293,24 +294,34 @@ QList<AbstractJob*> Scheduler::runningJobs() const
293294

294295
/******************************************************************************
295296
******************************************************************************/
296-
void Scheduler::onSpeedTimerTimeout()
297+
qreal Scheduler::totalSpeed()
297298
{
298-
m_speedTimer->stop();
299-
m_previouSpeed = 0;
300-
emit onJobChanged();
299+
return m_metricsSpeed;
301300
}
302301

303-
qreal Scheduler::totalSpeed()
302+
void Scheduler::onMetricsTimerTimeout()
304303
{
305304
qreal speed = 0;
306305
for (auto job : jobs()) {
307-
speed += qMax(job->speed(), qreal(0));
306+
speed += qMax(job->speed(), qreal(0)); // speed is negative for pending jobs
308307
}
308+
309309
if (speed > 0) {
310-
m_previouSpeed = speed;
311-
m_speedTimer->start(MSEC_SPEED_DISPLAY_TIME);
310+
m_metricsLoopCount = 0;
311+
} else {
312+
// When speed is 0 (i.e. all jobs are finished), the metrics aren't updated immediatelty.
313+
// Instead, the previous metrics is kept as-is for a couple of seconds,
314+
// to let us read the values, then it's updated.
315+
if (m_metricsLoopCount < METRICS_LOOP_COUNTER) {
316+
m_metricsLoopCount++;
317+
return;
318+
}
319+
}
320+
321+
if (m_metricsSpeed != speed) {
322+
m_metricsSpeed = speed;
323+
emit metricsChanged();
312324
}
313-
return m_previouSpeed;
314325
}
315326

316327
/******************************************************************************

src/core/scheduler.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Scheduler : public QObject, public IScheduler
8080
QAbstractItemModel *model() const;
8181

8282
signals:
83+
void metricsChanged();
8384
void jobFinished(AbstractJob *job);
8485
void jobRenamed(QString oldName, QString newName, bool success);
8586

@@ -93,8 +94,7 @@ private slots:
9394
void startNext(AbstractJob *job);
9495

9596
void onSettingsChanged();
96-
97-
void onSpeedTimerTimeout();
97+
void onMetricsTimerTimeout();
9898

9999
private:
100100
QueueModel *m_queueModel = nullptr;
@@ -104,8 +104,9 @@ private slots:
104104
NetworkManager *m_networkManager = nullptr;
105105
Settings *m_settings = nullptr;
106106

107-
qreal m_previouSpeed = 0;
108-
QTimer* m_speedTimer = nullptr;
107+
QTimer *m_metricsTimer = nullptr;
108+
qreal m_metricsSpeed = 0;
109+
int m_metricsLoopCount = 0;
109110

110111
// Pool
111112
int m_maxSimultaneousDownloads = 4;

src/dialogs/addbatchdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ QList<AbstractJob*> AddBatchDialog::createJobFiles(const QUrl &inputUrl) const
338338
QList<AbstractJob*> items;
339339
const QStringList urls = Regex::interpret(inputUrl);
340340
for (auto url : urls) {
341-
items << createJobFiles(url);
341+
items << createJobFile(url);
342342
}
343343
return items;
344344
}

src/mainwindow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
141141

142142
/* Connect the SceneManager to the MainWindow. */
143143
/* The SceneManager centralizes the changes. */
144+
connect(m_scheduler, SIGNAL(metricsChanged()), this, SLOT(onMetricsChanged()));
144145
connect(m_scheduler, SIGNAL(jobFinished(AbstractJob*)), this, SLOT(onJobFinished(AbstractJob*)));
145146
connect(m_scheduler, SIGNAL(jobRenamed(QString,QString,bool)), this, SLOT(onJobRenamed(QString,QString,bool)), Qt::QueuedConnection);
146147

@@ -924,6 +925,11 @@ void MainWindow::onDataChanged()
924925
m_scheduler->activateSnapshot();
925926
}
926927

928+
void MainWindow::onMetricsChanged()
929+
{
930+
refreshTitleAndStatus();
931+
}
932+
927933
void MainWindow::onJobFinished(AbstractJob *job)
928934
{
929935
refreshMenus();

src/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public slots:
113113

114114
private slots:
115115
void onDataChanged();
116+
void onMetricsChanged();
116117
void onJobFinished(AbstractJob *job);
117118
void onJobRenamed(const QString &oldName, const QString &newName, bool success);
118119
void onSelectionChanged();

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.2.0
1+
4.2.1

0 commit comments

Comments
 (0)