// Load Video datas from disk private static VideoDatas LoadVideos(string jsonPath, IPreviewBeatmapLevel level) { var infoText = File.ReadAllText(jsonPath); VideoDatas vids; try { try { vids = JsonConvert.DeserializeObject <VideoDatas>(infoText); } catch { VideoData vid = JsonConvert.DeserializeObject <VideoData>(infoText); vid.level = level; vids = new VideoDatas { videos = new List <VideoData> { vid }, level = level }; } } catch (Exception e) { Plugin.logger.Warn("Error parsing video json: " + jsonPath); Plugin.logger.Error(e.GetType().ToString()); Plugin.logger.Error(e.StackTrace); return(null); } foreach (VideoData vid in vids.videos) { vid.level = level; // if (File.Exists(GetVideoPath(vid))) // { // vid.downloadState = DownloadState.Downloaded; // } vid.UpdateDownloadState(); } return(vids); }
public void AddVideo(VideoData video, IPreviewBeatmapLevel level) { VideoDatas thisLevelsVideos; if (!levelsVideos.TryGetValue(level, out thisLevelsVideos)) { thisLevelsVideos = new VideoDatas { videos = new List <VideoData> { video }, level = video.level }; levelsVideos.TryAdd(level, thisLevelsVideos); } else { thisLevelsVideos.Add(video); thisLevelsVideos.activeVideo = thisLevelsVideos.Count - 1; } }
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(); }
public void RemoveVideos(VideoDatas videos) { //TODO: make sure this is right // levelsVideos.Remove(videos.level); levelsVideos.TryRemove(videos.level, out _); }
public void AddLevelsVideos(VideoDatas videos, IPreviewBeatmapLevel level) { levelsVideos.TryAdd(level, videos); }
public void AddLevelsVideos(VideoDatas videos) { AddLevelsVideos(videos, videos.level); }
public void RemoveVideos(VideoDatas videos) { //TODO: make sure this is right levelsVideos.Remove(videos.level); }