Skip to content

Commit

Permalink
Added aliasMap.csv support to more scrapers
Browse files Browse the repository at this point in the history
  • Loading branch information
retrobit committed Feb 18, 2024
1 parent 95eac64 commit 624d68e
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 127 deletions.
97 changes: 57 additions & 40 deletions src/abstractscraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,60 +457,72 @@ bool AbstractScraper::checkNom(const QString nom) {
return false;
}

QList<QString> AbstractScraper::getSearchNames(const QFileInfo &info) {
QString baseName = info.completeBaseName();
QList<QString> AbstractScraper::getSearchNames(const QFileInfo &info, QString &debug) {
QString baseName = info.baseName();
QList<QString> searchNames;
QString searchName = baseName;

debug.append("Base name: '" + baseName + "'\n");

if (config->scraper != "import") {
if (!config->aliasMap[baseName].isEmpty()) {
baseName = config->aliasMap[baseName];
debug.append("'aliasMap.csv' entry found\n");
QString aliasName = config->aliasMap[baseName];
debug.append("Alias name: '" + aliasName + "'\n");
searchName = aliasName;
} else if (info.suffix() == "lha") {
QString nameWithSpaces = config->whdLoadMap[baseName].first;
if (nameWithSpaces.isEmpty()) {
baseName = NameTools::getNameWithSpaces(baseName);
searchName = NameTools::getNameWithSpaces(baseName);
} else {
baseName = nameWithSpaces;
debug.append("'whdload_db.xml' entry found\n");
searchName = nameWithSpaces;
debug.append("Entry name: '" + searchName + "'\n");
}
} else if (config->platform == "scummvm") {
baseName = NameTools::getScummName(baseName, config->scummIni);
searchName = NameTools::getScummName(baseName, config->scummIni);
} else if ((config->platform == "neogeo" ||
config->platform == "arcade" ||
config->platform == "mame-advmame" ||
config->platform == "mame-libretro" ||
config->platform == "mame-mame4all" ||
config->platform == "fba") &&
!config->mameMap[baseName].isEmpty()) {
baseName = config->mameMap[baseName];
!config->mameMap[baseName].isEmpty()) {
debug.append("'mameMap.csv' entry found\n");
searchName = config->mameMap[baseName];
debug.append("Entry name: '" + searchName + "'\n");
}
}

QList<QString> searchNames;

if (baseName.isEmpty())
if (searchName.isEmpty())
return searchNames;

searchNames.append(NameTools::getUrlQueryName(baseName));
searchNames.append(NameTools::getUrlQueryName(searchName));

if (baseName.contains(":") || baseName.contains(" - ")) {
QString noSubtitle = baseName.left(baseName.indexOf(":")).simplified();
// If search name has a subtitle, also search without subtitle
if (searchName.contains(":") || searchName.contains(" - ")) {
QString noSubtitle = searchName.left(searchName.indexOf(":")).simplified();
noSubtitle = noSubtitle.left(noSubtitle.indexOf(" - ")).simplified();
// Only add if longer than 3. We don't want to search for "the" for
// instance
if (noSubtitle.length() > 3)
searchNames.append(NameTools::getUrlQueryName(noSubtitle));
}

if (NameTools::hasRomanNumeral(baseName) ||
NameTools::hasIntegerNumeral(baseName)) {
if (NameTools::hasRomanNumeral(baseName)) {
baseName = NameTools::convertToIntegerNumeral(baseName);
} else if (NameTools::hasIntegerNumeral(baseName)) {
baseName = NameTools::convertToRomanNumeral(baseName);
// If the search name has a Roman numeral, also search for an integer numeral version, vice-versa
if (NameTools::hasRomanNumeral(searchName) ||
NameTools::hasIntegerNumeral(searchName)) {
if (NameTools::hasRomanNumeral(searchName)) {
searchName = NameTools::convertToIntegerNumeral(searchName);
} else if (NameTools::hasIntegerNumeral(searchName)) {
searchName = NameTools::convertToRomanNumeral(searchName);
}
searchNames.append(NameTools::getUrlQueryName(baseName));
searchNames.append(NameTools::getUrlQueryName(searchName));

if (baseName.contains(":") || baseName.contains(" - ")) {
// If search name has a subtitle, also search without subtitle
if (searchName.contains(":") || searchName.contains(" - ")) {
QString noSubtitle =
baseName.left(baseName.indexOf(":")).simplified();
searchName.left(searchName.indexOf(":")).simplified();
noSubtitle =
noSubtitle.left(noSubtitle.indexOf(" - ")).simplified();
// Only add if longer than 3. We don't want to search for "the" for
Expand All @@ -524,55 +536,56 @@ QList<QString> AbstractScraper::getSearchNames(const QFileInfo &info) {
}

QString AbstractScraper::getCompareTitle(QFileInfo info) {
QString baseName = info.completeBaseName();
QString baseName = info.baseName();
QString compareTitle;

if (config->scraper != "import") {
if (!config->aliasMap[baseName].isEmpty()) {
baseName = config->aliasMap[baseName];
compareTitle = config->aliasMap[baseName];
} else if (info.suffix() == "lha") {
QString nameWithSpaces = config->whdLoadMap[baseName].first;
if (nameWithSpaces.isEmpty()) {
baseName = NameTools::getNameWithSpaces(baseName);
compareTitle = NameTools::getNameWithSpaces(baseName);
} else {
baseName = nameWithSpaces;
compareTitle = nameWithSpaces;
}
} else if (config->platform == "scummvm") {
baseName = NameTools::getScummName(baseName, config->scummIni);
compareTitle = NameTools::getScummName(baseName, config->scummIni);
} else if ((config->platform == "neogeo" ||
config->platform == "arcade" ||
config->platform == "mame-advmame" ||
config->platform == "mame-libretro" ||
config->platform == "mame-mame4all" ||
config->platform == "fba") &&
!config->mameMap[baseName].isEmpty()) {
baseName = config->mameMap[baseName];
compareTitle = config->mameMap[baseName];
}
}

// Now create actual compareTitle
baseName = baseName.replace("_", " ")
.left(baseName.indexOf("("))
.left(baseName.indexOf("["))
compareTitle = compareTitle.replace("_", " ")
.left(compareTitle.indexOf("("))
.left(compareTitle.indexOf("["))
.simplified();

QRegularExpressionMatch match;

// Always move ", The" to the beginning of the name
match = QRegularExpression(", [Tt]he").match(baseName);
match = QRegularExpression(", [Tt]he").match(compareTitle);
if (match.hasMatch()) {
baseName = baseName.replace(match.captured(0), "")
compareTitle = compareTitle.replace(match.captured(0), "")
.prepend(match.captured(0).right(3) + " ");
}

// Remove "vX.XXX" versioning string if one is found
match = QRegularExpression(
" v[.]{0,1}([0-9]{1}[0-9]{0,2}[.]{0,1}[0-9]{1,4}|[IVX]{1,5})$")
.match(baseName);
.match(compareTitle);
if (match.hasMatch() && match.capturedStart(0) != -1) {
baseName = baseName.left(match.capturedStart(0)).simplified();
compareTitle = compareTitle.left(match.capturedStart(0)).simplified();
}

return baseName;
return compareTitle;
}

void AbstractScraper::runPasses(QList<GameEntry> &gameEntries,
Expand Down Expand Up @@ -641,17 +654,21 @@ void AbstractScraper::runPasses(QList<GameEntry> &gameEntries,
}

QList<QString> searchNames;
if (config->searchName.isEmpty()) {
searchNames = getSearchNames(info);
} else {
if (!config->searchName.isEmpty()) {
// Add the string provided by "--query"
searchNames.append(config->searchName);
} else {
searchNames = getSearchNames(info, debug);
}

if (searchNames.isEmpty()) {
return;
}

for (int i = 0; i < searchNames.size(); i++) {
debug.append(QString("Search name #%1: '" + searchNames.at(i) + "'\n").arg(i+1));
}

for (int pass = 1; pass <= searchNames.size(); ++pass) {
output.append("\033[1;35mPass " + QString::number(pass) + "\033[0m ");
getSearchResults(gameEntries, searchNames.at(pass - 1),
Expand Down
2 changes: 1 addition & 1 deletion src/abstractscraper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AbstractScraper : public QObject {
AbstractScraper(Settings *config, QSharedPointer<NetManager> manager);
virtual ~AbstractScraper();
virtual void getGameData(GameEntry &game);
virtual QList<QString> getSearchNames(const QFileInfo &info);
virtual QList<QString> getSearchNames(const QFileInfo &info, QString &debug);
virtual QString getCompareTitle(QFileInfo info);
virtual void runPasses(QList<GameEntry> &gameEntries, const QFileInfo &info,
QString &output, QString &debug);
Expand Down
16 changes: 14 additions & 2 deletions src/arcadedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,20 @@ void ArcadeDB::getVideo(GameEntry &game) {
}
}

QList<QString> ArcadeDB::getSearchNames(const QFileInfo &info) {
QList<QString> ArcadeDB::getSearchNames(const QFileInfo &info, QString &debug) {
QString baseName = info.baseName();
QList<QString> searchNames;
searchNames.append(info.baseName());
QString searchName = baseName;

debug.append("Base name: '" + baseName + "'\n");

if (!config->aliasMap[baseName].isEmpty()) {
debug.append("'aliasMap.csv' entry found\n");
QString aliasName = config->aliasMap[baseName];
debug.append("Alias name: '" + aliasName + "'\n");
searchName = aliasName;
}

searchNames.append(searchName);
return searchNames;
}
2 changes: 1 addition & 1 deletion src/arcadedb.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ArcadeDB : public AbstractScraper {
ArcadeDB(Settings *config, QSharedPointer<NetManager> manager);

private:
QList<QString> getSearchNames(const QFileInfo &info) override;
QList<QString> getSearchNames(const QFileInfo &info, QString &debug) override;
void getSearchResults(QList<GameEntry> &gameEntries, QString searchName,
QString platform) override;
void getGameData(GameEntry &game) override;
Expand Down
6 changes: 3 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ void Config::copyFile(const QString &src, const QString &dest, FileOp fileOp) {
if (fileOp == FileOp::OVERWRITE) {
QFile::remove(dest);
QFile::copy(src, dest);
qDebug() << "Overwritten file" << dest << "\n";
qDebug() << "Overwritten file" << dest;
} else if (fileOp == FileOp::CREATE_DIST) {
QString d = QString(dest + ".dist");
QFile::remove(d);
QFile::copy(src, d);
qDebug() << "Created original dist file as" << d << "\n";
qDebug() << "Created original dist file as" << d;
}
} else {
QFile::copy(src, dest);
Expand Down Expand Up @@ -89,7 +89,7 @@ void Config::setupUserConfig() {
QString localEtcPath = QString(PREFIX "/etc/skyscraper/");

if (!QFileInfo::exists(localEtcPath)) {
// RetroPie installation type
// Non-Windows installation type
return;
}

Expand Down
18 changes: 16 additions & 2 deletions src/esgamelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,22 @@ QString ESGameList::getAbsoluteFileName(QString fileName) {
return "";
}

QList<QString> ESGameList::getSearchNames(const QFileInfo &info) {
QList<QString> ESGameList::getSearchNames(const QFileInfo &info, QString &debug) {
QString fileName = info.fileName();
QString baseName = info.baseName();
QList<QString> searchNames;
searchNames.append(info.fileName());
QString searchName = fileName;

debug.append("Filename: '" + fileName + "'\n");
debug.append("Base name: '" + baseName + "'\n");

if (!config->aliasMap[baseName].isEmpty()) {
debug.append("'aliasMap.csv' entry found\n");
QString aliasName = config->aliasMap[baseName];
debug.append("Alias name: '" + aliasName + "'\n");
searchName = aliasName;
}

searchNames.append(searchName);
return searchNames;
}
2 changes: 1 addition & 1 deletion src/esgamelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ESGameList : public AbstractScraper {
ESGameList(Settings *config, QSharedPointer<NetManager> manager);

private:
QList<QString> getSearchNames(const QFileInfo &info) override;
QList<QString> getSearchNames(const QFileInfo &info, QString &debug) override;
void getSearchResults(QList<GameEntry> &gameEntries, QString searchName,
QString platform) override;
void getGameData(GameEntry &game) override;
Expand Down
35 changes: 24 additions & 11 deletions src/igdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,30 +271,43 @@ void Igdb::getRating(GameEntry &game) {
}
}

QList<QString> Igdb::getSearchNames(const QFileInfo &info) {
QString baseName = info.completeBaseName();
QList<QString> Igdb::getSearchNames(const QFileInfo &info, QString &debug) {
QString baseName = info.baseName();
QString searchName = baseName;

debug.append("Base name: '" + baseName + "'\n");

if (!config->aliasMap[baseName].isEmpty()) {
baseName = config->aliasMap[baseName];
debug.append("'aliasMap.csv' entry found\n");
QString aliasName = config->aliasMap[baseName];
debug.append("Alias name: '" + aliasName + "'\n");
searchName = aliasName;
} else if (info.suffix() == "lha") {
QString nameWithSpaces = config->whdLoadMap[baseName].first;
if (nameWithSpaces.isEmpty()) {
baseName = NameTools::getNameWithSpaces(baseName);
searchName = NameTools::getNameWithSpaces(baseName);
} else {
baseName = nameWithSpaces;
debug.append("'whdload_db.xml' entry found\n");
searchName = nameWithSpaces;
debug.append("Entry name: '" + searchName + "'\n");
}
} else if (config->platform == "scummvm") {
baseName = NameTools::getScummName(baseName, config->scummIni);
} else if ((config->platform == "neogeo" || config->platform == "arcade" ||
searchName = NameTools::getScummName(baseName, config->scummIni);
} else if ((config->platform == "neogeo" ||
config->platform == "arcade" ||
config->platform == "mame-advmame" ||
config->platform == "mame-libretro" ||
config->platform == "mame-mame4all" ||
config->platform == "fba") &&
!config->mameMap[baseName].isEmpty()) {
baseName = config->mameMap[baseName];
!config->mameMap[baseName].isEmpty()) {
debug.append("'mameMap.csv' entry found\n");
searchName = config->mameMap[baseName];
debug.append("Entry name: '" + searchName + "'\n");
}
baseName = StrTools::stripBrackets(baseName);

QList<QString> searchNames;
searchNames.append(baseName);

searchName = StrTools::stripBrackets(baseName);
searchNames.append(searchName);
return searchNames;
}
2 changes: 1 addition & 1 deletion src/igdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Igdb : public AbstractScraper {
void getDescription(GameEntry &game) override;
void getRating(GameEntry &game) override;

QList<QString> getSearchNames(const QFileInfo &info) override;
QList<QString> getSearchNames(const QFileInfo &info, QString &debug) override;

QJsonDocument jsonDoc;
QJsonObject jsonObj;
Expand Down
10 changes: 5 additions & 5 deletions src/mobygames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void MobyGames::getSearchResults(QList<GameEntry> &gameEntries,
: "&platform=" + QString::number(platformId)));
queryGameId = 0;
}
qDebug() << "Request: " << req << "\n";
qDebug() << "Request: " << req;
netComm->request(req);
q.exec();
data = netComm->getData();
Expand Down Expand Up @@ -169,11 +169,11 @@ void MobyGames::getTags(GameEntry &game) {
for (auto gg : jsonGenres) {
QJsonObject jg = gg.toObject();
int genreCatId = jg["genre_category_id"].toInt();
qDebug() << "Got genre cat id" << genreCatId << "\n";
qDebug() << "Got genre cat id" << genreCatId;
if (/*Basic Genres*/ 1 == genreCatId || /*Gameplay*/ 4 == genreCatId) {
QString gs = jg["genre_name"].toString();
game.tags.append(gs + ", ");
qDebug() << "Using" << gs << "\n";
qDebug() << "Using" << gs;
}
}
game.tags.chop(2);
Expand Down Expand Up @@ -302,7 +302,7 @@ void MobyGames::getCover(GameEntry &game) {
game.url.left(game.url.indexOf("?api_key=")) + "/covers" +
game.url.mid(game.url.indexOf("?api_key="),
game.url.length() - game.url.indexOf("?api_key=")));
qDebug() << "Covers " << req << "\n";
qDebug() << "Covers " << req;
netComm->request(req);
q.exec();
data = netComm->getData();
Expand Down Expand Up @@ -424,7 +424,7 @@ int MobyGames::getPlatformId(const QString platform) {

QString MobyGames::getRegionShort(const QString &region) {
if (regionMap.contains(region)) {
qDebug() << "Got region" << regionMap[region] << "\n";
qDebug() << "Got region" << regionMap[region];
return regionMap[region];
}
return "na";
Expand Down
Loading

0 comments on commit 624d68e

Please sign in to comment.