public static async void AddSongToQueueByKey(string songKey, int channelId) { SongInfo info = await BeatSaver.InfoFromID(songKey); if (info != null) { radioChannels[channelId].radioQueue.Enqueue(info); Logger.Instance.Log("Successfully added songs to the queue!"); File.WriteAllText($"RadioQueue{channelId}.json", JsonConvert.SerializeObject(radioChannels[channelId].radioQueue, Formatting.Indented)); } }
public static async void AddPlaylistToQueue(string path, int channelId) { bool remotePlaylist = path.ToLower().Contains("http://") || path.ToLower().Contains("https://"); Playlist playlist = null; if (remotePlaylist) { using (WebClient w = new WebClient()) { w.Headers.Add("user-agent", $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}/{System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}"); try { string response = await w.DownloadStringTaskAsync(path); playlist = JsonConvert.DeserializeObject <Playlist>(response); } catch (Exception e) { Logger.Instance.Error("Unable to add playlist to queue! Exception: " + e); return; } } } else { try { string fullPath = Path.GetFullPath(path); if (File.Exists(fullPath)) { string content = await File.ReadAllTextAsync(fullPath); playlist = JsonConvert.DeserializeObject <Playlist>(content); } else { Logger.Instance.Error($"Unable to add playlist to queue! File \"{path}\" does not exist!"); return; } } catch (Exception e) { Logger.Instance.Error("Unable to add playlist to queue! Exception: " + e); return; } } try { foreach (PlaylistSong song in playlist.songs) { if (song == null) { continue; } if (!string.IsNullOrEmpty(song.hash)) { if (song.hash.Length >= 40) { radioChannels[channelId].radioQueue.Enqueue(new SongInfo() { levelId = song.hash.ToUpper().Substring((song.hash.Length - 40), 40), songName = song.songName, key = song.key }); continue; } } if (!string.IsNullOrEmpty(song.levelId)) { if (song.levelId.Length >= 40) { radioChannels[channelId].radioQueue.Enqueue(new SongInfo() { levelId = song.levelId.ToUpper().Substring((song.hash.Length - 40), 40), songName = song.songName, key = song.key }); continue; } } if (!string.IsNullOrEmpty(song.key)) { SongInfo info = await BeatSaver.InfoFromID(song.key); if (info != null) { radioChannels[channelId].radioQueue.Enqueue(info); } continue; } } Logger.Instance.Log("Successfully added all songs from playlist to the queue!"); File.WriteAllText($"RadioQueue{channelId}.json", JsonConvert.SerializeObject(radioChannels[channelId].radioQueue, Formatting.Indented)); } catch (Exception e) { Logger.Instance.Error("Unable to add playlist to queue! Exception: " + e); return; } }