public bool DownloadSteamLogo(Game game, bool overwrite, bool isBackgroundDownload) { logger.Debug($"DownloadSteamLogo starting for game {game.Name}"); var logoPath = extraMetadataHelper.GetGameLogoPath(game, true); if (File.Exists(logoPath) && !overwrite) { logger.Debug("Logo exists and overwrite is set to false, skipping"); return(true); } var steamId = string.Empty; if (SteamCommon.IsGameSteamGame(game)) { logger.Debug("Steam id found for Steam game"); steamId = game.GameId; } else if (!settings.SteamDlOnlyProcessPcGames || extraMetadataHelper.IsGamePcGame(game)) { steamId = extraMetadataHelper.GetSteamIdFromSearch(game, isBackgroundDownload); } else { logger.Debug("Game is not a PC game and execution is only allowed for PC games"); return(false); } if (steamId.IsNullOrEmpty()) { logger.Debug("Steam id not found"); return(false); } var steamUri = string.Format(steamLogoUriTemplate, steamId); var success = HttpDownloader.DownloadFileAsync(steamUri, logoPath).GetAwaiter().GetResult(); if (success && settings.ProcessLogosOnDownload) { ProcessLogoImage(logoPath); } return(success); }
public bool DownloadGoogleImage(Game game, string imageUrl, bool overwrite) { logger.Debug($"DownloadGoogleImage starting for game {game.Name}"); var logoPath = extraMetadataHelper.GetGameLogoPath(game, true); if (File.Exists(logoPath) && !overwrite) { logger.Debug("Logo exists and overwrite is set to false, skipping"); return(true); } var success = HttpDownloader.DownloadFileAsync(imageUrl, logoPath).GetAwaiter().GetResult(); if (success && settings.ProcessLogosOnDownload) { ProcessLogoImage(logoPath); } return(success); }
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); }
public bool DownloadSteamVideo(Game game, bool overwrite, bool isBackgroundDownload, bool downloadVideo = false, bool downloadVideoMicro = false) { logger.Debug($"DownloadSteamVideo starting for game {game.Name}"); var videoPath = extraMetadataHelper.GetGameVideoPath(game, true); var videoMicroPath = extraMetadataHelper.GetGameVideoMicroPath(game, true); if (File.Exists(videoPath) && !overwrite) { downloadVideo = false; } if (File.Exists(videoMicroPath) && !overwrite) { downloadVideoMicro = false; } if (!downloadVideo && !downloadVideoMicro) { return(true); } var steamId = string.Empty; if (SteamCommon.IsGameSteamGame(game)) { logger.Debug("Steam id found for Steam game"); steamId = game.GameId; } else if (!settings.SteamDlOnlyProcessPcGames || extraMetadataHelper.IsGamePcGame(game)) { steamId = extraMetadataHelper.GetSteamIdFromSearch(game, isBackgroundDownload); } else { logger.Debug("Game is not a PC game and execution is only allowed for PC games"); return(false); } if (steamId.IsNullOrEmpty()) { logger.Debug("Steam id not found"); return(false); } var steamAppDetails = SteamCommon.GetSteamAppDetails(steamId); if (steamAppDetails == null || steamAppDetails.data.Movies == null || steamAppDetails.data.Movies.Count == 0) { return(false); } if (downloadVideo) { var videoUrl = steamAppDetails.data.Movies[0].Mp4.Q480; if (settings.VideoSteamDownloadHdQuality) { videoUrl = steamAppDetails.data.Movies[0].Mp4.Max; } var success = HttpDownloader.DownloadFileAsync(videoUrl.ToString(), tempDownloadPath).GetAwaiter().GetResult(); if (success) { GetVideoInformation(tempDownloadPath); ProcessVideo(tempDownloadPath, videoPath, false, true); } } if (downloadVideoMicro) { var videoUrl = string.Format(steamMicrotrailerUrlTemplate, steamAppDetails.data.Movies[0].Id); var success = HttpDownloader.DownloadFileAsync(videoUrl.ToString(), tempDownloadPath).GetAwaiter().GetResult(); if (success) { ProcessVideo(tempDownloadPath, videoMicroPath, false, true); } } return(true); }