mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-27 03:39:39 +03:00
Parse URLs in torrent description
This commit is contained in:
parent
6a3d0da4ad
commit
ea04f79e0f
3 changed files with 63 additions and 1 deletions
60
src/misc.cpp
60
src/misc.cpp
|
@ -832,3 +832,63 @@ bool misc::removeEmptyFolder(const QString &dirpath)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString misc::parseHtmlLinks(const QString &raw_text)
|
||||
{
|
||||
QString result = raw_text;
|
||||
QRegExp reURL("(\\s|^)" //start with whitespace or beginning of line
|
||||
"("
|
||||
"(" //case 1 -- URL with scheme
|
||||
"(http(s?))\\://" //start with scheme
|
||||
"([a-zA-Z0-9_-]+\\.)+" // domainpart. at least one of these must exist
|
||||
"([a-zA-Z0-9\\?%=&/_\\.:#;-]+)" // everything to 1st non-URI char, must be at least one char after the previous dot (cannot use ".*" because it can be too greedy)
|
||||
")"
|
||||
"|"
|
||||
"(" //case 2a -- no scheme, contains common TLD example.com
|
||||
"([a-zA-Z0-9_-]+\\.)+" // domainpart. at least one of these must exist
|
||||
"(?=" // must be followed by TLD
|
||||
"AERO|aero|" //N.B. assertions are non-capturing
|
||||
"ARPA|arpa|"
|
||||
"ASIA|asia|"
|
||||
"BIZ|biz|"
|
||||
"CAT|cat|"
|
||||
"COM|com|"
|
||||
"COOP|coop|"
|
||||
"EDU|edu|"
|
||||
"GOV|gov|"
|
||||
"INFO|info|"
|
||||
"INT|int|"
|
||||
"JOBS|jobs|"
|
||||
"MIL|mil|"
|
||||
"MOBI|mobi|"
|
||||
"MUSEUM|museum|"
|
||||
"NAME|name|"
|
||||
"NET|net|"
|
||||
"ORG|org|"
|
||||
"PRO|pro|"
|
||||
"RO|ro|"
|
||||
"RU|ru|"
|
||||
"TEL|tel|"
|
||||
"TRAVEL|travel"
|
||||
")"
|
||||
"([a-zA-Z0-9\\?%=&/_\\.:#;-]+)" // everything to 1st non-URI char, must be at least one char after the previous dot (cannot use ".*" because it can be too greedy)
|
||||
")"
|
||||
"|"
|
||||
"(" // case 2b no scheme, no TLD, must have at least 2 aphanum strings plus uncommon TLD string --> del.icio.us
|
||||
"([a-zA-Z0-9_-]+\\.){2,}" //2 or more domainpart. --> del.icio.
|
||||
"[a-zA-Z]{2,}" //one ab (2 char or longer) --> us
|
||||
"([a-zA-Z0-9\\?%=&/_\\.:#;-]*)" // everything to 1st non-URI char, maybe nothing in case of del.icio.us/path
|
||||
")"
|
||||
")"
|
||||
);
|
||||
|
||||
|
||||
// Capture links
|
||||
result.replace(reURL, "\\1<a href=\"\\2\">\\2</a>");
|
||||
|
||||
// Capture links without scheme
|
||||
QRegExp reNoScheme("<a\\s+href=\"(?!http(s?))([a-zA-Z0-9\\?%=&/_\\.-:#]+)\\s*\">");
|
||||
result.replace(reNoScheme, "<a href=\"http://\\1\">");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -123,6 +123,8 @@ public:
|
|||
return MyFile.remove();
|
||||
}
|
||||
|
||||
static QString parseHtmlLinks(const QString &raw_text);
|
||||
|
||||
static bool removeEmptyFolder(const QString &dirpath);
|
||||
|
||||
static quint64 computePathSize(QString path);
|
||||
|
|
|
@ -263,7 +263,7 @@ void PropertiesWidget::loadTorrentInfos(const QTorrentHandle &_h) {
|
|||
// Pieces size
|
||||
pieceSize_lbl->setText(misc::friendlyUnit(h.piece_length()));
|
||||
// Comment
|
||||
comment_text->setHtml(h.comment());
|
||||
comment_text->setHtml(misc::parseHtmlLinks(h.comment()));
|
||||
// URL seeds
|
||||
loadUrlSeeds();
|
||||
// List files in torrent
|
||||
|
|
Loading…
Reference in a new issue