Improve check for existing podcasts

The feedExists method will now also take query parameters into account.

BUG: 461877
This commit is contained in:
Bart De Vries 2022-11-15 19:13:24 +01:00
parent 7e92b5c280
commit d192784e12
2 changed files with 16 additions and 6 deletions

View File

@ -584,13 +584,10 @@ void DataManager::loadEntry(const QString id) const
bool DataManager::feedExists(const QString &url)
{
// Try to account for some common cases where the URL is different but is
// actually pointing to the same data. Currently covering:
// - http vs https
// - encoded vs non-encoded URLs
QString cleanUrl = QUrl(url).authority() + QUrl(url).path(QUrl::FullyDecoded);
// using cleanUrl to do "fuzzy" check on the podcast URL
QString cleanedUrl = cleanUrl(url);
for (QString listUrl : m_feedmap) {
if (cleanUrl == (QUrl(listUrl).authority() + QUrl(listUrl).path(QUrl::FullyDecoded))) {
if (cleanedUrl == cleanUrl(listUrl)) {
return true;
}
}
@ -722,3 +719,14 @@ QStringList DataManager::getIdsFromModelIndexList(const QModelIndexList &list) c
qCDebug(kastsDataManager) << "Ids of selection:" << ids;
return ids;
}
QString DataManager::cleanUrl(const QString &url)
{
// this is a method to create a "canonical" version of a podcast url which
// would account for some common cases where the URL is different but is
// actually pointing to the same data. Currently covering:
// - http vs https (scheme is actually removed altogether!)
// - encoded vs non-encoded URLs
return QUrl(url).authority() + QUrl(url).path(QUrl::FullyDecoded)
+ (QUrl(url).hasQuery() ? QStringLiteral("?") + QUrl(url).query(QUrl::FullyDecoded) : QStringLiteral(""));
}

View File

@ -102,6 +102,8 @@ private:
void loadEntry(QString id) const;
void updateQueueListnrs() const;
QString cleanUrl(const QString &url);
QStringList getIdsFromModelIndexList(const QModelIndexList &list) const;
mutable QHash<QString, Feed *> m_feeds; // hash of pointers to all feeds in db, key = url (lazy loading)