FEATURE: Added support for BitComet links (bc://bt/...)

This commit is contained in:
Christophe Dumez 2010-07-22 22:19:42 +00:00
parent 7a2c0d5d5a
commit 3d4c1fe7da
9 changed files with 43 additions and 3 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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=([^&]+)");

View File

@ -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<boost::posix_time::ptime> boostDate);
// Replace ~ in path
static QString expandPath(QString path);

View File

@ -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;

View File

@ -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