From a90ed071336371936abb25b6de892c543d3c30cf Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 22 Feb 2025 11:12:42 +0100 Subject: Improve Metadata parsing Check the filename for the common pattern . If found, parse it and apply the result to the appropriate widgets. --- movieinfopage.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'movieinfopage.cpp') diff --git a/movieinfopage.cpp b/movieinfopage.cpp index ae77d00..4b02b05 100644 --- a/movieinfopage.cpp +++ b/movieinfopage.cpp @@ -232,10 +232,31 @@ void MovieInfoPage::extractMetadata(){ fn.replace(".mkv", ""); fn.replace(".mp4", ""); fn.replace(".", " "); - mSubtitle->setText(fn); + if(!extractFromTitle(fn)){ + mSubtitle->setText(fn); + } + } + } +} +bool MovieInfoPage::extractFromTitle(const QString &title){ + QString curTitle = title; + static QRegularExpression removals("\\(4[kK]\\)"); + static QRegularExpression titleRe("^(.*)?\\s?-\\s?(.*?)\\s+\\((\\d{4}-\\d{2}-\\d{2})\\)"); + curTitle = curTitle.replace(removals, ""); + QRegularExpressionMatch titleMatch = titleRe.match(curTitle); + if(titleMatch.hasMatch()){ + QString subtitle = titleMatch.captured(2).simplified().toLower(); + QDate created = QDate::fromString(titleMatch.captured(3), Qt::ISODate); + QStringList actors = titleMatch.captured(1).split('&'); + for(const auto &a : std::as_const(actors)){ + mPossbileActors.append(a.simplified().toLower()); } + mSubtitle->setText(subtitle); + mCreationDate->setDate(created); + return true; } + return false; } void MovieInfoPage::addOld(){ -- cgit v1.2.3-70-g09d2