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:
Christian Kandeler
2012-05-28 14:21:09 +02:00
committed by Christophe Dumez
parent acd4b64a8b
commit 55a6bc3855
3 changed files with 23 additions and 5 deletions

View File

@@ -22,6 +22,7 @@
#endif
#include "fs_utils.h"
#include "misc.h"
#ifndef CIFS_MAGIC_NUMBER
#define CIFS_MAGIC_NUMBER 0xFF534D42
@@ -118,7 +119,7 @@ private:
public:
FileSystemWatcher(QObject *parent): QFileSystemWatcher(parent) {
m_filters << "*.torrent";
m_filters << "*.torrent" << "*.magnet";
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);
foreach (const QString &file, files) {
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;
} else {
if (!m_partialTorrents.contains(file_abspath)) {