Improve album and title disc, remastered, etc matching
Don't partial remove things like "(Mono / Remastered)". Fixes #1387
This commit is contained in:
@@ -167,9 +167,20 @@ const QString Song::kFtsColumnSpec = Song::kFtsColumns.join(", ");
|
||||
const QString Song::kFtsBindSpec = Utilities::Prepend(":", Song::kFtsColumns).join(", ");
|
||||
const QString Song::kFtsUpdateSpec = Utilities::Updateify(Song::kFtsColumns).join(", ");
|
||||
|
||||
const QRegularExpression Song::kAlbumRemoveDisc(" ?-? ((\\(|\\[)?)(Disc|CD) ?([0-9]{1,2})((\\)|\\])?)$", QRegularExpression::CaseInsensitiveOption);
|
||||
const QRegularExpression Song::kAlbumRemoveMisc(" ?-? ((\\(|\\[)?)(Remastered|([0-9]{1,4}) *Remaster|Explicit) ?((\\)|\\])?)$", QRegularExpression::CaseInsensitiveOption);
|
||||
const QRegularExpression Song::kTitleRemoveMisc(" ?-? ((\\(|\\[)?)(Remastered|Remastered Version|([0-9]{1,4}) *Remaster) ?((\\)|\\])?)$", QRegularExpression::CaseInsensitiveOption);
|
||||
const Song::RegularExpressionList Song::kAlbumDisc = Song::RegularExpressionList()
|
||||
<< QRegularExpression("\\s+-*\\s*(Disc|CD)\\s*([0-9]{1,2})$", QRegularExpression::CaseInsensitiveOption)
|
||||
<< QRegularExpression("\\s+-*\\s*\\(\\s*(Disc|CD)\\s*([0-9]{1,2})\\)$", QRegularExpression::CaseInsensitiveOption)
|
||||
<< QRegularExpression("\\s+-*\\s*\\[\\s*(Disc|CD)\\s*([0-9]{1,2})\\]$", QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
const Song::RegularExpressionList Song::kAlbumMisc = Song::RegularExpressionList()
|
||||
<< QRegularExpression("\\s+-*\\s*(Remastered|([0-9]{1,4})\\s*Remaster|Explicit)\\s*$", QRegularExpression::CaseInsensitiveOption)
|
||||
<< QRegularExpression("\\s+-*\\s*\\(\\s*(Remastered|([0-9]{1,4})\\s*Remaster|Explicit)\\s*\\)\\s*$", QRegularExpression::CaseInsensitiveOption)
|
||||
<< QRegularExpression("\\s+-*\\s*\\[\\s*(Remastered|([0-9]{1,4})\\s*Remaster|Explicit)\\s*\\]\\s*$", QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
const Song::RegularExpressionList Song::kTitleMisc = Song::RegularExpressionList()
|
||||
<< QRegularExpression("\\s+-*\\s*(Remastered|Remastered Version|([0-9]{1,4})\\s*Remaster)\\s*$", QRegularExpression::CaseInsensitiveOption)
|
||||
<< QRegularExpression("\\s+-*\\s*\\(\\s*(Remastered|Remastered Version|([0-9]{1,4})\\s*Remaster)\\s*\\)\\s*$", QRegularExpression::CaseInsensitiveOption)
|
||||
<< QRegularExpression("\\s+-*\\s*\\[\\s*(Remastered|Remastered Version|([0-9]{1,4})\\s*Remaster)\\s*\\]\\s*$", QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
const QStringList Song::kArticles = QStringList() << "the " << "a " << "an ";
|
||||
|
||||
@@ -1843,3 +1854,53 @@ size_t HashSimilar(const Song &song) {
|
||||
// Should compare the same fields as function IsSimilar
|
||||
return qHash(song.title().toLower()) ^ qHash(song.artist().toLower()) ^ qHash(song.album().toLower());
|
||||
}
|
||||
|
||||
bool Song::ContainsRegexList(const QString &str, const RegularExpressionList ®ex_list) {
|
||||
|
||||
for (const QRegularExpression ®ex : regex_list) {
|
||||
if (str.contains(regex)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
QString Song::StripRegexList(QString str, const RegularExpressionList ®ex_list) {
|
||||
|
||||
for (const QRegularExpression ®ex : regex_list) {
|
||||
str = str.remove(regex);
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
bool Song::AlbumContainsDisc(const QString &album) {
|
||||
|
||||
return ContainsRegexList(album, kAlbumDisc);
|
||||
|
||||
}
|
||||
|
||||
QString Song::AlbumRemoveDisc(const QString &album) {
|
||||
|
||||
return StripRegexList(album, kAlbumDisc);
|
||||
|
||||
}
|
||||
|
||||
QString Song::AlbumRemoveMisc(const QString &album) {
|
||||
|
||||
return StripRegexList(album, kAlbumMisc);
|
||||
|
||||
}
|
||||
|
||||
QString Song::AlbumRemoveDiscMisc(const QString &album) {
|
||||
|
||||
return StripRegexList(album, RegularExpressionList() << kAlbumDisc << kAlbumMisc);
|
||||
|
||||
}
|
||||
|
||||
QString Song::TitleRemoveMisc(const QString &title) {
|
||||
|
||||
return StripRegexList(title, kTitleMisc);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user