diff --git a/Changelog b/Changelog index da3ac8b8c..447474715 100644 --- a/Changelog +++ b/Changelog @@ -15,6 +15,7 @@ - FEATURE: Torrents can be automatically paused once they reach a given ratio - FEATURE: Several files can now be disabled at once - FEATURE: Added "Select All/None" buttons to files list + - FEATURE: Added support for BitComet links (bc://bt/...) - BUGFIX: Hide seeding torrents files priorities in Web UI - BUGFIX: The user can disable permanently recursive torrent download - BUGFIX: Peer Exchange status is now correctly reported diff --git a/src/GUI.cpp b/src/GUI.cpp index 5be6a4fe3..fb856fe41 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -683,6 +683,10 @@ void GUI::dropEvent(QDropEvent *event) { BTSession->downloadFromUrl(file); continue; } + if(file.startsWith("bc://bt/", Qt::CaseInsensitive)) { + qDebug("Converting bc link to magnet link"); + file = misc::bcLinkToMagnet(file); + } if(file.startsWith("magnet:", Qt::CaseInsensitive)) { // FIXME: Possibly skipped torrent addition dialog BTSession->addMagnetUri(file); @@ -756,6 +760,10 @@ void GUI::processParams(const QStringList& params) { if(param.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) { BTSession->downloadFromUrl(param); }else{ + if(param.startsWith("bc://bt/", Qt::CaseInsensitive)) { + qDebug("Converting bc link to magnet link"); + param = misc::bcLinkToMagnet(param); + } if(param.startsWith("magnet:", Qt::CaseInsensitive)) { if(useTorrentAdditionDialog) { torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession); @@ -938,7 +946,11 @@ void GUI::showNotificationBaloon(QString title, QString msg) const { void GUI::downloadFromURLList(const QStringList& url_list) { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); - foreach(const QString& url, url_list) { + foreach(QString url, url_list) { + if(url.startsWith("bc://bt/", Qt::CaseInsensitive)) { + qDebug("Converting bc link to magnet link"); + url = misc::bcLinkToMagnet(url); + } if(url.startsWith("magnet:", Qt::CaseInsensitive)) { if(useTorrentAdditionDialog) { torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession); diff --git a/src/downloadfromurldlg.h b/src/downloadfromurldlg.h index 436620b71..d08062024 100644 --- a/src/downloadfromurldlg.h +++ b/src/downloadfromurldlg.h @@ -51,7 +51,7 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{ show(); // Paste clipboard if there is an URL in it QString clip_txt = qApp->clipboard()->text(); - if(clip_txt.startsWith("http://", Qt::CaseInsensitive) || clip_txt.startsWith("https://", Qt::CaseInsensitive) || clip_txt.startsWith("ftp://", Qt::CaseInsensitive) || clip_txt.startsWith("magnet:", Qt::CaseInsensitive)) { + if(clip_txt.startsWith("http://", Qt::CaseInsensitive) || clip_txt.startsWith("https://", Qt::CaseInsensitive) || clip_txt.startsWith("ftp://", Qt::CaseInsensitive) || clip_txt.startsWith("magnet:", Qt::CaseInsensitive) || clip_txt.startsWith("bc://bt/", Qt::CaseInsensitive)) { textUrls->setText(clip_txt); } } diff --git a/src/headlessloader.h b/src/headlessloader.h index a8b483414..702d23f07 100644 --- a/src/headlessloader.h +++ b/src/headlessloader.h @@ -89,6 +89,10 @@ public slots: if(param.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) { BTSession->downloadFromUrl(param); }else{ + if(param.startsWith("bc://bt/", Qt::CaseInsensitive)) { + qDebug("Converting bc link to magnet link"); + param = misc::bcLinkToMagnet(param); + } if(param.startsWith("magnet:", Qt::CaseInsensitive)) { BTSession->addMagnetUri(param); } else { diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index 22382ceb0..23b9c4f95 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -333,6 +333,10 @@ void HttpConnection::respondCommand(QString command) foreach(QString url, list){ url = url.trimmed(); if(!url.isEmpty()){ + if(url.startsWith("bc://bt/", Qt::CaseInsensitive)) { + qDebug("Converting bc link to magnet link"); + url = misc::bcLinkToMagnet(url); + } if(url.startsWith("magnet:", Qt::CaseInsensitive)) { emit MagnetReadyToBeDownloaded(url); } else { diff --git a/src/misc.cpp b/src/misc.cpp index 64558b173..48b54b096 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -475,6 +475,20 @@ bool misc::removeEmptyTree(QString path) { return false; } +QString misc::bcLinkToMagnet(QString bc_link) { + QByteArray raw_bc = bc_link.toUtf8(); + raw_bc = raw_bc.mid(8); // skip bc://bt/ + raw_bc = QByteArray::fromBase64(raw_bc); // Decode base64 + // Format is now AA/url_encoded_filename/size_bytes/info_hash/ZZ + QStringList parts = QString(raw_bc).split("/"); + if(parts.size() != 5) return QString::null; + QString filename = parts.at(1); + QString hash = parts.at(3); + QString magnet = "magnet:?xt=urn:btih:" + hash; + magnet += "&dn=" + filename; + return magnet; +} + QString misc::magnetUriToName(QString magnet_uri) { QString name = ""; QRegExp regHex("dn=([^&]+)"); diff --git a/src/misc.h b/src/misc.h index 3bdb08303..0c09bbf1b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -116,6 +116,7 @@ public: static bool removeEmptyTree(QString path); static QString magnetUriToName(QString magnet_uri); static QString magnetUriToHash(QString magnet_uri); + static QString bcLinkToMagnet(QString bc_link); static QString boostTimeToQString(const boost::optional boostDate); // Replace ~ in path static QString expandPath(QString path); diff --git a/src/searchengine.cpp b/src/searchengine.cpp index 118124d4e..e579617bd 100644 --- a/src/searchengine.cpp +++ b/src/searchengine.cpp @@ -403,6 +403,10 @@ void SearchEngine::saveResultsColumnsWidth() { } void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) { + if(torrent_url.startsWith("bc://bt/", Qt::CaseInsensitive)) { + qDebug("Converting bc link to magnet link"); + torrent_url = misc::bcLinkToMagnet(torrent_url); + } if(torrent_url.startsWith("magnet:")) { QStringList urls; urls << torrent_url; diff --git a/src/src.pro b/src/src.pro index 223d3d7fe..a810ba34f 100644 --- a/src/src.pro +++ b/src/src.pro @@ -3,7 +3,7 @@ LANG_PATH = lang ICONS_PATH = Icons # Set the following variable to 1 to enable debug -DEBUG_MODE = 0 +DEBUG_MODE = 1 # Global TEMPLATE = app