コード例 #1
0
 public MetadataController(UpdatableAppSettings settings, IgdbApi igdbApi)
 {
     this.settings      = settings;
     this.igdbApi       = igdbApi;
     gamesController    = new GamesController(settings, igdbApi);
     expandedController = new ExpandedGameController(settings, igdbApi);
     parsedController   = new GameParsedController(settings, igdbApi);
 }
コード例 #2
0
        private async Task <ulong> TryMatchGame(SdkModels.Game game)
        {
            if (game.Name.IsNullOrEmpty())
            {
                return(0);
            }

            ulong matchedGame = 0;
            var   copyGame    = game.GetClone();

            copyGame.Name = StringExtensions.NormalizeGameName(game.Name);
            var name = copyGame.Name;

            name = Regex.Replace(name, @"\s+RHCP$", "", RegexOptions.IgnoreCase);
            name = Regex.Replace(name, @"\s+RU$", "", RegexOptions.IgnoreCase);

            var results = await GamesController.GetSearchResults(name);

            results.ForEach(a => a.name = StringExtensions.NormalizeGameName(a.name));
            string testName = string.Empty;

            // Direct comparison
            matchedGame = MatchFun(game, name, results);
            if (matchedGame > 0)
            {
                return(matchedGame);
            }

            // Try replacing roman numerals: 3 => III
            testName    = Regex.Replace(name, @"\d+", ReplaceNumsForRomans);
            matchedGame = MatchFun(game, testName, results);
            if (matchedGame > 0)
            {
                return(matchedGame);
            }

            // Try adding The
            testName    = "The " + name;
            matchedGame = MatchFun(game, testName, results);
            if (matchedGame > 0)
            {
                return(matchedGame);
            }

            // Try chaning & / and
            testName    = Regex.Replace(name, @"\s+and\s+", " & ", RegexOptions.IgnoreCase);
            matchedGame = MatchFun(game, testName, results);
            if (matchedGame > 0)
            {
                return(matchedGame);
            }

            // Try removing apostrophes
            var resCopy = results.GetClone();

            resCopy.ForEach(a => a.name = a.name.Replace("'", ""));
            matchedGame = MatchFun(game, name, resCopy);
            if (matchedGame > 0)
            {
                return(matchedGame);
            }

            // Try removing all ":" and "-"
            testName = Regex.Replace(name, @"\s*(:|-)\s*", " ");
            resCopy  = results.GetClone();
            foreach (var res in resCopy)
            {
                res.name = Regex.Replace(res.name, @"\s*(:|-)\s*", " ");
                res.alternative_names?.ForEach(a => a.name = Regex.Replace(a.name, @"\s*(:|-)\s*", " "));
            }

            matchedGame = MatchFun(game, testName, resCopy);
            if (matchedGame > 0)
            {
                return(matchedGame);
            }

            // Try without subtitle
            var testResult = results.OrderBy(a => a.first_release_date).FirstOrDefault(a =>
            {
                if (a.first_release_date == 0)
                {
                    return(false);
                }

                if (!string.IsNullOrEmpty(a.name) && a.name.Contains(":"))
                {
                    return(string.Equals(name, a.name.Split(':')[0], StringComparison.InvariantCultureIgnoreCase));
                }

                return(false);
            });

            if (testResult != null)
            {
                return(testResult.id);
            }

            return(0);
        }