mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 04:54:18 +00:00
Improved ETA calculation
This commit is contained in:
parent
611b9424ee
commit
9bde00b7de
@ -21,14 +21,13 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QTimer>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "bittorrent.h"
|
#include "bittorrent.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "downloadThread.h"
|
#include "downloadThread.h"
|
||||||
|
|
||||||
#define ETAS_MAX_VALUES 5
|
#define ETAS_MAX_VALUES 8
|
||||||
|
|
||||||
// Main constructor
|
// Main constructor
|
||||||
bittorrent::bittorrent(){
|
bittorrent::bittorrent(){
|
||||||
@ -45,9 +44,10 @@ bittorrent::bittorrent(){
|
|||||||
DHTEnabled = false;
|
DHTEnabled = false;
|
||||||
// Enabling metadata plugin
|
// Enabling metadata plugin
|
||||||
s->add_extension(&create_metadata_plugin);
|
s->add_extension(&create_metadata_plugin);
|
||||||
timerAlerts = new QTimer(this);
|
connect(&timerAlerts, SIGNAL(timeout()), this, SLOT(readAlerts()));
|
||||||
connect(timerAlerts, SIGNAL(timeout()), this, SLOT(readAlerts()));
|
timerAlerts.start(3000);
|
||||||
timerAlerts->start(3000);
|
connect(&ETARefresher, SIGNAL(timeout()), this, SLOT(updateETAs()));
|
||||||
|
ETARefresher.start(6000);
|
||||||
// To download from urls
|
// To download from urls
|
||||||
downloader = new downloadThread(this);
|
downloader = new downloadThread(this);
|
||||||
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&)));
|
connect(downloader, SIGNAL(downloadFinished(const QString&, const QString&, int, const QString&)), this, SLOT(processDownloadedFile(const QString&, const QString&, int, const QString&)));
|
||||||
@ -56,7 +56,6 @@ bittorrent::bittorrent(){
|
|||||||
// Main destructor
|
// Main destructor
|
||||||
bittorrent::~bittorrent(){
|
bittorrent::~bittorrent(){
|
||||||
disableDirectoryScanning();
|
disableDirectoryScanning();
|
||||||
delete timerAlerts;
|
|
||||||
delete downloader;
|
delete downloader;
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
@ -74,20 +73,19 @@ void bittorrent::updateETAs(){
|
|||||||
QString hash = QString(misc::toString(h.info_hash()).c_str());
|
QString hash = QString(misc::toString(h.info_hash()).c_str());
|
||||||
QList<long> listEtas = ETAstats.value(hash, QList<long>());
|
QList<long> listEtas = ETAstats.value(hash, QList<long>());
|
||||||
if(listEtas.size() == ETAS_MAX_VALUES){
|
if(listEtas.size() == ETAS_MAX_VALUES){
|
||||||
|
listEtas.removeFirst();
|
||||||
|
}
|
||||||
|
torrent_status torrentStatus = h.status();
|
||||||
|
torrent_info ti = h.get_torrent_info();
|
||||||
|
if(torrentStatus.download_payload_rate != 0){
|
||||||
|
listEtas << (long)((ti.total_size()-torrentStatus.total_done)/(double)torrentStatus.download_payload_rate);
|
||||||
|
ETAstats[hash] = listEtas;
|
||||||
long moy = 0;
|
long moy = 0;
|
||||||
long val;
|
long val;
|
||||||
foreach(val, listEtas){
|
foreach(val, listEtas){
|
||||||
moy += val;
|
moy += val;
|
||||||
}
|
}
|
||||||
ETAs[hash] = (long) ((double)moy/(double)ETAS_MAX_VALUES);
|
ETAs[hash] = (long) ((double)moy/(double)listEtas.size());
|
||||||
ETAstats[hash] = QList<long>();
|
|
||||||
}else{
|
|
||||||
torrent_status torrentStatus = h.status();
|
|
||||||
torrent_info ti = h.get_torrent_info();
|
|
||||||
if(torrentStatus.download_payload_rate != 0){
|
|
||||||
listEtas << (long)((ti.total_size()-torrentStatus.total_done)/(double)torrentStatus.download_payload_rate);
|
|
||||||
ETAstats[hash] = listEtas;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -710,8 +708,6 @@ void bittorrent::readAlerts(){
|
|||||||
}
|
}
|
||||||
a = s->pop_alert();
|
a = s->pop_alert();
|
||||||
}
|
}
|
||||||
// ETAs
|
|
||||||
updateETAs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bittorrent::reloadTorrent(const torrent_handle &h, bool compact_mode){
|
void bittorrent::reloadTorrent(const torrent_handle &h, bool compact_mode){
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define __BITTORRENT_H__
|
#define __BITTORRENT_H__
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <libtorrent/entry.hpp>
|
#include <libtorrent/entry.hpp>
|
||||||
#include <libtorrent/bencode.hpp>
|
#include <libtorrent/bencode.hpp>
|
||||||
@ -40,9 +41,6 @@
|
|||||||
|
|
||||||
#include "deleteThread.h"
|
#include "deleteThread.h"
|
||||||
|
|
||||||
class QTimer;
|
|
||||||
class QString;
|
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
class downloadThread;
|
class downloadThread;
|
||||||
@ -55,7 +53,7 @@ class bittorrent : public QObject{
|
|||||||
bool DHTEnabled;
|
bool DHTEnabled;
|
||||||
QString scan_dir;
|
QString scan_dir;
|
||||||
QTimer *timerScan;
|
QTimer *timerScan;
|
||||||
QTimer *timerAlerts;
|
QTimer timerAlerts;
|
||||||
downloadThread *downloader;
|
downloadThread *downloader;
|
||||||
QStringList supported_preview_extensions;
|
QStringList supported_preview_extensions;
|
||||||
QString defaultSavePath;
|
QString defaultSavePath;
|
||||||
@ -63,6 +61,7 @@ class bittorrent : public QObject{
|
|||||||
QStringList torrentsUnchecked;
|
QStringList torrentsUnchecked;
|
||||||
QHash<QString, QList<long> > ETAstats;
|
QHash<QString, QList<long> > ETAstats;
|
||||||
QHash<QString, long> ETAs;
|
QHash<QString, long> ETAs;
|
||||||
|
QTimer ETARefresher;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString getSavePath(const QString& hash);
|
QString getSavePath(const QString& hash);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user