diff --git a/src/downloadfromurldlg.h b/src/downloadfromurldlg.h index 4331f7863..736331637 100644 --- a/src/downloadfromurldlg.h +++ b/src/downloadfromurldlg.h @@ -50,9 +50,27 @@ 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) || clip_txt.startsWith("bc://bt/", Qt::CaseInsensitive)) { - textUrls->setText(clip_txt); + QStringList clip_txt_list = clip_txt.split(QString::fromUtf8("\n")); + clip_txt.clear(); + QStringList clip_txt_list_cleaned; + foreach (clip_txt, clip_txt_list) { + clip_txt = clip_txt.trimmed(); + if (!clip_txt.isEmpty()) { + if (clip_txt_list_cleaned.indexOf(QRegExp(clip_txt, Qt::CaseInsensitive, QRegExp::FixedString)) < 0) { + 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) + || (clip_txt.size() == 40 && !clip_txt.contains(QRegExp("[^0-9A-Fa-f]"))) + || (clip_txt.size() == 32 && !clip_txt.contains(QRegExp("[^2-7A-Za-z]")))) { + clip_txt_list_cleaned << clip_txt; + } + } + } } + if (clip_txt_list_cleaned.size() > 0) + textUrls->setText(clip_txt_list_cleaned.join("\n")); } ~downloadFromURL() {} diff --git a/src/downloadfromurldlg.ui b/src/downloadfromurldlg.ui index bb706a0ba..4a6137240 100644 --- a/src/downloadfromurldlg.ui +++ b/src/downloadfromurldlg.ui @@ -52,7 +52,7 @@ - Both HTTP and Magnet links are supported + One per line HTTP links, Magnet links and info-hashes are supported diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dd68f5e9e..49a86cd81 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1182,13 +1182,20 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) { qDebug("Converting bc link to magnet link"); url = misc::bcLinkToMagnet(url); } + if ((url.size() == 40 && !url.contains(QRegExp("[^0-9A-Fa-f]"))) + || (url.size() == 32 && !url.contains(QRegExp("[^2-7A-Za-z]")))) { + url = "magnet:?xt=urn:btih:" + url; + } if (url.startsWith("magnet:", Qt::CaseInsensitive)) { if (useTorrentAdditionDialog) AddNewTorrentDialog::showMagnet(url); else QBtSession::instance()->addMagnetUri(url); - } else + } + else if (url.startsWith("http://", Qt::CaseInsensitive) || startsWith("https://", Qt::CaseInsensitive) + || url.startsWith("ftp://", Qt::CaseInsensitive)) { QBtSession::instance()->downloadFromUrl(url); + } } }