public UniversalSteamMetadataSettings(UniversalSteamMetadata plugin) { this.plugin = plugin; var savedSettings = plugin.LoadPluginSettings <UniversalSteamMetadataSettings>(); if (savedSettings != null) { DownloadVerticalCovers = savedSettings.DownloadVerticalCovers; BackgroundSource = savedSettings.BackgroundSource; } }
public UniversalSteamMetadataProvider(MetadataRequestOptions options, UniversalSteamMetadata plugin) { this.options = options; this.plugin = plugin; apiClient = new SteamApiClient(); }
internal uint GetMatchingGame(Game gameInfo) { var normalizedName = StringExtensions.NormalizeGameName(gameInfo.Name); var results = UniversalSteamMetadata.GetSearchResults(normalizedName); results.ForEach(a => a.Name = StringExtensions.NormalizeGameName(a.Name)); string testName = string.Empty; uint matchedGame = 0; // Direct comparison matchedGame = MatchFun(normalizedName, results); if (matchedGame > 0) { return(matchedGame); } // Try replacing roman numerals: 3 => III testName = Regex.Replace(normalizedName, @"\d+", ReplaceNumsForRomans); matchedGame = MatchFun(testName, results); if (matchedGame > 0) { return(matchedGame); } // Try adding The testName = "The " + normalizedName; matchedGame = MatchFun(testName, results); if (matchedGame > 0) { return(matchedGame); } // Try chaning & / and testName = Regex.Replace(normalizedName, @"\s+and\s+", " & ", RegexOptions.IgnoreCase); matchedGame = MatchFun(testName, results); if (matchedGame > 0) { return(matchedGame); } // Try removing apostrophes var resCopy = Serialization.GetClone(results); resCopy.ForEach(a => a.Name = a.Name.Replace("'", "")); matchedGame = MatchFun(normalizedName, resCopy); if (matchedGame > 0) { return(matchedGame); } // Try removing all ":" and "-" testName = Regex.Replace(normalizedName, @"\s*(:|-)\s*", " "); resCopy = Serialization.GetClone(results); foreach (var res in resCopy) { res.Name = Regex.Replace(res.Name, @"\s*(:|-)\s*", " "); } matchedGame = MatchFun(testName, resCopy); if (matchedGame > 0) { return(matchedGame); } // Try without subtitle var testResult = results.FirstOrDefault(a => { if (!string.IsNullOrEmpty(a.Name) && a.Name.Contains(":")) { return(string.Equals(normalizedName, a.Name.Split(':')[0], StringComparison.InvariantCultureIgnoreCase)); } return(false); }); if (testResult != null) { return(testResult.GameId); } return(0); }
internal void GetGameData() { if (currentMetadata != null) { return; } try { var metadataProvider = new MetadataProvider(apiClient); if (BuiltinExtensions.GetExtensionFromId(options.GameData.PluginId) == BuiltinExtension.SteamLibrary) { var appId = uint.Parse(options.GameData.GameId); currentMetadata = metadataProvider.GetGameMetadata( appId, plugin.SettingsViewModel.Settings.BackgroundSource, plugin.SettingsViewModel.Settings.DownloadVerticalCovers); } else { if (options.IsBackgroundDownload) { var matchedId = GetMatchingGame(options.GameData); if (matchedId > 0) { currentMetadata = metadataProvider.GetGameMetadata( matchedId, plugin.SettingsViewModel.Settings.BackgroundSource, plugin.SettingsViewModel.Settings.DownloadVerticalCovers); } else { currentMetadata = new SteamGameMetadata(); } } else { var selectedGame = plugin.PlayniteApi.Dialogs.ChooseItemWithSearch(null, (a) => { if (uint.TryParse(a, out var appId)) { try { var store = WebApiClient.GetStoreAppDetail(appId); return(new List <GenericItemOption> { new StoreSearchResult { GameId = appId, Name = store.name } }); } catch (Exception e) { logger.Error(e, $"Failed to get Steam app info {appId}"); return(new List <GenericItemOption>()); } } else { try { var name = StringExtensions.NormalizeGameName(a); return(new List <GenericItemOption>(UniversalSteamMetadata.GetSearchResults(name))); } catch (Exception e) { logger.Error(e, $"Failed to get Steam search data for {a}"); return(new List <GenericItemOption>()); } } }, options.GameData.Name, string.Empty); if (selectedGame == null) { currentMetadata = new SteamGameMetadata(); } else { currentMetadata = metadataProvider.GetGameMetadata( ((StoreSearchResult)selectedGame).GameId, plugin.SettingsViewModel.Settings.BackgroundSource, plugin.SettingsViewModel.Settings.DownloadVerticalCovers); } } } } catch (Exception e) { logger.Error(e, $"Failed to get Steam metadata."); currentMetadata = new SteamGameMetadata(); } }