Ejemplo n.º 1
0
        private void UpdateAssetsTagsStatus()
        {
            if (settings.Settings.UpdateMissingLogoTagOnLibUpdate ||
                settings.Settings.UpdateMissingVideoTagOnLibUpdate ||
                settings.Settings.UpdateMissingMicrovideoTagOnLibUpdate)
            {
                PlayniteApi.Dialogs.ActivateGlobalProgress((a) =>
                {
                    Tag logoMissingTag       = null;
                    Tag videoMissingTag      = null;
                    Tag microvideoMissingTag = null;
                    if (settings.Settings.UpdateMissingLogoTagOnLibUpdate)
                    {
                        logoMissingTag = PlayniteApi.Database.Tags.Add("[EMT] Logo Missing");
                    }
                    if (settings.Settings.UpdateMissingVideoTagOnLibUpdate)
                    {
                        videoMissingTag = PlayniteApi.Database.Tags.Add("[EMT] Video missing");
                    }
                    if (settings.Settings.UpdateMissingMicrovideoTagOnLibUpdate)
                    {
                        microvideoMissingTag = PlayniteApi.Database.Tags.Add("[EMT] Video Micro missing");
                    }

                    foreach (var game in PlayniteApi.Database.Games)
                    {
                        var gameUpdated = false;
                        if (logoMissingTag != null)
                        {
                            if (File.Exists(extraMetadataHelper.GetGameLogoPath(game)))
                            {
                                var tagRemoved = RemoveTag(game, logoMissingTag, false);
                                if (tagRemoved)
                                {
                                    gameUpdated = true;
                                }
                            }
                            else
                            {
                                var tagAdded = AddTag(game, logoMissingTag, false);
                                if (tagAdded)
                                {
                                    gameUpdated = true;
                                }
                            }
                        }
                        if (videoMissingTag != null)
                        {
                            if (File.Exists(extraMetadataHelper.GetGameVideoPath(game)))
                            {
                                var tagRemoved = RemoveTag(game, videoMissingTag, false);
                                if (tagRemoved)
                                {
                                    gameUpdated = true;
                                }
                            }
                            else
                            {
                                var tagAdded = AddTag(game, videoMissingTag, false);
                                if (tagAdded)
                                {
                                    gameUpdated = true;
                                }
                            }
                        }
                        if (microvideoMissingTag != null)
                        {
                            if (File.Exists(extraMetadataHelper.GetGameVideoMicroPath(game)))
                            {
                                var tagRemoved = RemoveTag(game, microvideoMissingTag, false);
                                if (tagRemoved)
                                {
                                    gameUpdated = true;
                                }
                            }
                            else
                            {
                                var tagAdded = AddTag(game, microvideoMissingTag, false);
                                if (tagAdded)
                                {
                                    gameUpdated = true;
                                }
                            }
                        }
                        if (gameUpdated)
                        {
                            PlayniteApi.Database.Games.Update(game);
                        }
                    }
                }, new GlobalProgressOptions(ResourceProvider.GetString("LOCExtra_Metadata_Loader_ProgressMessageUpdatingAssetsTags")));
            }
        }
Ejemplo n.º 2
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);
        }