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);
        }
        private string GetSgdbRequestUrl(Game game, bool isBackgroundDownload)
        {
            if (SteamCommon.IsGameSteamGame(game))
            {
                return(ApplySgdbLogoFilters(string.Format(sgdbLogoRequestEnumUriTemplate, "steam", game.GameId.ToString())));
            }
            else
            {
                var gamesList = GetSteamGridDbSearchResults(game.Name);
                // Try to see if there's an exact match, to not prompt the user unless needed
                var matchingGameName = game.Name.GetMatchModifiedName();
                var exactMatches     = gamesList.Where(x => x.Name.GetMatchModifiedName() == matchingGameName);
                if (isBackgroundDownload)
                {
                    if (exactMatches?.ToList().Count > 0)
                    {
                        return(ApplySgdbLogoFilters(string.Format(sgdbLogoRequestIdUriTemplate, exactMatches.First().Id.ToString())));
                    }
                }
                else
                {
                    if (exactMatches?.ToList().Count == 1)
                    {
                        return(ApplySgdbLogoFilters(string.Format(sgdbLogoRequestIdUriTemplate, exactMatches.First().Id.ToString())));
                    }

                    var selectedGame = playniteApi.Dialogs.ChooseItemWithSearch(
                        new List <GenericItemOption>(),
                        (a) => GetSteamGridDbGenericItemOptions(a),
                        game.Name,
                        ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogCaptionSelectGame"));
                    if (selectedGame != null)
                    {
                        return(ApplySgdbLogoFilters(string.Format(sgdbLogoRequestIdUriTemplate, selectedGame.Description)));
                    }
                }
            }

            return(null);
        }
Exemple #3
0
        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);
        }