Exemple #1
0
        public void RetrieveVideoData()
        {
            Task.Run(() =>
            {
                IsRetrieving = true;

                foreach (var customSongKVP in SongLoader.Instance.CustomSongs)
                {
                    string videoJsonPath = GetJSONPath(customSongKVP.Value.ModPath);

                    if (File.Exists(videoJsonPath))
                    {
                        var video = LoadVideo(videoJsonPath, customSongKVP.Value);

                        if (video != null)
                        {
                            AddVideo(video);
                        }
                    }
                }

                IsRetrieving = false;
                VideosLoadedEvent?.Invoke();
            });
        }
        private void RetrieveCustomLevelVideoData(Loader loader, Dictionary <string, CustomPreviewBeatmapLevel> levels)
        {
            Action job = delegate
            {
                try
                {
                    float i = 0;
                    foreach (var level in levels)
                    {
                        i++;
                        var songPath = level.Value.customLevelPath;
                        var results  = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories);
                        if (results.Length == 0)
                        {
                            continue;
                        }

                        var result = results[0];

                        try
                        {
                            var i1 = i;
                            HMMainThreadDispatcher.instance.Enqueue(delegate
                            {
                                if (_loadingCancelled)
                                {
                                    return;
                                }

                                VideoData video = LoadVideo(result, level.Value);
                                if (video != null)
                                {
                                    AddVideo(video);
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            Plugin.logger.Error("Failed to load song folder: " + result);
                            Plugin.logger.Error(e.ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    Plugin.logger.Error("RetrieveCustomLevelVideoData failed:");
                    Plugin.logger.Error(e.ToString());
                }
            };

            Action finish = delegate
            {
                AreVideosLoaded  = true;
                AreVideosLoading = false;

                _loadingTask = null;

                VideosLoadedEvent?.Invoke();
            };

            _loadingTask = new HMTask(job, finish);
            _loadingTask.Run();
        }
        private void RetrieveOSTVideoData()
        {
            BeatmapLevelSO[] levels = Resources.FindObjectsOfTypeAll <BeatmapLevelSO>().Where(x => x.GetType() != typeof(CustomBeatmapLevel)).ToArray();

            Action job = delegate
            {
                try
                {
                    float i = 0;
                    foreach (var level in levels)
                    {
                        i++;
                        var videoFileName = level.songName;
                        // strip invlid characters
                        foreach (var c in Path.GetInvalidFileNameChars())
                        {
                            videoFileName = videoFileName.Replace(c, '-');
                        }
                        videoFileName = videoFileName.Replace('\\', '-');
                        videoFileName = videoFileName.Replace('/', '-');

                        var songPath = Path.Combine(Environment.CurrentDirectory, "CustomSongs", "_OST", videoFileName);

                        if (!Directory.Exists(songPath))
                        {
                            continue;
                        }
                        var results = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories);
                        if (results.Length == 0)
                        {
                            continue;
                        }

                        var result = results[0];

                        try
                        {
                            var i1 = i;
                            HMMainThreadDispatcher.instance.Enqueue(delegate
                            {
                                if (_loadingCancelled)
                                {
                                    return;
                                }
                                VideoData video = LoadVideo(result, level.difficultyBeatmapSets[0].difficultyBeatmaps[0].level);
                                if (video != null)
                                {
                                    AddVideo(video);
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            Plugin.logger.Error("Failed to load song folder: " + result);
                            Plugin.logger.Error(e.ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    Plugin.logger.Error("RetrieveOSTVideoData failed:");
                    Plugin.logger.Error(e.ToString());
                }
            };

            Action finish = delegate
            {
                AreVideosLoaded  = true;
                AreVideosLoading = false;

                _loadingTask = null;

                VideosLoadedEvent?.Invoke();
            };

            _loadingTask = new HMTask(job, finish);
            _loadingTask.Run();
        }
        private void RetrieveCustomLevelVideoData()
        {
            _loadingTask = new HMTask(() =>
            {
                try
                {
                    float i = 0;
                    foreach (var level in mapLevels)
                    {
                        i++;
                        var songPath = level.Value.customLevelPath;
                        var results  = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories);
                        if (results.Length == 0)
                        {
                            continue;
                        }

                        var result = results[0];

                        try
                        {
                            var i1 = i;
                            HMMainThreadDispatcher.instance.Enqueue(delegate
                            {
                                VideoDatas videos;
                                if (_loadingCancelled)
                                {
                                    return;
                                }
                                try
                                {
                                    videos       = LoadVideos(result, level.Value);
                                    videos.level = level.Value;
                                    foreach (VideoData vid in videos.videos)
                                    {
                                        vid.level = level.Value;
                                    }
                                }
                                catch
                                {
                                    videos = new VideoDatas {
                                        videos = new List <VideoData> {
                                            LoadVideo(result, level.Value)
                                        }, level = level.Value
                                    };
                                }

                                if (videos != null && videos.videos.Count != 0)
                                {
                                    AddLevelsVideos(videos);
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            Plugin.Logger.Error("Failed to load song folder: " + result);
                            Plugin.Logger.Error(e.ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    Plugin.Logger.Error("RetrieveCustomLevelVideoData failed:");
                    Plugin.Logger.Error(e.ToString());
                }
            }, () =>
            {
                AreVideosLoaded  = true;
                AreVideosLoading = false;

                _loadingTask = null;

                VideosLoadedEvent?.Invoke();
            });
            _loadingTask.Run();
        }
        private void RetrieveOSTVideoData()
        {
            BeatmapLevelSO[] levels = Resources.FindObjectsOfTypeAll <BeatmapLevelSO>()
                                      .Where(x => x.GetType() != typeof(CustomBeatmapLevel)).ToArray();
            Plugin.Logger.Info("Getting OST Video Data");
            Action job = delegate
            {
                try
                {
                    float i = 0;
                    foreach (BeatmapLevelSO level in levels)
                    {
                        var soundData = new float[level.beatmapLevelData.audioClip.samples];
                        level.beatmapLevelData.audioClip.GetData(soundData, level.beatmapLevelData.audioClip.samples);
                        i++;
                        var videoFileName = level.songName;
                        // Plugin.Logger.Info($"Trying for: {videoFileName}");
                        // strip invlid characters
                        foreach (var c in Path.GetInvalidFileNameChars())
                        {
                            videoFileName = videoFileName.Replace(c, '-');
                        }

                        videoFileName = videoFileName.Replace('\\', '-');
                        videoFileName = videoFileName.Replace('/', '-');

                        var songPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "CustomLevels", "_OST", videoFileName);

                        if (!Directory.Exists(songPath))
                        {
                            continue;
                        }
                        // Plugin.Logger.Info($"Using name: {videoFileName}");
                        // Plugin.Logger.Info($"At Path: {songPath}");
                        // Plugin.Logger.Info($"Exists");
                        var results = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories);
                        if (results.Length == 0)
                        {
                            // Plugin.Logger.Info($"No video.json");
                            continue;
                        }
                        // Plugin.Logger.Info($"Found video.json");

                        var result = results[0];
                        Plugin.Logger.Info(result);

                        try
                        {
                            var i1 = i;
                            HMMainThreadDispatcher.instance.Enqueue(() =>
                            {
                                VideoDatas videos;
                                if (_loadingCancelled)
                                {
                                    return;
                                }
                                IPreviewBeatmapLevel previewBeatmapLevel = level.difficultyBeatmapSets[0].difficultyBeatmaps[0].level;
                                Plugin.Logger.Info($"Loading: {previewBeatmapLevel.songName}");
                                try
                                {
                                    // Plugin.Logger.Info($"Loading as multiple videos");
                                    videos       = LoadVideos(result, previewBeatmapLevel);
                                    videos.level = previewBeatmapLevel;
                                }
                                catch
                                {
                                    // Plugin.Logger.Info($"Loading as single video");
                                    var video = LoadVideo(result, previewBeatmapLevel);
                                    videos    = new VideoDatas
                                    {
                                        videos = new List <VideoData> {
                                            video
                                        },
                                        level = video.level
                                    };
                                }

                                if (videos.videos.Count != 0)
                                {
                                    AddLevelsVideos(videos);
                                    foreach (var videoData in videos)
                                    {
                                        // Plugin.Logger.Info($"Found Video: {videoData.ToString()}");
                                    }
                                }
                                else
                                {
                                    // Plugin.Logger.Info($"No Videos");
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            Plugin.Logger.Error("Failed to load song folder: " + result);
                            Plugin.Logger.Error(e.ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    Plugin.Logger.Error("RetrieveOSTVideoData failed:");
                    Plugin.Logger.Error(e.ToString());
                }
            };

            _loadingTask = new HMTask(job, () =>
            {
                AreVideosLoaded  = true;
                AreVideosLoading = false;

                _loadingTask = null;

                VideosLoadedEvent?.Invoke();
            });
            _loadingTask.Run();
        }
        private void RetrieveCustomLevelVideoData(SongLoader songLoader, List <CustomLevel> levels)
        {
            Action job = delegate
            {
                try
                {
                    float i = 0;
                    foreach (var level in levels)
                    {
                        i++;
                        var songPath = level.customSongInfo.path;
                        var results  = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories);
                        if (results.Length == 0)
                        {
                            continue;
                        }

                        var result = results[0];

                        try
                        {
                            var i1 = i;
                            HMMainThreadDispatcher.instance.Enqueue(delegate
                            {
                                if (_loadingCancelled)
                                {
                                    return;
                                }
                                VideoData video = LoadVideo(result, level.difficultyBeatmaps[0].level);
                                if (video != null)
                                {
                                    AddVideo(video);
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed to load song folder: " + result);
                            Console.WriteLine(e.ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("RetrieveCustomLevelVideoData failed:");
                    Console.WriteLine(e.ToString());
                }
            };

            Action finish = delegate
            {
                AreVideosLoaded  = true;
                AreVideosLoading = false;

                _loadingTask = null;

                VideosLoadedEvent?.Invoke();
            };

            _loadingTask = new HMTask(job, finish);
            _loadingTask.Run();
        }