Skip to content

Commit

Permalink
FEATURE: Added support for BitComet links (bc://bt/...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Dumez committed Jul 22, 2010
1 parent 7a2c0d5 commit 3d4c1fe
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/GUI.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/downloadfromurldlg.h
Expand Up @@ -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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/headlessloader.h
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/httpconnection.cpp
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions src/misc.cpp
Expand Up @@ -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=([^&]+)");
Expand Down
1 change: 1 addition & 0 deletions src/misc.h
Expand Up @@ -116,6 +116,7 @@ class misc : public QObject{
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<boost::posix_time::ptime> boostDate);
// Replace ~ in path
static QString expandPath(QString path);
Expand Down
4 changes: 4 additions & 0 deletions src/searchengine.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -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
Expand Down

0 comments on commit 3d4c1fe

Please sign in to comment.