public IEnumerator SavePlaylistCoroutine(string path = "") { Logger.Log($"Saving playlist \"{playlistTitle}\"..."); try { image = Sprites.SpriteToBase64(icon); playlistSongCount = songs.Count; } catch (Exception e) { Logger.Exception("Unable to save playlist! Exception: " + e); yield break; } foreach (PlaylistSong song in songs) { yield return(song.MatchKey()); } try { if (!string.IsNullOrEmpty(path)) { fileLoc = Path.GetFullPath(path); } File.WriteAllText(fileLoc, JsonConvert.SerializeObject(this, Formatting.Indented)); Logger.Log("Playlist saved!"); } catch (Exception e) { Logger.Exception("Unable to save playlist! Exception: " + e); yield break; } }
public IEnumerator RequestSongByLevelIDCoroutine(string levelId, Action <Song> callback) { UnityWebRequest wwwId = UnityWebRequest.Get($"{PluginConfig.beatsaverURL}/api/songs/search/hash/" + levelId); wwwId.timeout = 10; yield return(wwwId.SendWebRequest()); if (wwwId.isNetworkError || wwwId.isHttpError) { Logger.Error(wwwId.error); } else { #if DEBUG Logger.Log("Received response from BeatSaver..."); #endif JSONNode node = JSON.Parse(wwwId.downloadHandler.text); if (node["songs"].Count == 0) { Logger.Error($"Song {levelId} doesn't exist on BeatSaver!"); callback?.Invoke(null); yield break; } Song _tempSong = Song.FromSearchNode(node["songs"][0]); callback?.Invoke(_tempSong); } }
public void DownloadAllSongsFromQueue() { Logger.Log("Downloading all songs from queue..."); for (int i = 0; i < Math.Min(PluginConfig.maxSimultaneousDownloads, queuedSongs.Count); i++) { StartCoroutine(DownloadSong(queuedSongs[i])); } Refresh(); }
public void AbortDownloads() { Logger.Log("Cancelling downloads..."); foreach (Song song in queuedSongs.Where(x => x.songQueueState == SongQueueState.Downloading || x.songQueueState == SongQueueState.Queued)) { song.songQueueState = SongQueueState.Error; } Refresh(); allSongsDownloaded?.Invoke(); }
public static void MatchSongsForAllPlaylists(bool matchAll = false) { Logger.Log("Matching songs for all playlists!"); Task.Run(() => { for (int i = 0; i < loadedPlaylists.Count; i++) { MatchSongsForPlaylist(loadedPlaylists[i], matchAll); } }); }
public static void MatchSongsForPlaylist(Playlist playlist, bool matchAll = false) { if (!SongLoader.AreSongsLoaded || SongLoader.AreSongsLoading || playlist.playlistTitle == "All songs" || playlist.playlistTitle == "Your favorite songs") { return; } Logger.Log("Started matching songs for playlist \"" + playlist.playlistTitle + "\"..."); if (!playlist.songs.All(x => x.level != null) || matchAll) { Stopwatch execTime = new Stopwatch(); execTime.Start(); playlist.songs.AsParallel().ForAll(x => { if (x.level == null || matchAll) { try { if (!string.IsNullOrEmpty(x.levelId)) //check that we have levelId and if we do, try to match level { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.levelID == x.levelId); } if (x.level == null && !string.IsNullOrEmpty(x.hash)) //if level is still null, check that we have hash and if we do, try to match level { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.levelID.StartsWith(x.hash.ToUpper())); } if (x.level == null && !string.IsNullOrEmpty(x.key)) //if level is still null, check that we have key and if we do, try to match level { ScrappedSong song = ScrappedData.Songs.FirstOrDefault(z => z.Key == x.key); if (song != null) { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.levelID.StartsWith(song.Hash)); } else { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.customSongInfo.path.Contains(x.key)); } } } catch (Exception e) { Logger.Warning($"Unable to match song with {(string.IsNullOrEmpty(x.key) ? " unknown key!" : ("key " + x.key + " !"))} Exception: {e}"); } } }); Logger.Log($"Matched all songs for playlist \"{playlist.playlistTitle}\"! Time: {execTime.Elapsed.TotalSeconds.ToString("0.00")}s"); execTime.Reset(); } }
private async Task ExtractZipAsync(Song songInfo, Stream zipStream, string customSongsPath) { try { Logger.Log("Extracting..."); _extractingZip = true; ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Read); await Task.Run(() => archive.ExtractToDirectory(customSongsPath)).ConfigureAwait(false); archive.Dispose(); } catch (Exception e) { Logger.Exception($"Unable to extract ZIP! Exception: {e}"); songInfo.songQueueState = SongQueueState.Error; _extractingZip = false; return; } zipStream.Close(); songInfo.path = Directory.GetDirectories(customSongsPath).FirstOrDefault(); if (string.IsNullOrEmpty(songInfo.path)) { songInfo.path = customSongsPath; } _extractingZip = false; songInfo.songQueueState = SongQueueState.Downloaded; _alreadyDownloadedSongs.Add(songInfo); Logger.Log($"Extracted {songInfo.songName} {songInfo.songSubName}!"); HMMainThreadDispatcher.instance.Enqueue(() => { try { string dirName = new DirectoryInfo(customSongsPath).Name; #if DEBUG Logger.Log("Original path: " + customSongsPath); Logger.Log("Folder name: " + dirName); #endif SongLoader.Instance.RetrieveNewSong(dirName); } catch (Exception e) { Logger.Exception("Unable to load song! Exception: " + e); } }); }
public IEnumerator SavePlaylistCoroutine(string path = "") { Logger.Log($"Saving playlist \"{playlistTitle}\"..."); try { if (icon != null) { image = Sprites.SpriteToBase64(icon); } else { image = null; } playlistSongCount = songs.Count; } catch (Exception e) { Logger.Exception("Unable to save playlist! Exception: " + e); yield break; } // match key if we can, not really that important anymore if (SongDataCore.Plugin.BeatSaver.Data.Songs.Count > 0) { foreach (PlaylistSong song in songs) { yield return(song.MatchKey()); } } try { if (!string.IsNullOrEmpty(path)) { fileLoc = Path.GetFullPath(path); } File.WriteAllText(fileLoc, JsonConvert.SerializeObject(this, Formatting.Indented)); Logger.Log("Playlist saved!"); } catch (Exception e) { Logger.Exception("Unable to save playlist! Exception: " + e); yield break; } }
public void Refresh() { int removed = queuedSongs.RemoveAll(x => x.songQueueState == SongQueueState.Downloaded || x.songQueueState == SongQueueState.Error); Logger.Log($"Removed {removed} songs from queue"); _queuedSongsTableView.ReloadData(); _queuedSongsTableView.ScrollToCellWithIdx(0, TableViewScroller.ScrollPositionType.Beginning, true); if (queuedSongs.Count(x => x.songQueueState == SongQueueState.Downloading || x.songQueueState == SongQueueState.Queued) == 0) { Logger.Log("All songs downloaded!"); allSongsDownloaded?.Invoke(); } if (queuedSongs.Count(x => x.songQueueState == SongQueueState.Downloading) < PluginConfig.maxSimultaneousDownloads && queuedSongs.Any(x => x.songQueueState == SongQueueState.Queued)) { StartCoroutine(DownloadSong(queuedSongs.First(x => x.songQueueState == SongQueueState.Queued))); } }
public IEnumerator DownloadPlaylist(Playlist playlist) { PlaylistsCollection.MatchSongsForPlaylist(playlist, true); List <PlaylistSong> needToDownload = playlist.songs.Where(x => x.level == null).ToList(); Logger.Log($"Need to download {needToDownload.Count} songs"); _downloadingPlaylist = true; foreach (var item in needToDownload) { Song beatSaverSong = null; if (String.IsNullOrEmpty(playlist.customArchiveUrl)) { Logger.Log("Obtaining hash and url for " + item.key + ": " + item.songName); yield return(GetInfoForSong(playlist, item, (Song song) => { beatSaverSong = song; })); } else { string archiveUrl = playlist.customArchiveUrl.Replace("[KEY]", item.key); beatSaverSong = new Song() { songName = item.songName, id = item.key, downloadingProgress = 0f, hash = (item.levelId == null ? "" : item.levelId), downloadUrl = archiveUrl }; } if (beatSaverSong != null && !SongLoader.CustomLevels.Any(x => x.levelID.Substring(0, 32) == beatSaverSong.hash.ToUpper())) { _downloadQueueViewController.EnqueueSong(beatSaverSong, true); } } _downloadingPlaylist = false; }
public IEnumerator RequestSongByKeyCoroutine(string key, Action <Song> callback) { UnityWebRequest wwwId = UnityWebRequest.Get($"{PluginConfig.beatsaverURL}/api/songs/detail/" + key); wwwId.timeout = 10; yield return(wwwId.SendWebRequest()); if (wwwId.isNetworkError || wwwId.isHttpError) { Logger.Error(wwwId.error); } else { #if DEBUG Logger.Log("Received response from BeatSaver..."); #endif JSONNode node = JSON.Parse(wwwId.downloadHandler.text); Song _tempSong = new Song(node["song"]); callback?.Invoke(_tempSong); } }
public Playlist(JSONNode playlistNode) { string image = playlistNode["image"].Value; // If we cannot find an image or parse the provided one correctly, fall back to anything. // It will never be displayed by SongBrowser. if (!string.IsNullOrEmpty(image)) { try { icon = Sprites.Base64ToSprite(image.Substring(image.IndexOf(",") + 1)); } catch { Logger.Exception("Unable to convert playlist image to sprite!"); icon = Sprites.StarFullIcon; } } else { icon = Sprites.StarFullIcon; } playlistTitle = playlistNode["playlistTitle"]; playlistAuthor = playlistNode["playlistAuthor"]; customDetailUrl = playlistNode["customDetailUrl"]; customArchiveUrl = playlistNode["customArchiveUrl"]; if (!string.IsNullOrEmpty(customDetailUrl)) { if (!customDetailUrl.EndsWith("/")) { customDetailUrl += "/"; } Logger.Log("Found playlist with customDetailUrl! Name: " + playlistTitle + ", CustomDetailUrl: " + customDetailUrl); } if (!string.IsNullOrEmpty(customArchiveUrl) && customArchiveUrl.Contains("[KEY]")) { Logger.Log("Found playlist with customArchiveUrl! Name: " + playlistTitle + ", CustomArchiveUrl: " + customArchiveUrl); } songs = new List <PlaylistSong>(); foreach (JSONNode node in playlistNode["songs"].AsArray) { PlaylistSong song = new PlaylistSong(); song.key = node["key"]; song.songName = node["songName"]; song.hash = node["hash"]; song.levelId = node["levelId"]; songs.Add(song); } if (playlistNode["playlistSongCount"] != null) { playlistSongCount = playlistNode["playlistSongCount"].AsInt; } if (playlistNode["fileLoc"] != null) { fileLoc = playlistNode["fileLoc"]; } if (playlistNode["playlistURL"] != null) { fileLoc = playlistNode["playlistURL"]; } }
public void Awake() { _keyButtonPrefab = Resources.FindObjectsOfTypeAll <TextMeshProButton>().First(x => x.name == "KeyboardButton"); Logger.Log("Found keyboard button!"); string[] array = new string[] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", "<-", "space", "OK", "Cancel" }; for (int i = 0; i < array.Length; i++) { RectTransform parent = transform.GetChild(i) as RectTransform; //TextMeshProButton textMeshProButton = Instantiate(_keyButtonPrefab, parent); TextMeshProButton textMeshProButton = parent.GetComponentInChildren <TextMeshProButton>(); textMeshProButton.text.text = array[i]; RectTransform rectTransform = textMeshProButton.transform as RectTransform; rectTransform.localPosition = Vector2.zero; rectTransform.localScale = Vector3.one; rectTransform.anchoredPosition = Vector2.zero; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector3.one; rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; Navigation navigation = textMeshProButton.button.navigation; navigation.mode = Navigation.Mode.None; textMeshProButton.button.navigation = navigation; textMeshProButton.button.onClick.RemoveAllListeners(); if (i < array.Length - 4) { string key = array[i]; textMeshProButton.button.onClick.AddListener(delegate() { textKeyWasPressedEvent?.Invoke(key[0]); }); } else if (i == array.Length - 4) { textMeshProButton.button.onClick.AddListener(delegate() { deleteButtonWasPressedEvent?.Invoke(); }); } else if (i == array.Length - 1) { (textMeshProButton.transform as RectTransform).sizeDelta = new Vector2(7f, 1.5f); _cancelButton = textMeshProButton.button; _cancelButton.gameObject.SetActive(!HideCancelButton); textMeshProButton.button.onClick.AddListener(delegate() { cancelButtonWasPressedEvent?.Invoke(); }); } else if (i == array.Length - 2) { _okButton = textMeshProButton.button; _okButton.interactable = OkButtonInteractivity; textMeshProButton.button.onClick.AddListener(delegate() { okButtonWasPressedEvent?.Invoke(); }); } else { textMeshProButton.button.onClick.AddListener(delegate() { textKeyWasPressedEvent?.Invoke(' '); }); } } name = "CustomUIKeyboard"; (transform as RectTransform).anchoredPosition -= new Vector2(0f, 0f); for (int i = 1; i <= 10; i++) { TextMeshProButton textButton = Instantiate(_keyButtonPrefab); textButton.text.text = (i % 10).ToString(); string key = (i % 10).ToString(); textButton.button.onClick.AddListener(delegate() { textKeyWasPressedEvent?.Invoke(key[0]); }); RectTransform buttonRect = textButton.GetComponent <RectTransform>(); RectTransform component2 = transform.GetChild(i - 1).gameObject.GetComponent <RectTransform>(); RectTransform buttonHolder = Instantiate(component2, component2.parent, false); Destroy(buttonHolder.GetComponentInChildren <Button>().gameObject); buttonHolder.anchoredPosition -= new Vector2(0f, -10.5f); buttonRect.SetParent(buttonHolder, false); buttonRect.localPosition = Vector2.zero; buttonRect.localScale = Vector3.one; buttonRect.anchoredPosition = Vector2.zero; buttonRect.anchorMin = Vector2.zero; buttonRect.anchorMax = Vector3.one; buttonRect.offsetMin = Vector2.zero; buttonRect.offsetMax = Vector2.zero; } }
public IEnumerator DownloadSongCoroutine(Song songInfo) { songInfo.songQueueState = SongQueueState.Downloading; UnityWebRequest www; bool timeout = false; float time = 0f; UnityWebRequestAsyncOperation asyncRequest; try { www = UnityWebRequest.Get(songInfo.downloadUrl); asyncRequest = www.SendWebRequest(); } catch (Exception e) { Logger.Error(e); songInfo.songQueueState = SongQueueState.Error; songInfo.downloadingProgress = 1f; yield break; } while ((!asyncRequest.isDone || songInfo.downloadingProgress < 1f) && songInfo.songQueueState != SongQueueState.Error) { yield return(null); time += Time.deltaTime; if (time >= 5f && asyncRequest.progress <= float.Epsilon) { www.Abort(); timeout = true; Logger.Error("Connection timed out!"); } songInfo.downloadingProgress = asyncRequest.progress; } if (songInfo.songQueueState == SongQueueState.Error && (!asyncRequest.isDone || songInfo.downloadingProgress < 1f)) { www.Abort(); } if (www.isNetworkError || www.isHttpError || timeout || songInfo.songQueueState == SongQueueState.Error) { songInfo.songQueueState = SongQueueState.Error; Logger.Error("Unable to download song! " + (www.isNetworkError ? $"Network error: {www.error}" : (www.isHttpError ? $"HTTP error: {www.error}" : "Unknown error"))); } else { Logger.Log("Received response from BeatSaver.com..."); string docPath = ""; string customSongsPath = ""; byte[] data = www.downloadHandler.data; Stream zipStream = null; try { docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); customSongsPath = docPath + "/CustomSongs/" + songInfo.id + "/"; if (!Directory.Exists(customSongsPath)) { Directory.CreateDirectory(customSongsPath); } zipStream = new MemoryStream(data); Logger.Log("Downloaded zip!"); } catch (Exception e) { Logger.Exception(e); songInfo.songQueueState = SongQueueState.Error; yield break; } yield return(new WaitWhile(() => _extractingZip)); //because extracting several songs at once sometimes hangs the game Task extract = ExtractZipAsync(songInfo, zipStream, customSongsPath); yield return(new WaitWhile(() => !extract.IsCompleted)); songDownloaded?.Invoke(songInfo); } }
public static void ReloadPlaylists(bool fullRefresh = true) { try { List <string> playlistFiles = new List <string>(); if (PluginConfig.beatDropInstalled) { String beatDropPath = Path.Combine(PluginConfig.beatDropPlaylistsLocation, "playlists"); if (Directory.Exists(beatDropPath)) { string[] beatDropJSONPlaylists = Directory.GetFiles(beatDropPath, "*.json"); string[] beatDropBPLISTPlaylists = Directory.GetFiles(beatDropPath, "*.bplist"); playlistFiles.AddRange(beatDropJSONPlaylists); playlistFiles.AddRange(beatDropBPLISTPlaylists); Logger.Log($"Found {beatDropJSONPlaylists.Length + beatDropBPLISTPlaylists.Length} playlists in BeatDrop folder"); } } string[] localJSONPlaylists = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.json"); string[] localBPLISTPlaylists = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.bplist"); playlistFiles.AddRange(localJSONPlaylists); playlistFiles.AddRange(localBPLISTPlaylists); Logger.Log($"Found {localJSONPlaylists.Length + localBPLISTPlaylists.Length} playlists in Playlists folder"); if (fullRefresh) { loadedPlaylists.Clear(); foreach (string path in playlistFiles) { try { Playlist playlist = Playlist.LoadPlaylist(path); if (Path.GetFileName(path) == "favorites.json" && playlist.playlistTitle == "Your favorite songs") { continue; } loadedPlaylists.Add(playlist); Logger.Log($"Found \"{playlist.playlistTitle}\" by {playlist.playlistAuthor}"); } catch (Exception e) { Logger.Log($"Unable to parse playlist @ {path}! Exception: {e}"); } } } else { foreach (string path in playlistFiles) { if (!loadedPlaylists.Any(x => x.fileLoc == path)) { Logger.Log("Found new playlist! Path: " + path); try { Playlist playlist = Playlist.LoadPlaylist(path); if (Path.GetFileName(path) == "favorites.json" && playlist.playlistTitle == "Your favorite songs") { continue; } loadedPlaylists.Add(playlist); Logger.Log($"Found \"{playlist.playlistTitle}\" by {playlist.playlistAuthor}"); if (SongLoader.AreSongsLoaded) { MatchSongsForPlaylist(playlist); } } catch (Exception e) { Logger.Log($"Unable to parse playlist @ {path}! Exception: {e}"); } } } } } catch (Exception e) { Logger.Exception("Unable to load playlists! Exception: " + e); } }
public bool DeleteSong(Song song) { bool zippedSong = false; string path = ""; CustomLevel level = SongLoader.CustomLevels.FirstOrDefault(x => x.levelID.StartsWith(song.hash)); if (string.IsNullOrEmpty(song.path)) { if (level != null) { path = level.customSongInfo.path; } } else { path = song.path; } if (string.IsNullOrEmpty(path)) { return(false); } if (!Directory.Exists(path)) { return(false); } if (path.Contains("/.cache/")) { zippedSong = true; } if (zippedSong) { Logger.Log("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } string songHash = Directory.GetParent(path).Name; try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Can't find or delete empty folder!"); } string docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); string customSongsPath = docPath + "/CustomSongs/"; string hash = ""; foreach (string file in Directory.GetFiles(customSongsPath, "*.zip")) { if (CreateMD5FromFile(file, out hash)) { if (hash == songHash) { File.Delete(file); break; } } } } else { Logger.Log("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Unable to delete empty folder!"); } } if (level != null) { SongLoader.Instance.RemoveSongWithLevelID(level.levelID); } Logger.Log($"{_alreadyDownloadedSongs.RemoveAll(x => x.Compare(song))} song removed"); return(true); }
public static void LoadOrCreateConfig() { if (!Directory.Exists("UserData")) { Directory.CreateDirectory("UserData"); } if (!ModPrefs.HasKey("BeatSaverDownloader", "beatsaverURL")) { ModPrefs.SetString("BeatSaverDownloader", "beatsaverURL", "https://beatsaver.com"); Logger.Log("Created config"); } else { beatsaverURL = ModPrefs.GetString("BeatSaverDownloader", "beatsaverURL"); if (string.IsNullOrEmpty(beatsaverURL)) { ModPrefs.SetString("BeatSaverDownloader", "beatsaverURL", "https://beatsaver.com"); beatsaverURL = "https://beatsaver.com"; Logger.Log("Created config"); } } if (!ModPrefs.HasKey("BeatSaverDownloader", "disableDeleteButton")) { ModPrefs.SetBool("BeatSaverDownloader", "disableDeleteButton", false); } else { disableDeleteButton = ModPrefs.GetBool("BeatSaverDownloader", "disableDeleteButton", false, true); } if (!ModPrefs.HasKey("BeatSaverDownloader", "deleteToRecycleBin")) { ModPrefs.SetBool("BeatSaverDownloader", "deleteToRecycleBin", true); } else { deleteToRecycleBin = ModPrefs.GetBool("BeatSaverDownloader", "deleteToRecycleBin", true, true); } if (!ModPrefs.HasKey("BeatSaverDownloader", "maxSimultaneousDownloads")) { ModPrefs.SetInt("BeatSaverDownloader", "maxSimultaneousDownloads", 3); } else { maxSimultaneousDownloads = ModPrefs.GetInt("BeatSaverDownloader", "maxSimultaneousDownloads", 3, true); } /*if (!File.Exists(configPath)) * { * File.Create(configPath).Close(); * } * * favoriteSongs.AddRange(File.ReadAllLines(configPath, Encoding.UTF8)); */ try { if (Registry.CurrentUser.OpenSubKey(@"Software").GetSubKeyNames().Contains("178eef3d-4cea-5a1b-bfd0-07a21d068990")) { beatDropPlaylistsLocation = (string)Registry.CurrentUser.OpenSubKey(@"Software\178eef3d-4cea-5a1b-bfd0-07a21d068990").GetValue("InstallLocation", ""); if (Directory.Exists(beatDropPlaylistsLocation)) { beatDropInstalled = true; } else if (Directory.Exists("%LocalAppData%\\Programs\\BeatDrop\\playlists")) { beatDropInstalled = true; beatDropPlaylistsLocation = "%LocalAppData%\\Programs\\BeatDrop\\playlists"; } else { beatDropInstalled = false; beatDropPlaylistsLocation = ""; } } } catch (Exception e) { Logger.Log($"Can't open registry key! Exception: {e}"); if (Directory.Exists("%LocalAppData%\\Programs\\BeatDrop\\playlists")) { beatDropInstalled = true; beatDropPlaylistsLocation = "%LocalAppData%\\Programs\\BeatDrop\\playlists"; } else { Logger.Log("Unable to find BeatDrop installation folder!"); } } if (!Directory.Exists("Playlists")) { Directory.CreateDirectory("Playlists"); } }
public Playlist(JSONNode playlistNode) { string image = playlistNode["image"].Value; if (!string.IsNullOrEmpty(image)) { try { icon = Sprites.Base64ToSprite(image.Substring(image.IndexOf(",") + 1)); } catch { Logger.Exception("Unable to convert playlist image to sprite!"); icon = Sprites.BeastSaberLogo; } } else { icon = Sprites.BeastSaberLogo; } playlistTitle = playlistNode["playlistTitle"]; playlistAuthor = playlistNode["playlistAuthor"]; customDetailUrl = playlistNode["customDetailUrl"]; customArchiveUrl = playlistNode["customArchiveUrl"]; if (!string.IsNullOrEmpty(customDetailUrl)) { if (!customDetailUrl.EndsWith("/")) { customDetailUrl += "/"; } Logger.Log("Found playlist with customDetailUrl! Name: " + playlistTitle + ", CustomDetailUrl: " + customDetailUrl); } if (!string.IsNullOrEmpty(customArchiveUrl) && customArchiveUrl.Contains("[KEY]")) { Logger.Log("Found playlist with customArchiveUrl! Name: " + playlistTitle + ", CustomArchiveUrl: " + customArchiveUrl); } songs = new List <PlaylistSong>(); foreach (JSONNode node in playlistNode["songs"].AsArray) { PlaylistSong song = new PlaylistSong(); song.key = node["key"]; song.songName = node["songName"]; song.hash = node["hash"]; song.levelId = node["levelId"]; songs.Add(song); } if (playlistNode["playlistSongCount"] != null) { playlistSongCount = playlistNode["playlistSongCount"].AsInt; } if (playlistNode["fileLoc"] != null) { fileLoc = playlistNode["fileLoc"]; } if (playlistNode["playlistURL"] != null) { fileLoc = playlistNode["playlistURL"]; } }