Skip to content

Commit

Permalink
config switch ignoreYearInFilename added
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemba committed Dec 7, 2024
1 parent 427b3a8 commit ea4dc4a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
;onlyMissing="false"
;innerBracketsReplace="] ["
;innerParenthesesReplace=") ("
;ignoreYearInFilename="false"

; The following is an example of configs that only affect the 'snes' platform.
;[snes]
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ humans](https://keepachangelog.com).
- Added: Option to retain disc numbering from game filename, when no other
bracket information is requested. See
[`keepDiscInfo`](CONFIGINI.md#keepdiscinfo) for details. Thanks, @maxexcloo!
- Added: Option to override year comparison during scraping, if year is present
in game filename. See
[`ignoreYearInFilename`](CONFIGINI.md#ignoreyearinfilename).
- Added: [Platform 'Fujitsu
FM-Towns'](https://github.com/Gemba/skyscraper/pull/95/files). Manually update
your `peas.json` and `platformid_map.csv` to make use of it.
Expand Down
23 changes: 23 additions & 0 deletions docs/CONFIGINI.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ This is an alphabetical index of all configuration options including the section
| [gameListFolder](CONFIGINI.md#gamelistfolder) | Y | Y | Y | |
| [gameListVariants](CONFIGINI.md#gamelistvariants) | | | Y | |
| [hints](CONFIGINI.md#hints) | Y | | | |
| [ignoreYearInFilename](CONFIGINI.md#ignoreyearinfilename) | Y | Y | | |
| [importFolder](CONFIGINI.md#importfolder) | Y | Y | | |
| [includeFrom](CONFIGINI.md#includefrom) | Y | Y | | |
| [includePattern](CONFIGINI.md#includepattern) | Y | Y | Y | |
Expand Down Expand Up @@ -1066,3 +1067,25 @@ gameListVariants="enable-manuals"

Default value: unset
Allowed in sections: Only for frontend `[emulationstation]`

---

#### ignoreYearInFilename

During scraping, if and only if a year information is identified in parentheses
in the ROM filename, this information is compared against the release year in
the scraper database. If the years are different the game information from the
scraper database is discarded. If no year information is in the ROM filename any
match for the game from the scraper is accepted. To allow a less strict
comparision without having to remove or adjust the year information from the
filename, you can set this option to true.

**Example(s)**

Filename: `Statix (1995)(Black Legend)[h TRSi - HLM].zip`
Release year from scrape source: 1994
`ignoreYearInFilename=true`: Scraper match is accepted
`ignoreYearInFilename=false`: Scraper match is discarded, may end up in result _Game 'Statix (1995)(Black Legend)[h TRSi - HLM]' not found :(_

Default value: `false`
Allowed in sections: `[main]`, `[<PLATFORM>]`
29 changes: 19 additions & 10 deletions src/scraperworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,19 @@ void ScraperWorker::run() {
game.found = false;
} else {
int compareYear = UNDEF_YEAR;
QString baseParNotes =
NameTools::getParNotes(info.completeBaseName());
// If baseParNotes matches (NNNN), compareYear = NNNN
QRegularExpressionMatch match =
QRegularExpression("\\((\\d{4})\\)").match(baseParNotes);
if (match.hasMatch()) {
QString yyyy = match.captured(1);
compareYear = yyyy.toInt();
if (!config.ignoreYearInFilename) {
QString baseParNotes =
NameTools::getParNotes(info.completeBaseName());
// If baseParNotes matches (NNNN), compareYear = NNNN
QRegularExpressionMatch match =
QRegularExpression("\\((\\d{4})\\)").match(baseParNotes);
if (match.hasMatch()) {
QString yyyy = match.captured(1);
compareYear = yyyy.toInt();
}
}
game = getBestEntry(gameEntries, compareTitle, compareYear,
lowestDistance);
lowestDistance, debug);
if (config.interactive && !fromCache) {
game = getEntryFromUser(gameEntries, game, compareTitle,
lowestDistance);
Expand Down Expand Up @@ -576,19 +578,25 @@ unsigned int ScraperWorker::editDistance(const std::string &s1,

GameEntry ScraperWorker::getBestEntry(const QList<GameEntry> &gameEntries,
QString compareTitle, int compareYear,
int &lowestDistance) {
int &lowestDistance, QString &debug) {
GameEntry game;

// If scraper provides only one match, always return that match unless we're
// comparing years.
int releaseYear = UNDEF_YEAR;
QString debugMsg = "Match was discarded as ROM file name contains (%1) "
"and scrape data contains %2 as release year. No "
"match. See config option ignoreYearInFilename, or "
"remove/adjust year from ROM filename to rectify.\n";
if (scraper->getType() == scraper->MatchType::MATCH_ONE) {
GameEntry entry = gameEntries.first();
releaseYear = getReleaseYear(entry.releaseDate);
// compare year specified in title like "(NNNN)"
if (compareYear != UNDEF_YEAR && releaseYear != UNDEF_YEAR &&
compareYear != releaseYear) {
// If year was specified, and doesn't match, return empty game.
debug.append(debugMsg.arg(compareYear).arg(releaseYear));
game.found = false;
return game;
}
lowestDistance = 0;
Expand Down Expand Up @@ -626,6 +634,7 @@ GameEntry ScraperWorker::getBestEntry(const QList<GameEntry> &gameEntries,
// If year was specified, and doesn't match, skip.
if (compareYear != UNDEF_YEAR && releaseYear != UNDEF_YEAR &&
compareYear != releaseYear) {
debug.append(debugMsg.arg(compareYear).arg(releaseYear));
continue;
}
if (config.scraper != "openretro") {
Expand Down
2 changes: 1 addition & 1 deletion src/scraperworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ScraperWorker : public QObject {

GameEntry getBestEntry(const QList<GameEntry> &gameEntries,
QString compareTitle, int compareYear,
int &lowestDistance);
int &lowestDistance, QString &debug);
GameEntry getEntryFromUser(const QList<GameEntry> &gameEntries,
const GameEntry &suggestedGame,
const QString &compareTitle,
Expand Down
4 changes: 4 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ void RuntimeCfg::applyConfigIni(CfgType type, QSettings *settings,
config->interactive = v;
continue;
}
if (k == "ignoreYearInFilename") {
config->ignoreYearInFilename = v;
continue;
}
if (k == "keepDiscInfo") {
config->keepDiscInfo = v;
continue;
Expand Down
6 changes: 4 additions & 2 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct Settings {
int maxFails = 42;
bool skipped = false;
bool tidyDesc = true;
bool ignoreYearInFilename = false;
QString artworkConfig = "";
QByteArray artworkXml = "";
QString excludePattern = "";
Expand Down Expand Up @@ -210,14 +211,15 @@ class RuntimeCfg : public QObject {
{"gameListFolder", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM | CfgType::FRONTEND )},
{"gameListVariants", QPair<QString, int>("str", CfgType::FRONTEND )},
{"hints", QPair<QString, int>("bool", CfgType::MAIN )},
{"ignoreYearInFilename", QPair<QString, int>("bool", CfgType::MAIN | CfgType::PLATFORM )},
{"importFolder", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM )},
{"includeFrom", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM )},
{"includePattern", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM | CfgType::FRONTEND )},
{"inputFolder", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM )},
{"innerBracketsReplace", QPair<QString, int>("str", CfgType::MAIN )},
{"innerParenthesesReplace", QPair<QString, int>("str", CfgType::MAIN )},
{"inputFolder", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM )},
{"interactive", QPair<QString, int>("bool", CfgType::MAIN | CfgType::PLATFORM | CfgType::SCRAPER )},
{"jpgQuality", QPair<QString, int>("int", CfgType::MAIN | CfgType::PLATFORM | CfgType::SCRAPER )},
{"jpgQuality", QPair<QString, int>("int", CfgType::MAIN | CfgType::PLATFORM | CfgType::SCRAPER )},
{"keepDiscInfo", QPair<QString, int>("bool", CfgType::MAIN | CfgType::PLATFORM )},
{"lang", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM )},
{"langPrios", QPair<QString, int>("str", CfgType::MAIN | CfgType::PLATFORM )},
Expand Down

0 comments on commit ea4dc4a

Please sign in to comment.