private void PlaybackStopped(object sender, PlaybackStopEventArgs e) { if (e.IsPaused) { return; } //The item was in a paused state when the user stopped it, clean up the paused session list. PausedSessionsHelper.RemoveSessionFromList(e.Session.Id); PlayingSessionsHelper.RemoveSessionFromList(e.Session.Id); }
private void PlaybackProgress(object sender, PlaybackProgressEventArgs e) { switch (e.Session.PlayState.IsPaused) { case true: PausedSessionsHelper.AddSessionToList(e.Session.Id); break; case false: PausedSessionsHelper.RemoveSessionFromList(e.Session.Id); PlayingSessionsHelper.AddSessionToList(e.Session.Id); break; } }
public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress) { var rnd = new Random(); var rndMaster = rnd.Next(1, 10); Logger.Info($"Count of streams {SessionManager.Sessions.Count()}"); Logger.Info( $"AllowAudioTranscode {Plugin.Instance.PluginConfiguration.Allow4KAudioTranscode} AllowVideoTranscode {Plugin.Instance.PluginConfiguration.Allow4KVideoTranscode}"); foreach (var sessionManagerSession in SessionManager.Sessions) { Logger.Info( $"Device Id {sessionManagerSession.DeviceId} - UserName {sessionManagerSession.UserName} - ID {sessionManagerSession.Id} PlayState Method {sessionManagerSession.PlayState?.PlayMethod} AudioDirect {sessionManagerSession.TranscodingInfo?.IsAudioDirect} Video Direct {sessionManagerSession.TranscodingInfo?.IsVideoDirect}"); if (sessionManagerSession.PlayState != null && sessionManagerSession.PlayState.PlayMethod == PlayMethod.Transcode && sessionManagerSession.NowPlayingItem != null) { var mediaSourceItem = sessionManagerSession.FullNowPlayingItem.GetMediaSources(false, false, new LibraryOptions()) .Single(x => string.Equals(x.Id, sessionManagerSession.PlayState.MediaSourceId, StringComparison.CurrentCultureIgnoreCase)); Logger.Info( $"Height {mediaSourceItem.VideoStream.Height} Width {mediaSourceItem.VideoStream.Width}"); var is4K = mediaSourceItem.VideoStream.Height <= 2160 && mediaSourceItem.VideoStream.Width <= 4096 && mediaSourceItem.VideoStream.Height > 640 && mediaSourceItem.VideoStream.Width > 480; if (!is4K) { is4K = mediaSourceItem.VideoStream.DisplayTitle.ToLower().Contains("4k"); } if (sessionManagerSession.TranscodingInfo != null && is4K && !Plugin.Instance.PluginConfiguration.Allow4KVideoTranscode && !sessionManagerSession.TranscodingInfo.IsVideoDirect) { Logger.Info("Inside Kill Video 4k"); Logger.Info( $"Device Id {sessionManagerSession.DeviceId} - UserName {sessionManagerSession.UserName} - ID {sessionManagerSession.Id}"); await SessionManager.SendPlaystateCommand(null, sessionManagerSession.Id, new PlaystateRequest { Command = PlaystateCommand.Stop, ControllingUserId = UserManager.Users .FirstOrDefault(user => user.Policy.IsAdministrator)?.Id.ToString() }, new CancellationToken()); var text = "Stream stopped because of transcoding. Reason(s): " + string.Join(", ", sessionManagerSession.TranscodingInfo.TranscodeReasons) + "Try adjusting your video internet quality settings in your emby app. To correct/fix your actual problem:. go to your settings OR click on your profile picture, → click on PlayBack (In French: Lecture, OR in Portuguese: Reprodução/Leitura ) → Internet Quality OR Maximum Stream Birate. And set it to the highest level allowed on your device. More Info in our Website/Discord."; await SessionManager.SendMessageCommand(null, sessionManagerSession.Id, new MessageCommand { Header = "Stream Video Transcoding Not Enabled in our servers.", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); } if (sessionManagerSession.TranscodingInfo != null && is4K && !Plugin.Instance.PluginConfiguration.Allow4KAudioTranscode && !sessionManagerSession.TranscodingInfo.IsAudioDirect) { Logger.Info("Inside Kill Audio 4k"); Logger.Info( $"Device Id {sessionManagerSession.DeviceId} - UserName {sessionManagerSession.UserName} - ID {sessionManagerSession.Id}"); await SessionManager.SendPlaystateCommand(null, sessionManagerSession.Id, new PlaystateRequest { Command = PlaystateCommand.Stop, ControllingUserId = UserManager.Users .FirstOrDefault(user => user.Policy.IsAdministrator)?.Id.ToString() }, new CancellationToken()); var text = "Stream stopped because of transcoding. Reason(s): " + string.Join(", ", sessionManagerSession.TranscodingInfo.TranscodeReasons) + "Try adjusting your video internet quality settings to a higher value and/or changing audio sources depending on your reason."; await SessionManager.SendMessageCommand(null, sessionManagerSession.Id, new MessageCommand { Header = "Stream Audio Transcoding Disabled", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); } } if (sessionManagerSession.TranscodingInfo != null && sessionManagerSession.PlayState != null && sessionManagerSession.PlayState.PlayMethod == PlayMethod.Transcode && !sessionManagerSession.TranscodingInfo.IsVideoDirect && Plugin.Instance.PluginConfiguration.NagTranscode && rndMaster == rnd.Next(1, 10)) { Logger.Info("Inside nag transcode"); Logger.Info( $"Device Id {sessionManagerSession.DeviceId} - UserName {sessionManagerSession.UserName} - ID {sessionManagerSession.Id}"); var text = "You are being nagged for transcoding. Reason(s): " + string.Join(", ", sessionManagerSession.TranscodingInfo.TranscodeReasons) + "Try adjusting your video internet quality settings to a higher value and/or changing audio sources depending on your reason."; await SessionManager.SendMessageCommand(null, sessionManagerSession.Id, new MessageCommand { Header = "Stream Transcoding Nag", Text = prettyText(text) }, new CancellationToken()); } } var killPausedStreams = PausedSessionsHelper.GetSessionsToKill(); Logger.Info($"Count of paused streams {killPausedStreams.Count()}"); foreach (var pausedStream in killPausedStreams) { await SessionManager.SendPlaystateCommand(null, pausedStream.SessionId, new PlaystateRequest { Command = PlaystateCommand.Stop, ControllingUserId = UserManager.Users .FirstOrDefault(user => user.Policy.IsAdministrator)?.Id.ToString() }, new CancellationToken()); var text = "Stream killed due to being paused for more than " + Plugin.Instance.PluginConfiguration.PausedDurationMin + "min."; await SessionManager.SendMessageCommand(null, pausedStream.SessionId, new MessageCommand { Header = "Paused Stream Killed", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); } var killLongPlayingStreams = PlayingSessionsHelper.GetSessionsToKill(); Logger.Info($"Count of Long Playing streams {killLongPlayingStreams.Count()}"); foreach (var PlayingStream in killLongPlayingStreams) { await SessionManager.SendPlaystateCommand(null, PlayingStream.SessionId, new PlaystateRequest { Command = PlaystateCommand.Stop, ControllingUserId = UserManager.Users.FirstOrDefault(user => user.Policy.IsAdministrator)?.Id.ToString() }, new CancellationToken()); var text = "Stream killed due to beeing playing for more than " + Plugin.Instance.PluginConfiguration.PlayingDurationH + "H."; await SessionManager.SendMessageCommand(null, PlayingStream.SessionId, new MessageCommand { Header = "Long Playing Stream Killed", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); } }