mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 04:54:18 +00:00
Check for magnet links in watched folders.
Look for files ending with ".magnet" and interpret their contents as a magnet link. This allows scripts to collect magnet links from the web and let qBittorrent download them non-interactively.
This commit is contained in:
parent
acd4b64a8b
commit
55a6bc3855
@ -22,6 +22,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "fs_utils.h"
|
#include "fs_utils.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
#ifndef CIFS_MAGIC_NUMBER
|
#ifndef CIFS_MAGIC_NUMBER
|
||||||
#define CIFS_MAGIC_NUMBER 0xFF534D42
|
#define CIFS_MAGIC_NUMBER 0xFF534D42
|
||||||
@ -118,7 +119,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
FileSystemWatcher(QObject *parent): QFileSystemWatcher(parent) {
|
FileSystemWatcher(QObject *parent): QFileSystemWatcher(parent) {
|
||||||
m_filters << "*.torrent";
|
m_filters << "*.torrent" << "*.magnet";
|
||||||
connect(this, SIGNAL(directoryChanged(QString)), this, SLOT(scanLocalFolder(QString)));
|
connect(this, SIGNAL(directoryChanged(QString)), this, SLOT(scanLocalFolder(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +272,13 @@ private:
|
|||||||
const QStringList files = dir.entryList(m_filters, QDir::Files, QDir::Unsorted);
|
const QStringList files = dir.entryList(m_filters, QDir::Files, QDir::Unsorted);
|
||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
const QString file_abspath = dir.absoluteFilePath(file);
|
const QString file_abspath = dir.absoluteFilePath(file);
|
||||||
if (fsutils::isValidTorrentFile(file_abspath)) {
|
if (file_abspath.endsWith(".magnet")) {
|
||||||
|
QFile f(file_abspath);
|
||||||
|
if (f.open(QIODevice::ReadOnly)
|
||||||
|
&& !misc::magnetUriToHash(QString::fromLocal8Bit(f.readAll())).isEmpty()) {
|
||||||
|
torrents << file_abspath;
|
||||||
|
}
|
||||||
|
} else if (fsutils::isValidTorrentFile(file_abspath)) {
|
||||||
torrents << file_abspath;
|
torrents << file_abspath;
|
||||||
} else {
|
} else {
|
||||||
if (!m_partialTorrents.contains(file_abspath)) {
|
if (!m_partialTorrents.contains(file_abspath)) {
|
||||||
|
@ -924,7 +924,7 @@ void QBtSession::loadTorrentSettings(QTorrentHandle& h) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed) {
|
QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool fromScanDir, const QString &filePath) {
|
||||||
Preferences pref;
|
Preferences pref;
|
||||||
QTorrentHandle h;
|
QTorrentHandle h;
|
||||||
const QString hash(misc::magnetUriToHash(magnet_uri));
|
const QString hash(misc::magnetUriToHash(magnet_uri));
|
||||||
@ -952,7 +952,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed) {
|
|||||||
add_torrent_params p = initializeAddTorrentParams(hash);
|
add_torrent_params p = initializeAddTorrentParams(hash);
|
||||||
|
|
||||||
// Get save path
|
// Get save path
|
||||||
const QString savePath(getSavePath(hash, false));
|
const QString savePath(getSavePath(hash, fromScanDir, filePath));
|
||||||
if (!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash) && resumed) {
|
if (!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash) && resumed) {
|
||||||
qDebug("addMagnetURI: Temp folder is enabled.");
|
qDebug("addMagnetURI: Temp folder is enabled.");
|
||||||
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
|
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
|
||||||
@ -1742,6 +1742,17 @@ bool QBtSession::isFilePreviewPossible(const QString &hash) const {
|
|||||||
void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) {
|
void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) {
|
||||||
foreach (const QString &file, pathList) {
|
foreach (const QString &file, pathList) {
|
||||||
qDebug("File %s added", qPrintable(file));
|
qDebug("File %s added", qPrintable(file));
|
||||||
|
if (file.endsWith(".magnet")) {
|
||||||
|
QFile f(file);
|
||||||
|
if (!f.open(QIODevice::ReadOnly)) {
|
||||||
|
qDebug("Failed to open magnet file: %s", qPrintable(f.errorString()));
|
||||||
|
} else {
|
||||||
|
const QString link = QString::fromLocal8Bit(f.readAll());
|
||||||
|
addMagnetUri(link, false, true, file);
|
||||||
|
f.remove();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
torrent_info t(file.toUtf8().constData());
|
torrent_info t(file.toUtf8().constData());
|
||||||
if (t.is_valid())
|
if (t.is_valid())
|
||||||
|
@ -105,7 +105,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
||||||
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false, bool fromScanDir=false, const QString &filePath=QString());
|
||||||
void loadSessionState();
|
void loadSessionState();
|
||||||
void saveSessionState();
|
void saveSessionState();
|
||||||
void downloadFromUrl(const QString &url, const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
|
void downloadFromUrl(const QString &url, const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user