public async Task SkipToNextSong() { await DesktopSongRequestService.songRequestLock.WaitAsync(); if (this.allRequests.Count > 0) { SongRequestItem request = this.allRequests.FirstOrDefault(); if (request.Type == SongRequestServiceTypeEnum.Spotify) { await ChannelSession.Services.Spotify.PauseCurrentlyPlaying(); } else if (request.Type == SongRequestServiceTypeEnum.YouTube || request.Type == SongRequestServiceTypeEnum.SoundCloud) { await this.StopOverlaySong(request.Type); } this.allRequests.RemoveAt(0); } if (this.allRequests.Count > 0) { await this.PlaySong(this.allRequests.FirstOrDefault()); } DesktopSongRequestService.songRequestLock.Release(); GlobalEvents.SongRequestsChangedOccurred(); }
private async Task PlaySongInternal(SongRequestItem item) { if (item != null) { if (item.Type == SongRequestServiceTypeEnum.Spotify) { if (ChannelSession.Services.Spotify != null) { SpotifySong song = await ChannelSession.Services.Spotify.GetSong(item.ID); if (song != null) { await ChannelSession.Services.Spotify.PlaySong(song); this.currentSong = item; } } } else if (item.Type == SongRequestServiceTypeEnum.YouTube) { this.currentSong = item; await this.youTubeContext.PlaySong(item.ID, ChannelSession.Settings.SongRequestVolume); } } }
public async Task PlayPauseCurrentSong() { if (this.allRequests.Count > 0) { await DesktopSongRequestService.songRequestLock.WaitAsync(); SongRequestItem request = this.allRequests.FirstOrDefault(); if (request.Type == SongRequestServiceTypeEnum.Spotify) { if (ChannelSession.Services.Spotify != null) { SpotifyCurrentlyPlaying currentlyPlaying = await ChannelSession.Services.Spotify.GetCurrentlyPlaying(); if (currentlyPlaying != null && currentlyPlaying.ID != null) { if (currentlyPlaying.IsPlaying) { await ChannelSession.Services.Spotify.PauseCurrentlyPlaying(); } else { await ChannelSession.Services.Spotify.PlayCurrentlyPlaying(); } } } } else if (request.Type == SongRequestServiceTypeEnum.YouTube || request.Type == SongRequestServiceTypeEnum.SoundCloud) { await this.PlayPauseOverlaySong(request.Type); } DesktopSongRequestService.songRequestLock.Release(); } }
private async Task PlaySongInternal(SongRequestItem item) { if (item != null) { if (item.Type == SongRequestServiceTypeEnum.Spotify) { if (ChannelSession.Services.Spotify != null) { SpotifySong song = await ChannelSession.Services.Spotify.GetSong(item.ID); if (song != null) { await ChannelSession.Services.Spotify.PlaySong(song); this.currentSong = item; } } } else if (item.Type == SongRequestServiceTypeEnum.YouTube) { IOverlayService overlay = ChannelSession.Services.OverlayServers.GetOverlay(ChannelSession.Services.OverlayServers.DefaultOverlayName); if (overlay != null) { await overlay.SendSongRequest(new OverlaySongRequest() { Type = SongRequestServiceTypeEnum.YouTube.ToString(), Action = "song", Source = item.ID, Volume = ChannelSession.Settings.SongRequestVolume }); this.currentSong = item; } } } }
public async Task RemoveSongRequest(SongRequestItem song) { await DesktopSongRequestService.songRequestLock.WaitAsync(); this.allRequests.Remove(song); DesktopSongRequestService.songRequestLock.Release(); GlobalEvents.SongRequestsChangedOccurred(); }
private async Task PlayOverlaySong(SongRequestItem request) { if (ChannelSession.Services.OverlayServer != null) { await ChannelSession.Services.OverlayServer.SendSongRequest(new OverlaySongRequest() { Type = request.Type.ToString(), Action = "song", Source = request.ID }); } }
public async Task RemoveSongRequest(SongRequestItem song) { await SongRequestService.songRequestLock.WaitAndRelease(() => { this.allRequests.Remove(song); return(Task.FromResult(0)); }); GlobalEvents.SongRequestsChangedOccurred(); }
public Task <SongRequestItem> GetNextTrack() { SongRequestItem result = null; if (this.allRequests.Count > 1) { result = this.allRequests.Skip(1).FirstOrDefault(); } return(Task.FromResult(result)); }
private async void DeleteQueueButton_Click(object sender, RoutedEventArgs e) { await this.Window.RunAsyncOperation(async () => { Button button = (Button)sender; SongRequestItem songRequest = (SongRequestItem)button.DataContext; await ChannelSession.Services.SongRequestService.RemoveSongRequest(songRequest); await this.RefreshRequestsList(); }); }
public override async Task <OverlayItemBase> GetProcessedItem(UserViewModel user, IEnumerable <string> arguments, Dictionary <string, string> extraSpecialIdentifiers) { if (ChannelSession.Services.SongRequestService != null && this.songRequestsUpdated) { this.songRequestsUpdated = false; List <SongRequestItem> songRequests = new List <SongRequestItem>(); SongRequestItem currentlyPlaying = await ChannelSession.Services.SongRequestService.GetCurrentlyPlaying(); if (currentlyPlaying != null) { songRequests.Add(currentlyPlaying); } IEnumerable <SongRequestItem> allSongRequests = this.testSongRequestsList; if (this.testSongRequestsList.Count == 0) { allSongRequests = await ChannelSession.Services.SongRequestService.GetAllRequests(); } foreach (SongRequestItem songRequest in allSongRequests) { if (!songRequests.Any(sr => sr.Equals(songRequest))) { songRequests.Add(songRequest); } } this.SongRequestUpdates.Clear(); this.currentSongRequests.Clear(); OverlaySongRequests copy = this.Copy <OverlaySongRequests>(); for (int i = 0; i < songRequests.Count() && i < this.TotalToShow; i++) { this.currentSongRequests.Add(songRequests.ElementAt(i)); } while (this.currentSongRequests.Count > 0) { OverlayCustomHTMLItem overlayItem = (OverlayCustomHTMLItem)await base.GetProcessedItem(user, arguments, extraSpecialIdentifiers); copy.SongRequestUpdates.Add(new OverlaySongRequestItem() { HTMLText = overlayItem.HTMLText }); this.currentSongRequests.RemoveAt(0); } return(copy); } return(null); }
private async Task SkipToNextSongInternal() { if (this.allRequests.Count > 0 && this.allRequests.First().Equals(this.currentSong)) { this.allRequests.RemoveAt(0); } else if (this.playlistItems.Count > 0 && this.playlistItems.First().Equals(this.currentSong)) { this.playlistItems.RemoveAt(0); } if (this.currentSong != null) { if (this.currentSong.Type == SongRequestServiceTypeEnum.Spotify) { await ChannelSession.Services.Spotify.PauseCurrentlyPlaying(); this.spotifyStatus = null; } else if (this.currentSong.Type == SongRequestServiceTypeEnum.YouTube) { IOverlayService overlay = ChannelSession.Services.OverlayServers.GetOverlay(ChannelSession.Services.OverlayServers.DefaultOverlayName); if (overlay != null) { await overlay.SendSongRequest(new OverlaySongRequest() { Type = SongRequestServiceTypeEnum.YouTube.ToString(), Action = "stop", Volume = ChannelSession.Settings.SongRequestVolume }); this.youTubeStatus = null; } } this.currentSong.State = SongRequestStateEnum.Ended; this.currentSong = null; } SongRequestItem newSong = null; if (this.allRequests.Count > 0) { newSong = this.allRequests.First(); } else if (this.playlistItems.Count > 0) { newSong = this.playlistItems.First(); } if (newSong != null) { await this.PlaySongInternal(newSong); } }
public Task StatusUpdate(SongRequestItem item) { if (item != null) { if (item.Type == SongRequestServiceTypeEnum.YouTube && !string.IsNullOrEmpty(item.ID)) { this.youTubeStatus = item; this.youTubeStatus.ID = Regex.Replace(this.youTubeStatus.ID, YouTubeFullLinkWithTimePattern, ""); this.youTubeStatus.ID = this.youTubeStatus.ID.Replace(YouTubeFullLinkPrefix, ""); } } return(Task.FromResult(0)); }
private void ReplaceSongRequestSpecialIdentifiers(string header, SongRequestItem song) { if (song != null) { this.ReplaceSpecialIdentifier(header + "title", song.Name); this.ReplaceSpecialIdentifier(header + "username", (song.User != null && !string.IsNullOrEmpty(song.User.UserName)) ? song.User.UserName : "******"); this.ReplaceSpecialIdentifier(header + "albumimage", (song.AlbumImage != null) ? song.AlbumImage : string.Empty); } else { this.ReplaceSpecialIdentifier(header + "title", "No Song"); this.ReplaceSpecialIdentifier(header + "username", "Nobody"); this.ReplaceSpecialIdentifier(header + "albumimage", string.Empty); } }
private async Task RefreshRequestsList() { await SongRequestControl.songListLock.WaitAndRelease(async () => { this.EnableSongRequestsToggleButton.IsChecked = ChannelSession.Services.SongRequestService.IsEnabled; this.SongRequestServicesGrid.IsEnabled = !ChannelSession.Services.SongRequestService.IsEnabled; this.DefaultPlaylistURL.IsEnabled = !ChannelSession.Services.SongRequestService.IsEnabled; this.CurrentlyPlayingAndSongQueueGrid.IsEnabled = ChannelSession.Services.SongRequestService.IsEnabled; this.ClearQueueButton.IsEnabled = ChannelSession.Services.SongRequestService.IsEnabled; SongRequestItem currentSong = await ChannelSession.Services.SongRequestService.GetCurrentlyPlaying(); if (currentSong != null) { CurrentSongName.Text = currentSong.Name; } else { CurrentSongName.Text = "None"; } this.requestPlaylist.Clear(); IEnumerable<SongRequestItem> requests = await ChannelSession.Services.SongRequestService.GetAllRequests(); if (requests.Count() > 0) { if (!requests.First().Equals(currentSong)) { this.requestPlaylist.Add(requests.First()); } foreach (SongRequestItem item in requests.Skip(1)) { this.requestPlaylist.Add(item); } } if (currentSong != null && (requests.Count() == 0 || !requests.First().Equals(currentSong))) { this.SongTypeIdentifierTextBlock.Text = "Playlist Song:"; } else { this.SongTypeIdentifierTextBlock.Text = "Current Song:"; } }); }
private async Task PlayerBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); bool shouldSkip = false; await DesktopSongRequestService.songRequestLock.WaitAsync(); SongRequestItem current = this.allRequests.FirstOrDefault(); if (current != null) { if (current.Type == SongRequestServiceTypeEnum.Spotify) { if (ChannelSession.Services.Spotify != null) { SpotifyCurrentlyPlaying currentlyPlaying = await ChannelSession.Services.Spotify.GetCurrentlyPlaying(); if (currentlyPlaying == null || currentlyPlaying.ID == null || !currentlyPlaying.ID.Equals(current.ID) || (!currentlyPlaying.IsPlaying && currentlyPlaying.CurrentProgress == 0)) { shouldSkip = true; } } } else if (current.Type == SongRequestServiceTypeEnum.YouTube || current.Type == SongRequestServiceTypeEnum.SoundCloud) { if (this.overlaySongFinished) { this.overlaySongFinished = false; shouldSkip = true; } } } DesktopSongRequestService.songRequestLock.Release(); if (shouldSkip) { await this.SkipToNextSong(); } await Task.Delay(2000); }); }
private async Task SkipToNextSongInternal() { if (this.allRequests.Count > 0 && this.allRequests.First().Equals(this.currentSong)) { this.allRequests.RemoveAt(0); } else if (this.playlistItems.Count > 0 && this.playlistItems.First().Equals(this.currentSong)) { this.playlistItems.RemoveAt(0); } if (this.currentSong != null) { if (this.currentSong.Type == SongRequestServiceTypeEnum.Spotify) { await ChannelSession.Services.Spotify.PauseCurrentlyPlaying(); this.spotifyStatus = null; } else if (this.currentSong.Type == SongRequestServiceTypeEnum.YouTube) { await this.youTubeContext.Stop(); } this.currentSong.State = SongRequestStateEnum.Ended; this.currentSong = null; } SongRequestItem newSong = null; if (this.allRequests.Count > 0) { newSong = this.allRequests.First(); } else if (this.playlistItems.Count > 0) { newSong = this.playlistItems.First(); } if (newSong != null) { await this.PlaySongInternal(newSong); } }
private async Task <SongRequestItem> GetYouTubeStatus() { IOverlayService overlay = ChannelSession.Services.OverlayServers.GetOverlay(ChannelSession.Services.OverlayServers.DefaultOverlayName); if (overlay != null) { this.youTubeStatus = null; await overlay.SendSongRequest(new OverlaySongRequest() { Type = SongRequestServiceTypeEnum.YouTube.ToString(), Action = "status" }); for (int i = 0; i < 10 && this.youTubeStatus == null; i++) { await Task.Delay(500); } } return(this.youTubeStatus); }
public async Task <SongRequestItem> GetStatus() { this.status = null; if (this.httpListenerServer != null) { await this.dispatcher.InvokeAsync(() => { this.browser.InvokeScript("getStatus"); }); for (int i = 0; i < 10 && this.status == null; i++) { await Task.Delay(500); } } return(status); }
protected override Task <Dictionary <string, string> > GetReplacementSets(UserViewModel user, IEnumerable <string> arguments, Dictionary <string, string> extraSpecialIdentifiers) { SongRequestItem songRequest = this.currentSongRequests.ElementAt(0); Dictionary <string, string> replacementSets = new Dictionary <string, string>(); replacementSets["BACKGROUND_COLOR"] = this.BackgroundColor; replacementSets["BORDER_COLOR"] = this.BorderColor; replacementSets["TEXT_COLOR"] = this.TextColor; replacementSets["TEXT_FONT"] = this.TextFont; replacementSets["WIDTH"] = this.Width.ToString(); replacementSets["HEIGHT"] = this.Height.ToString(); replacementSets["TEXT_SIZE"] = ((int)(0.2 * ((double)this.Height))).ToString(); replacementSets["SONG_IMAGE"] = songRequest.AlbumImage; replacementSets["SONG_IMAGE_SIZE"] = ((int)(0.8 * ((double)this.Height))).ToString(); replacementSets["SONG_NAME"] = songRequest.Name; return(Task.FromResult(replacementSets)); }
public async Task RemoveLastSongRequested() { SongRequestItem song = null; await SongRequestService.songRequestLock.WaitAndRelease(() => { song = this.allRequests.LastOrDefault(); if (song != null) { this.allRequests.Remove(song); } return(Task.FromResult(0)); }); GlobalEvents.SongRequestsChangedOccurred(); if (song != null) { await ChannelSession.Chat.SendMessage(string.Format("{0} was removed from the queue.", song.Name)); GlobalEvents.SongRequestsChangedOccurred(); } }
private async Task PlaySong(SongRequestItem request) { if (request != null) { if (request.Type == SongRequestServiceTypeEnum.Spotify) { if (ChannelSession.Services.Spotify != null) { SpotifySong song = await ChannelSession.Services.Spotify.GetSong(request.ID); if (song != null) { await ChannelSession.Services.Spotify.PlaySong(song); } } } else if (request.Type == SongRequestServiceTypeEnum.YouTube || request.Type == SongRequestServiceTypeEnum.SoundCloud) { await this.PlayOverlaySong(request); } } }
private async Task <SongRequestItem> GetSpotifyStatus() { if (ChannelSession.Services.Spotify != null) { SpotifyCurrentlyPlaying currentlyPlaying = await ChannelSession.Services.Spotify.GetCurrentlyPlaying(); if (currentlyPlaying != null && currentlyPlaying.ID != null) { SongRequestItem result = new SongRequestItem() { Type = SongRequestServiceTypeEnum.Spotify, ID = currentlyPlaying.ID, Progress = currentlyPlaying.CurrentProgress, Length = currentlyPlaying.Duration, AlbumImage = this.GetAlbumArt(SongRequestServiceTypeEnum.Spotify, currentlyPlaying.Album?.ImageLink) }; if (currentlyPlaying.IsPlaying) { result.State = SongRequestStateEnum.Playing; } else if (currentlyPlaying.CurrentProgress > 0) { result.State = SongRequestStateEnum.Paused; } else { result.State = SongRequestStateEnum.Ended; } result.Volume = await ChannelSession.Services.Spotify.GetVolume(); return(result); } } return(null); }
public async Task RemoveLastSongRequestedByUser(UserViewModel user) { SongRequestItem song = null; await SongRequestService.songRequestLock.WaitAndRelease(() => { song = this.allRequests.LastOrDefault(s => s.User.ID == user.ID); if (song != null) { this.allRequests.Remove(song); } return(Task.FromResult(0)); }); if (song != null) { await ChannelSession.Chat.SendMessage(string.Format("{0} was removed from the queue.", song.Name)); GlobalEvents.SongRequestsChangedOccurred(); } else { await ChannelSession.Chat.Whisper(user.UserName, string.Format("You have no songs in the queue.", song.Name)); } }
protected override async Task ProcessReceivedPacket(string packetJSON) { if (!string.IsNullOrEmpty(packetJSON)) { JObject packetObj = JObject.Parse(packetJSON); if (packetObj["type"] != null) { if (packetObj["type"].ToString().Equals("songRequestStatus")) { if (ChannelSession.Services.SongRequestService != null) { SongRequestItem item = null; if (packetObj["data"] != null) { item = packetObj["data"].ToObject <SongRequestItem>(); } await ChannelSession.Services.SongRequestService.StatusUpdate(item); } } } } await base.ProcessReceivedPacket(packetJSON); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Chat != null) { if (this.SongRequestType == SongRequestActionTypeEnum.EnableDisableSongRequests) { if (!ChannelSession.Services.SongRequestService.IsEnabled) { if (!await ChannelSession.Services.SongRequestService.Initialize()) { await ChannelSession.Services.SongRequestService.Disable(); await ChannelSession.Chat.Whisper(user.UserName, "Song Requests were not able to enabled, please try manually enabling it."); return; } } else { await ChannelSession.Services.SongRequestService.Disable(); } } else { if (ChannelSession.Services.SongRequestService == null || !ChannelSession.Services.SongRequestService.IsEnabled) { await ChannelSession.Chat.Whisper(user.UserName, "Song Requests are not currently enabled"); return; } if (this.SongRequestType == SongRequestActionTypeEnum.SearchSongsAndUseArtistSelect) { await ChannelSession.Services.SongRequestService.AddSongRequest(user, this.SpecificService, string.Join(" ", arguments)); } else if (this.SongRequestType == SongRequestActionTypeEnum.SearchSongsAndPickFirstResult) { await ChannelSession.Services.SongRequestService.AddSongRequest(user, this.SpecificService, string.Join(" ", arguments), pickFirst : true); } else if (this.SongRequestType == SongRequestActionTypeEnum.RemoveLast) { await ChannelSession.Services.SongRequestService.RemoveLastSongRequested(); } else if (this.SongRequestType == SongRequestActionTypeEnum.RemoveLastByUser) { await ChannelSession.Services.SongRequestService.RemoveLastSongRequestedByUser(user); } else if (this.SongRequestType == SongRequestActionTypeEnum.SetVolume) { if (arguments != null && arguments.Count() > 0) { string volumeAmount = await this.ReplaceStringWithSpecialModifiers(arguments.First(), user, arguments); if (int.TryParse(volumeAmount, out int volume)) { volume = MathHelper.Clamp(volume, 0, 100); ChannelSession.Settings.SongRequestVolume = volume; await ChannelSession.Services.SongRequestService.RefreshVolume(); return; } } await ChannelSession.Chat.Whisper(user.UserName, "Please specify a volume level [0-100]."); return; } else if (this.SongRequestType == SongRequestActionTypeEnum.DisplayCurrentlyPlaying) { SongRequestItem currentlyPlaying = await ChannelSession.Services.SongRequestService.GetCurrentlyPlaying(); if (currentlyPlaying != null) { await ChannelSession.Chat.SendMessage("Currently Playing: " + currentlyPlaying.Name); } else { await ChannelSession.Chat.SendMessage("There is currently no song playing for the Song Request queue"); } } else if (this.SongRequestType == SongRequestActionTypeEnum.DisplayNextSong) { SongRequestItem nextTrack = await ChannelSession.Services.SongRequestService.GetNextTrack(); if (nextTrack != null) { await ChannelSession.Chat.SendMessage("Coming Up Next: " + nextTrack.Name); } else { await ChannelSession.Chat.SendMessage("There are currently no Song Requests left in the queue"); } } else if (this.SongRequestType == SongRequestActionTypeEnum.PlayPauseCurrentSong) { await ChannelSession.Services.SongRequestService.PlayPauseCurrentSong(); } else if (this.SongRequestType == SongRequestActionTypeEnum.SkipToNextSong) { await ChannelSession.Services.SongRequestService.SkipToNextSong(); } } } }
public async Task ReplaceCommonSpecialModifiers(UserViewModel user, IEnumerable <string> arguments = null) { foreach (string counter in ChannelSession.Counters.Keys) { this.ReplaceSpecialIdentifier(counter, ChannelSession.Counters[counter].ToString()); } foreach (var kvp in SpecialIdentifierStringBuilder.CustomSpecialIdentifiers) { this.ReplaceSpecialIdentifier(kvp.Key, kvp.Value); } this.ReplaceSpecialIdentifier("timedigits", DateTimeOffset.Now.ToString("HHmm")); this.ReplaceSpecialIdentifier("datetime", DateTimeOffset.Now.ToString("g")); this.ReplaceSpecialIdentifier("date", DateTimeOffset.Now.ToString("d")); this.ReplaceSpecialIdentifier("time", DateTimeOffset.Now.ToString("t")); this.ReplaceSpecialIdentifier("linebreak", Environment.NewLine); if (this.ContainsSpecialIdentifier(SpecialIdentifierStringBuilder.TopSpecialIdentifierHeader)) { Dictionary <uint, UserDataViewModel> allUsersDictionary = ChannelSession.Settings.UserData.ToDictionary(); allUsersDictionary.Remove(ChannelSession.Channel.user.id); IEnumerable <UserDataViewModel> allUsers = allUsersDictionary.Select(kvp => kvp.Value); allUsers = allUsers.Where(u => !u.IsCurrencyRankExempt); foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values) { if (this.ContainsRegexSpecialIdentifier(currency.TopRegexSpecialIdentifier)) { this.ReplaceNumberBasedRegexSpecialIdentifier(currency.TopRegexSpecialIdentifier, (total) => { List <string> currencyUserList = new List <string>(); int userPosition = 1; foreach (UserDataViewModel currencyUser in allUsers.OrderByDescending(u => u.GetCurrencyAmount(currency)).Take(total)) { currencyUserList.Add($"#{userPosition}) {currencyUser.UserName} - {currencyUser.GetCurrencyAmount(currency)}"); userPosition++; } string result = "No users found."; if (currencyUserList.Count > 0) { result = string.Join(", ", currencyUserList); } return(result); }); } } if (this.ContainsRegexSpecialIdentifier(SpecialIdentifierStringBuilder.TopTimeRegexSpecialIdentifier)) { this.ReplaceNumberBasedRegexSpecialIdentifier(SpecialIdentifierStringBuilder.TopTimeRegexSpecialIdentifier, (total) => { List <string> timeUserList = new List <string>(); int userPosition = 1; foreach (UserDataViewModel timeUser in allUsers.OrderByDescending(u => u.ViewingMinutes).Take(total)) { timeUserList.Add($"#{userPosition}) {timeUser.UserName} - {timeUser.ViewingTimeShortString}"); userPosition++; } string result = "No users found."; if (timeUserList.Count > 0) { result = string.Join(", ", timeUserList); } return(result); }); } if (this.ContainsRegexSpecialIdentifier(SpecialIdentifierStringBuilder.TopSparksUsedRegexSpecialIdentifierHeader)) { await this.HandleSparksUsed("weekly", async() => { return(await ChannelSession.Connection.GetWeeklyLeaderboard(ChannelSession.Channel)); }); await this.HandleSparksUsed("monthly", async() => { return(await ChannelSession.Connection.GetMonthlyLeaderboard(ChannelSession.Channel)); }); await this.HandleSparksUsed("yearly", async() => { return(await ChannelSession.Connection.GetYearlyLeaderboard(ChannelSession.Channel)); }); await this.HandleSparksUsed("alltime", async() => { return(await ChannelSession.Connection.GetAllTimeLeaderboard(ChannelSession.Channel)); }); } } if (this.ContainsSpecialIdentifier(CurrentSongIdentifierHeader)) { SongRequestItem song = null; if (ChannelSession.Services.SongRequestService != null && ChannelSession.Services.SongRequestService.IsEnabled) { song = await ChannelSession.Services.SongRequestService.GetCurrentlyPlaying(); } if (song != null) { this.ReplaceSpecialIdentifier(CurrentSongIdentifierHeader + "title", song.Name); this.ReplaceSpecialIdentifier(CurrentSongIdentifierHeader + "username", song.User.UserName); this.ReplaceSpecialIdentifier(CurrentSongIdentifierHeader + "albumimage", song.AlbumImage ?? string.Empty); } else { this.ReplaceSpecialIdentifier(CurrentSongIdentifierHeader + "title", "No Song"); this.ReplaceSpecialIdentifier(CurrentSongIdentifierHeader + "username", "Nobody"); this.ReplaceSpecialIdentifier(CurrentSongIdentifierHeader + "albumimage", string.Empty); } } if (this.ContainsSpecialIdentifier(NextSongIdentifierHeader)) { SongRequestItem song = null; if (ChannelSession.Services.SongRequestService != null && ChannelSession.Services.SongRequestService.IsEnabled) { song = await ChannelSession.Services.SongRequestService.GetNextTrack(); } if (song != null) { this.ReplaceSpecialIdentifier(NextSongIdentifierHeader + "title", song.Name); this.ReplaceSpecialIdentifier(NextSongIdentifierHeader + "username", song.User.UserName); this.ReplaceSpecialIdentifier(NextSongIdentifierHeader + "albumimage", song.AlbumImage ?? string.Empty); } else { this.ReplaceSpecialIdentifier(NextSongIdentifierHeader + "title", "No Song"); this.ReplaceSpecialIdentifier(NextSongIdentifierHeader + "username", "Nobody"); this.ReplaceSpecialIdentifier(NextSongIdentifierHeader + "albumimage", string.Empty); } } if (this.ContainsSpecialIdentifier(UptimeSpecialIdentifierHeader) || this.ContainsSpecialIdentifier(StartSpecialIdentifierHeader)) { DateTimeOffset startTime = await UptimeChatCommand.GetStartTime(); if (startTime > DateTimeOffset.MinValue) { TimeSpan duration = DateTimeOffset.Now.Subtract(startTime); this.ReplaceSpecialIdentifier(StartSpecialIdentifierHeader + "datetime", startTime.ToString("g")); this.ReplaceSpecialIdentifier(StartSpecialIdentifierHeader + "date", startTime.ToString("d")); this.ReplaceSpecialIdentifier(StartSpecialIdentifierHeader + "time", startTime.ToString("t")); this.ReplaceSpecialIdentifier(UptimeSpecialIdentifierHeader + "total", (int)duration.TotalHours + duration.ToString("\\:mm")); this.ReplaceSpecialIdentifier(UptimeSpecialIdentifierHeader + "hours", ((int)duration.TotalHours).ToString()); this.ReplaceSpecialIdentifier(UptimeSpecialIdentifierHeader + "minutes", duration.ToString("mm")); this.ReplaceSpecialIdentifier(UptimeSpecialIdentifierHeader + "seconds", duration.ToString("ss")); } } if (this.ContainsSpecialIdentifier(CostreamUsersSpecialIdentifier)) { this.ReplaceSpecialIdentifier(CostreamUsersSpecialIdentifier, await CostreamChatCommand.GetCostreamUsers()); } if (ChannelSession.Services.Twitter != null && this.ContainsSpecialIdentifier("tweet")) { IEnumerable <Tweet> tweets = await ChannelSession.Services.Twitter.GetLatestTweets(); if (tweets != null && tweets.Count() > 0) { Tweet latestTweet = tweets.FirstOrDefault(); DateTimeOffset latestTweetLocalTime = latestTweet.DateTime.ToLocalTime(); this.ReplaceSpecialIdentifier("tweetlatesturl", latestTweet.TweetLink); this.ReplaceSpecialIdentifier("tweetlatesttext", latestTweet.Text); this.ReplaceSpecialIdentifier("tweetlatestdatetime", latestTweetLocalTime.ToString("g")); this.ReplaceSpecialIdentifier("tweetlatestdate", latestTweetLocalTime.ToString("d")); this.ReplaceSpecialIdentifier("tweetlatesttime", latestTweetLocalTime.ToString("t")); Tweet streamTweet = tweets.FirstOrDefault(t => t.IsStreamTweet); if (streamTweet != null) { DateTimeOffset streamTweetLocalTime = streamTweet.DateTime.ToLocalTime(); this.ReplaceSpecialIdentifier("tweetstreamurl", streamTweet.TweetLink); this.ReplaceSpecialIdentifier("tweetstreamtext", streamTweet.Text); this.ReplaceSpecialIdentifier("tweetstreamdatetime", streamTweetLocalTime.ToString("g")); this.ReplaceSpecialIdentifier("tweetstreamdate", streamTweetLocalTime.ToString("d")); this.ReplaceSpecialIdentifier("tweetstreamtime", streamTweetLocalTime.ToString("t")); } } } if (ChannelSession.Services.Spotify != null && this.ContainsSpecialIdentifier("spotify")) { SpotifyUserProfile profile = await ChannelSession.Services.Spotify.GetCurrentProfile(); if (profile != null) { this.ReplaceSpecialIdentifier("spotifyprofileurl", profile.Link); } SpotifyCurrentlyPlaying currentlyPlaying = await ChannelSession.Services.Spotify.GetCurrentlyPlaying(); if (currentlyPlaying != null) { this.ReplaceSpecialIdentifier("spotifycurrentlyplaying", currentlyPlaying.ToString()); } } if (ChannelSession.Services.ExtraLife.IsConnected() && this.ContainsSpecialIdentifier(ExtraLifeSpecialIdentifierHeader)) { ExtraLifeTeam team = await ChannelSession.Services.ExtraLife.GetTeam(); this.ReplaceSpecialIdentifier(ExtraLifeSpecialIdentifierHeader + "teamdonationgoal", team.fundraisingGoal.ToString()); this.ReplaceSpecialIdentifier(ExtraLifeSpecialIdentifierHeader + "teamdonationcount", team.numDonations.ToString()); this.ReplaceSpecialIdentifier(ExtraLifeSpecialIdentifierHeader + "teamdonationamount", team.sumDonations.ToString()); ExtraLifeTeamParticipant participant = await ChannelSession.Services.ExtraLife.GetParticipant(); this.ReplaceSpecialIdentifier(ExtraLifeSpecialIdentifierHeader + "userdonationgoal", participant.fundraisingGoal.ToString()); this.ReplaceSpecialIdentifier(ExtraLifeSpecialIdentifierHeader + "userdonationcount", participant.numDonations.ToString()); this.ReplaceSpecialIdentifier(ExtraLifeSpecialIdentifierHeader + "userdonationamount", participant.sumDonations.ToString()); } if (this.ContainsSpecialIdentifier(FeaturedChannelsSpecialIdentifer)) { IEnumerable <ExpandedChannelModel> featuredChannels = await ChannelSession.Connection.GetFeaturedChannels(); if (featuredChannels != null) { this.ReplaceSpecialIdentifier(FeaturedChannelsSpecialIdentifer, string.Join(", ", featuredChannels.Select(c => "@" + c.user.username))); } } if (this.ContainsSpecialIdentifier(StreamSpecialIdentifierHeader)) { ChannelDetailsModel details = await ChannelSession.Connection.GetChannelDetails(ChannelSession.Channel); if (details != null) { this.ReplaceSpecialIdentifier(StreamSpecialIdentifierHeader + "title", details.name); this.ReplaceSpecialIdentifier(StreamSpecialIdentifierHeader + "agerating", details.audience); this.ReplaceSpecialIdentifier(StreamSpecialIdentifierHeader + "viewercount", details.viewersCurrent.ToString()); this.ReplaceSpecialIdentifier(StreamSpecialIdentifierHeader + "followcount", details.numFollowers.ToString()); this.ReplaceSpecialIdentifier(StreamSpecialIdentifierHeader + "subcount", details.numSubscribers.ToString()); } if (this.ContainsSpecialIdentifier(StreamHostCountSpecialIdentifier)) { IEnumerable <ChannelAdvancedModel> hosters = await ChannelSession.Connection.GetHosters(ChannelSession.Channel); if (hosters != null) { this.ReplaceSpecialIdentifier(StreamHostCountSpecialIdentifier, hosters.Count().ToString()); } } } if (this.ContainsSpecialIdentifier(MilestoneSpecialIdentifierHeader)) { PatronageStatusModel patronageStatus = await ChannelSession.Connection.GetPatronageStatus(ChannelSession.Channel); if (patronageStatus != null) { PatronagePeriodModel patronagePeriod = await ChannelSession.Connection.GetPatronagePeriod(patronageStatus); if (patronagePeriod != null) { IEnumerable <PatronageMilestoneModel> patronageMilestones = patronagePeriod.milestoneGroups.SelectMany(mg => mg.milestones); PatronageMilestoneModel patronageMilestone = patronageMilestones.FirstOrDefault(m => m.id == patronageStatus.currentMilestoneId); if (patronageMilestone != null) { this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "amount", patronageMilestone.target.ToString()); this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "remainingamount", (patronageMilestone.target - patronageStatus.patronageEarned).ToString()); this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "reward", patronageMilestone.DollarAmountText()); } PatronageMilestoneModel patronageNextMilestone = patronageMilestones.FirstOrDefault(m => m.id == (patronageStatus.currentMilestoneId + 1)); if (patronageNextMilestone != null) { this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "nextamount", patronageNextMilestone.target.ToString()); this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "remainingnextamount", (patronageNextMilestone.target - patronageStatus.patronageEarned).ToString()); this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "nextreward", patronageNextMilestone.DollarAmountText()); } PatronageMilestoneModel patronageFinalMilestone = patronageMilestones.OrderByDescending(m => m.id).FirstOrDefault(); if (patronageNextMilestone != null) { this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "finalamount", patronageFinalMilestone.target.ToString()); this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "remainingfinalamount", (patronageFinalMilestone.target - patronageStatus.patronageEarned).ToString()); this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "finalreward", patronageFinalMilestone.DollarAmountText()); } IEnumerable <PatronageMilestoneModel> patronageMilestonesEarned = patronageMilestones.Where(m => m.target <= patronageStatus.patronageEarned); if (patronageMilestonesEarned.Count() > 0) { PatronageMilestoneModel patronageMilestoneHighestEarned = patronageMilestonesEarned.OrderByDescending(m => m.reward).FirstOrDefault(); if (patronageMilestoneHighestEarned != null) { this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "earnedamount", patronageStatus.patronageEarned.ToString()); this.ReplaceSpecialIdentifier(MilestoneSpecialIdentifierHeader + "earnedreward", patronageMilestoneHighestEarned.DollarAmountText()); } } } } } if (this.ContainsSpecialIdentifier(UserSpecialIdentifierHeader)) { await this.HandleUserSpecialIdentifiers(user, string.Empty); } if (arguments != null) { for (int i = 0; i < arguments.Count(); i++) { string currentArgumentSpecialIdentifierHeader = ArgSpecialIdentifierHeader + (i + 1); if (this.ContainsSpecialIdentifier(currentArgumentSpecialIdentifierHeader)) { UserViewModel argUser = await this.GetUserFromArgument(arguments.ElementAt(i)); if (argUser != null) { await this.HandleUserSpecialIdentifiers(argUser, currentArgumentSpecialIdentifierHeader); } this.ReplaceSpecialIdentifier(currentArgumentSpecialIdentifierHeader + "text", arguments.ElementAt(i)); } } this.ReplaceSpecialIdentifier("allargs", string.Join(" ", arguments)); } if (this.ContainsSpecialIdentifier(TargetSpecialIdentifierHeader)) { UserViewModel targetUser = null; if (arguments != null && arguments.Count() > 0) { targetUser = await this.GetUserFromArgument(arguments.ElementAt(0)); } if (targetUser == null) { targetUser = user; } await this.HandleUserSpecialIdentifiers(targetUser, TargetSpecialIdentifierHeader); } if (this.ContainsSpecialIdentifier(StreamerSpecialIdentifierHeader)) { await this.HandleUserSpecialIdentifiers(new UserViewModel(ChannelSession.Channel.user), StreamerSpecialIdentifierHeader); } if (this.ContainsSpecialIdentifier(StreamBossSpecialIdentifierHeader)) { OverlayWidget streamBossWidget = ChannelSession.Settings.OverlayWidgets.FirstOrDefault(w => w.Item is OverlayStreamBoss); if (streamBossWidget != null) { OverlayStreamBoss streamBossOverlay = (OverlayStreamBoss)streamBossWidget.Item; if (streamBossOverlay != null && streamBossOverlay.CurrentBoss != null) { await this.HandleUserSpecialIdentifiers(streamBossOverlay.CurrentBoss, StreamBossSpecialIdentifierHeader); } } } if (this.ContainsSpecialIdentifier(RandomSpecialIdentifierHeader)) { if (this.randomUserSpecialIdentifierGroupID != Guid.Empty && RandomUserSpecialIdentifierGroups.ContainsKey(this.randomUserSpecialIdentifierGroupID)) { if (RandomUserSpecialIdentifierGroups[randomUserSpecialIdentifierGroupID].RandomUser != null && this.ContainsSpecialIdentifier(SpecialIdentifierStringBuilder.RandomSpecialIdentifierHeader + "user")) { await this.HandleUserSpecialIdentifiers(RandomUserSpecialIdentifierGroups[randomUserSpecialIdentifierGroupID].RandomUser, RandomSpecialIdentifierHeader); } if (RandomUserSpecialIdentifierGroups[randomUserSpecialIdentifierGroupID].RandomFollower != null && this.ContainsSpecialIdentifier(SpecialIdentifierStringBuilder.RandomFollowerSpecialIdentifierHeader + "user")) { await this.HandleUserSpecialIdentifiers(RandomUserSpecialIdentifierGroups[randomUserSpecialIdentifierGroupID].RandomFollower, RandomFollowerSpecialIdentifierHeader); } if (RandomUserSpecialIdentifierGroups[randomUserSpecialIdentifierGroupID].RandomSubscriber != null && this.ContainsSpecialIdentifier(SpecialIdentifierStringBuilder.RandomSubscriberSpecialIdentifierHeader + "user")) { await this.HandleUserSpecialIdentifiers(RandomUserSpecialIdentifierGroups[randomUserSpecialIdentifierGroupID].RandomSubscriber, RandomSubscriberSpecialIdentifierHeader); } } if (this.ContainsRegexSpecialIdentifier(RandomNumberRegexSpecialIdentifier)) { this.ReplaceNumberBasedRegexSpecialIdentifier(RandomNumberRegexSpecialIdentifier, (maxNumber) => { int number = RandomHelper.GenerateRandomNumber(maxNumber) + 1; return(number.ToString()); }); } } if (this.ContainsRegexSpecialIdentifier(UnicodeRegexSpecialIdentifier)) { this.ReplaceNumberBasedRegexSpecialIdentifier(UnicodeRegexSpecialIdentifier, (number) => { char uChar = (char)number; return(uChar.ToString()); }); } }
private async Task PlayerBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); bool changeOccurred = false; await SongRequestService.songRequestLock.WaitAndRelease(async() => { Logger.LogDiagnostic("Current Song: " + this.currentSong); Logger.LogDiagnostic("Spotify Status: " + this.spotifyStatus); Logger.LogDiagnostic("YouTube Status: " + this.youTubeStatus); if (this.currentSong == null) { await this.SkipToNextSongInternal(); changeOccurred = true; } else { SongRequestItem status = null; if (this.currentSong.Type == SongRequestServiceTypeEnum.Spotify) { status = this.spotifyStatus = await this.GetSpotifyStatus(); } else if (this.currentSong.Type == SongRequestServiceTypeEnum.YouTube) { status = await this.GetYouTubeStatus(); } if (status != null) { if (status.Volume != ChannelSession.Settings.SongRequestVolume) { await this.RefreshVolumeInternal(); } if (this.currentSong.Type == status.Type && this.currentSong.ID.Equals(status.ID)) { this.currentSong.Progress = status.Progress; this.currentSong.State = status.State; } } if (currentSong.State == SongRequestStateEnum.NotStarted) { await this.RefreshVolumeInternal(); await this.PlaySongInternal(this.currentSong); changeOccurred = true; } else if (this.currentSong.State == SongRequestStateEnum.Ended) { await this.RefreshVolumeInternal(); await this.SkipToNextSongInternal(); changeOccurred = true; } } }); if (changeOccurred) { GlobalEvents.SongRequestsChangedOccurred(); await Task.Delay(2500, tokenSource.Token); } await Task.Delay(1000, tokenSource.Token); }); }
public void SetStatus(string result) { this.status = SerializerHelper.DeserializeFromString <SongRequestItem>(result); }
public SongRequestItemSearch(SongRequestItem songRequest) { this.SongRequest = songRequest; this.Type = this.SongRequest.Type; }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Chat != null) { if (this.SongRequestType == SongRequestActionTypeEnum.EnableDisableSongRequests) { if (!ChannelSession.Services.SongRequestService.IsEnabled) { if (!await ChannelSession.Services.SongRequestService.Initialize()) { ChannelSession.Services.SongRequestService.Disable(); await ChannelSession.Chat.Whisper(user.UserName, "Song Requests were not able to enabled, please try manually enabling it."); return; } } else { ChannelSession.Services.SongRequestService.Disable(); } } else { if (ChannelSession.Services.SongRequestService == null || !ChannelSession.Services.SongRequestService.IsEnabled) { await ChannelSession.Chat.Whisper(user.UserName, "Song Requests are not currently enabled"); return; } if (this.SongRequestType == SongRequestActionTypeEnum.AddSongToQueue) { await ChannelSession.Services.SongRequestService.AddSongRequest(user, string.Join(" ", arguments)); } else if (this.SongRequestType == SongRequestActionTypeEnum.DisplayCurrentlyPlaying) { SongRequestItem currentlyPlaying = await ChannelSession.Services.SongRequestService.GetCurrentlyPlaying(); if (currentlyPlaying != null) { await ChannelSession.Chat.SendMessage("Currently Playing: " + currentlyPlaying.Name); } else { await ChannelSession.Chat.SendMessage("There is currently no song playing for the Song Request queue"); } } else if (this.SongRequestType == SongRequestActionTypeEnum.DisplayNextSong) { SongRequestItem nextTrack = await ChannelSession.Services.SongRequestService.GetNextTrack(); if (nextTrack != null) { await ChannelSession.Chat.SendMessage("Coming Up Next: " + nextTrack.Name); } else { await ChannelSession.Chat.SendMessage("There are currently no Song Requests left in the queue"); } } else if (this.SongRequestType == SongRequestActionTypeEnum.PlayPauseCurrentSong) { await ChannelSession.Services.SongRequestService.PlayPauseCurrentSong(); } else if (this.SongRequestType == SongRequestActionTypeEnum.SkipToNextSong) { await ChannelSession.Services.SongRequestService.SkipToNextSong(); } } } }