mirror of
https://github.com/qbittorrent/qBittorrent
synced 2024-09-26 07:32:23 +02:00
Add date column to the built-in search engine
Adds a date column to the built-in search engine to show when a torrent was published/uploaded on the engine site. When a plugin wants to show a date, it can now add a `pub_date` entry to its result dict. The value format is a unix timestamp (an integer representing seconds since epoch). Plugins with no date support will keep working. PR #20703.
This commit is contained in:
parent
775b38079f
commit
42b87963fd
@ -55,6 +55,7 @@ namespace
|
|||||||
PL_LEECHS,
|
PL_LEECHS,
|
||||||
PL_ENGINE_URL,
|
PL_ENGINE_URL,
|
||||||
PL_DESC_LINK,
|
PL_DESC_LINK,
|
||||||
|
PL_PUB_DATE,
|
||||||
NB_PLUGIN_COLUMNS
|
NB_PLUGIN_COLUMNS
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -176,7 +177,7 @@ bool SearchHandler::parseSearchResult(const QStringView line, SearchResult &sear
|
|||||||
const QList<QStringView> parts = line.split(u'|');
|
const QList<QStringView> parts = line.split(u'|');
|
||||||
const int nbFields = parts.size();
|
const int nbFields = parts.size();
|
||||||
|
|
||||||
if (nbFields < (NB_PLUGIN_COLUMNS - 1)) return false; // -1 because desc_link is optional
|
if (nbFields <= PL_ENGINE_URL) return false; // Anything after ENGINE_URL is optional
|
||||||
|
|
||||||
searchResult = SearchResult();
|
searchResult = SearchResult();
|
||||||
searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed().toString(); // download URL
|
searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed().toString(); // download URL
|
||||||
@ -194,9 +195,17 @@ bool SearchHandler::parseSearchResult(const QStringView line, SearchResult &sear
|
|||||||
searchResult.nbLeechers = -1;
|
searchResult.nbLeechers = -1;
|
||||||
|
|
||||||
searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed().toString(); // Search site URL
|
searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed().toString(); // Search site URL
|
||||||
if (nbFields == NB_PLUGIN_COLUMNS)
|
|
||||||
|
if (nbFields > PL_DESC_LINK)
|
||||||
searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed().toString(); // Description Link
|
searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed().toString(); // Description Link
|
||||||
|
|
||||||
|
if (nbFields > PL_PUB_DATE)
|
||||||
|
{
|
||||||
|
const qint64 secs = parts.at(PL_PUB_DATE).trimmed().toLongLong(&ok);
|
||||||
|
if (ok && (secs > 0))
|
||||||
|
searchResult.pubDate = QDateTime::fromSecsSinceEpoch(secs); // Date
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -47,6 +48,7 @@ struct SearchResult
|
|||||||
qlonglong nbLeechers = 0;
|
qlonglong nbLeechers = 0;
|
||||||
QString siteUrl;
|
QString siteUrl;
|
||||||
QString descrLink;
|
QString descrLink;
|
||||||
|
QDateTime pubDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SearchPluginManager;
|
class SearchPluginManager;
|
||||||
|
@ -71,6 +71,7 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, IGUIApplication *
|
|||||||
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
|
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
|
||||||
m_searchListModel->setHeaderData(SearchSortModel::LEECHES, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
|
m_searchListModel->setHeaderData(SearchSortModel::LEECHES, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
|
||||||
m_searchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine"));
|
m_searchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine"));
|
||||||
|
m_searchListModel->setHeaderData(SearchSortModel::PUB_DATE, Qt::Horizontal, tr("Published On"));
|
||||||
// Set columns text alignment
|
// Set columns text alignment
|
||||||
m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
||||||
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
||||||
@ -533,6 +534,7 @@ void SearchJobWidget::appendSearchResults(const QVector<SearchResult> &results)
|
|||||||
setModelData(SearchSortModel::SIZE, Utils::Misc::friendlyUnit(result.fileSize), result.fileSize, (Qt::AlignRight | Qt::AlignVCenter));
|
setModelData(SearchSortModel::SIZE, Utils::Misc::friendlyUnit(result.fileSize), result.fileSize, (Qt::AlignRight | Qt::AlignVCenter));
|
||||||
setModelData(SearchSortModel::SEEDS, QString::number(result.nbSeeders), result.nbSeeders, (Qt::AlignRight | Qt::AlignVCenter));
|
setModelData(SearchSortModel::SEEDS, QString::number(result.nbSeeders), result.nbSeeders, (Qt::AlignRight | Qt::AlignVCenter));
|
||||||
setModelData(SearchSortModel::LEECHES, QString::number(result.nbLeechers), result.nbLeechers, (Qt::AlignRight | Qt::AlignVCenter));
|
setModelData(SearchSortModel::LEECHES, QString::number(result.nbLeechers), result.nbLeechers, (Qt::AlignRight | Qt::AlignVCenter));
|
||||||
|
setModelData(SearchSortModel::PUB_DATE, QLocale().toString(result.pubDate.toLocalTime(), QLocale::ShortFormat), result.pubDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResultsCount();
|
updateResultsCount();
|
||||||
|
@ -45,6 +45,7 @@ public:
|
|||||||
SEEDS,
|
SEEDS,
|
||||||
LEECHES,
|
LEECHES,
|
||||||
ENGINE_URL,
|
ENGINE_URL,
|
||||||
|
PUB_DATE,
|
||||||
DL_LINK,
|
DL_LINK,
|
||||||
DESC_LINK,
|
DESC_LINK,
|
||||||
NB_SEARCH_COLUMNS
|
NB_SEARCH_COLUMNS
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#VERSION: 1.47
|
#VERSION: 1.48
|
||||||
|
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions are met:
|
# modification, are permitted provided that the following conditions are met:
|
||||||
@ -26,12 +26,16 @@
|
|||||||
|
|
||||||
|
|
||||||
def prettyPrinter(dictionary):
|
def prettyPrinter(dictionary):
|
||||||
dictionary['size'] = anySizeToBytes(dictionary['size'])
|
outtext = "|".join((
|
||||||
outtext = "|".join((dictionary["link"], dictionary["name"].replace("|", " "),
|
dictionary["link"],
|
||||||
str(dictionary["size"]), str(dictionary["seeds"]),
|
dictionary["name"].replace("|", " "),
|
||||||
str(dictionary["leech"]), dictionary["engine_url"]))
|
str(anySizeToBytes(dictionary['size'])),
|
||||||
if 'desc_link' in dictionary:
|
str(dictionary["seeds"]),
|
||||||
outtext = "|".join((outtext, dictionary["desc_link"]))
|
str(dictionary["leech"]),
|
||||||
|
dictionary["engine_url"],
|
||||||
|
dictionary.get("desc_link", ""), # Optional
|
||||||
|
str(dictionary.get("pub_date", -1)), # Optional
|
||||||
|
))
|
||||||
|
|
||||||
# fd 1 is stdout
|
# fd 1 is stdout
|
||||||
with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
|
with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/search/searchhandler.h"
|
#include "base/search/searchhandler.h"
|
||||||
|
#include "base/utils/datetime.h"
|
||||||
#include "base/utils/foreignapps.h"
|
#include "base/utils/foreignapps.h"
|
||||||
#include "base/utils/random.h"
|
#include "base/utils/random.h"
|
||||||
#include "base/utils/string.h"
|
#include "base/utils/string.h"
|
||||||
@ -301,6 +302,7 @@ int SearchController::generateSearchId() const
|
|||||||
* - "nbLeechers"
|
* - "nbLeechers"
|
||||||
* - "siteUrl"
|
* - "siteUrl"
|
||||||
* - "descrLink"
|
* - "descrLink"
|
||||||
|
* - "pubDate"
|
||||||
*/
|
*/
|
||||||
QJsonObject SearchController::getResults(const QList<SearchResult> &searchResults, const bool isSearchActive, const int totalResults) const
|
QJsonObject SearchController::getResults(const QList<SearchResult> &searchResults, const bool isSearchActive, const int totalResults) const
|
||||||
{
|
{
|
||||||
@ -315,7 +317,8 @@ QJsonObject SearchController::getResults(const QList<SearchResult> &searchResult
|
|||||||
{u"nbSeeders"_s, searchResult.nbSeeders},
|
{u"nbSeeders"_s, searchResult.nbSeeders},
|
||||||
{u"nbLeechers"_s, searchResult.nbLeechers},
|
{u"nbLeechers"_s, searchResult.nbLeechers},
|
||||||
{u"siteUrl"_s, searchResult.siteUrl},
|
{u"siteUrl"_s, searchResult.siteUrl},
|
||||||
{u"descrLink"_s, searchResult.descrLink}
|
{u"descrLink"_s, searchResult.descrLink},
|
||||||
|
{u"pubDate"_s, Utils::DateTime::toSecsSinceEpoch(searchResult.pubDate)}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1685,6 +1685,7 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
this.newColumn('nbSeeders', '', 'QBT_TR(Seeders)QBT_TR[CONTEXT=SearchResultsTable]', 100, true);
|
this.newColumn('nbSeeders', '', 'QBT_TR(Seeders)QBT_TR[CONTEXT=SearchResultsTable]', 100, true);
|
||||||
this.newColumn('nbLeechers', '', 'QBT_TR(Leechers)QBT_TR[CONTEXT=SearchResultsTable]', 100, true);
|
this.newColumn('nbLeechers', '', 'QBT_TR(Leechers)QBT_TR[CONTEXT=SearchResultsTable]', 100, true);
|
||||||
this.newColumn('siteUrl', '', 'QBT_TR(Search engine)QBT_TR[CONTEXT=SearchResultsTable]', 250, true);
|
this.newColumn('siteUrl', '', 'QBT_TR(Search engine)QBT_TR[CONTEXT=SearchResultsTable]', 250, true);
|
||||||
|
this.newColumn('pubDate', '', 'QBT_TR(Published On)QBT_TR[CONTEXT=SearchResultsTable]', 200, true);
|
||||||
|
|
||||||
this.initColumnsFunctions();
|
this.initColumnsFunctions();
|
||||||
},
|
},
|
||||||
@ -1701,10 +1702,17 @@ window.qBittorrent.DynamicTable = (function() {
|
|||||||
td.set('text', formattedValue);
|
td.set('text', formattedValue);
|
||||||
td.set('title', formattedValue);
|
td.set('title', formattedValue);
|
||||||
};
|
};
|
||||||
|
const displayDate = function(td, row) {
|
||||||
|
const value = this.getRowValue(row) * 1000;
|
||||||
|
const formattedValue = (isNaN(value) || (value <= 0)) ? "" : (new Date(value).toLocaleString());
|
||||||
|
td.set('text', formattedValue);
|
||||||
|
td.set('title', formattedValue);
|
||||||
|
};
|
||||||
|
|
||||||
this.columns['fileSize'].updateTd = displaySize;
|
this.columns['fileSize'].updateTd = displaySize;
|
||||||
this.columns['nbSeeders'].updateTd = displayNum;
|
this.columns['nbSeeders'].updateTd = displayNum;
|
||||||
this.columns['nbLeechers'].updateTd = displayNum;
|
this.columns['nbLeechers'].updateTd = displayNum;
|
||||||
|
this.columns['pubDate'].updateTd = displayDate;
|
||||||
},
|
},
|
||||||
|
|
||||||
getFilteredAndSortedRows: function() {
|
getFilteredAndSortedRows: function() {
|
||||||
|
@ -988,6 +988,7 @@
|
|||||||
nbLeechers: result.nbLeechers,
|
nbLeechers: result.nbLeechers,
|
||||||
nbSeeders: result.nbSeeders,
|
nbSeeders: result.nbSeeders,
|
||||||
siteUrl: result.siteUrl,
|
siteUrl: result.siteUrl,
|
||||||
|
pubDate: result.pubDate,
|
||||||
};
|
};
|
||||||
|
|
||||||
newRows.push(row);
|
newRows.push(row);
|
||||||
|
Loading…
Reference in New Issue
Block a user