コード例 #1
0
        private List <SteamGridDbGameSearchResponse.Data> GetSteamGridDbSearchResults(string gameName)
        {
            var searchUrl = string.Format(sgdbGameSearchUriTemplate, Uri.EscapeDataString(gameName));
            var headers   = new Dictionary <string, string> {
                { "Accept", "application/json" },
                { "Authorization", $"Bearer {settings.SgdbApiKey}" }
            };
            var downloadedString = HttpDownloader.DownloadStringWithHeadersAsync(searchUrl, headers).GetAwaiter().GetResult();

            if (!string.IsNullOrEmpty(downloadedString))
            {
                var response = JsonConvert.DeserializeObject <SteamGridDbGameSearchResponse.Response>(downloadedString);
                if (response.Success)
                {
                    return(response.Data);
                }
                else
                {
                    logger.Debug($"SteamGridDB request failed. Response string: {downloadedString}");
                }
            }
            return(new List <SteamGridDbGameSearchResponse.Data>());
        }
コード例 #2
0
        public bool DownloadSgdbLogo(Game game, bool overwrite, bool isBackgroundDownload)
        {
            var logoPath = extraMetadataHelper.GetGameLogoPath(game, true);

            if (File.Exists(logoPath) && !overwrite)
            {
                logger.Debug("Logo exists and overwrite is set to false, skipping");
                return(true);
            }
            else if (settings.SgdbApiKey.IsNullOrEmpty())
            {
                logger.Debug("SteamGridDB API Key has not been configured in settings.");
                playniteApi.Notifications.Add(new NotificationMessage("emtSgdbNoApiKey", ResourceProvider.GetString("LOCExtra_Metadata_Loader_NotificationMessageSgdbApiKeyMissing"), NotificationType.Error));
                return(false);
            }

            var requestString = GetSgdbRequestUrl(game, isBackgroundDownload);

            if (!string.IsNullOrEmpty(requestString))
            {
                var headers = new Dictionary <string, string> {
                    { "Accept", "application/json" },
                    { "Authorization", $"Bearer {settings.SgdbApiKey}" }
                };
                var downloadedString = HttpDownloader.DownloadStringWithHeadersAsync(requestString, headers).GetAwaiter().GetResult();
                if (!string.IsNullOrEmpty(downloadedString))
                {
                    var response = JsonConvert.DeserializeObject <SteamGridDbLogoResponse.Response>(downloadedString);
                    if (response.Success && response.Data.Count > 0)
                    {
                        var success = false;
                        if (isBackgroundDownload || response.Data.Count == 1)
                        {
                            success = HttpDownloader.DownloadFileAsync(response.Data[0].Url, logoPath).GetAwaiter().GetResult();
                        }
                        else
                        {
                            var imageFileOptions = new List <ImageFileOption>();
                            foreach (var icon in response.Data)
                            {
                                imageFileOptions.Add(new ImageFileOption
                                {
                                    Path = icon.Thumb,
                                });
                            }
                            if (imageFileOptions.Count > 0)
                            {
                                var selectedOption = playniteApi.Dialogs.ChooseImageFile(
                                    imageFileOptions, string.Format(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogCaptionSelectLogo"), game.Name));
                                if (selectedOption != null)
                                {
                                    // Since the ImageFileOption dialog used the thumb url, the full resolution
                                    // image url needs to be retrieved
                                    success = HttpDownloader.DownloadFileAsync(response.Data.First(x => x.Thumb == selectedOption.Path).Url, logoPath).GetAwaiter().GetResult();
                                }
                            }
                        }
                        if (success && settings.ProcessLogosOnDownload)
                        {
                            ProcessLogoImage(logoPath);
                        }
                    }
                    else if (!response.Success)
                    {
                        logger.Debug($"SteamGridDB request failed. Response string: {downloadedString}");
                    }
                }
            }

            return(false);
        }