Browse Source

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

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
3d4c1fe7da
  1. 1
      Changelog
  2. 14
      src/GUI.cpp
  3. 2
      src/downloadfromurldlg.h
  4. 4
      src/headlessloader.h
  5. 4
      src/httpconnection.cpp
  6. 14
      src/misc.cpp
  7. 1
      src/misc.h
  8. 4
      src/searchengine.cpp
  9. 2
      src/src.pro

1
Changelog

@ -15,6 +15,7 @@ @@ -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

14
src/GUI.cpp

@ -683,6 +683,10 @@ void GUI::dropEvent(QDropEvent *event) { @@ -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) { @@ -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 { @@ -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);

2
src/downloadfromurldlg.h

@ -51,7 +51,7 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{ @@ -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);
}
}

4
src/headlessloader.h

@ -89,6 +89,10 @@ public slots: @@ -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 {

4
src/httpconnection.cpp

@ -333,6 +333,10 @@ void HttpConnection::respondCommand(QString command) @@ -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 {

14
src/misc.cpp

@ -475,6 +475,20 @@ bool misc::removeEmptyTree(QString path) { @@ -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=([^&]+)");

1
src/misc.h

@ -116,6 +116,7 @@ public: @@ -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);

4
src/searchengine.cpp

@ -403,6 +403,10 @@ void SearchEngine::saveResultsColumnsWidth() { @@ -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;

2
src/src.pro

@ -3,7 +3,7 @@ LANG_PATH = lang @@ -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

Loading…
Cancel
Save