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.RemoteSessionFromList(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.RemoteSessionFromList(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} MediaSourceId {sessionManagerSession.PlayState?.MediaSourceId}"); if (sessionManagerSession.PlayState != null && sessionManagerSession.PlayState.PlayMethod == PlayMethod.Transcode && sessionManagerSession.NowPlayingItem != null) { var mediaSourceItem = sessionManagerSession.FullNowPlayingItem.GetMediaSources(false, false, new LibraryOptions()) .SingleOrDefault(x => string.Equals(x.Id, sessionManagerSession.PlayState.MediaSourceId, StringComparison.OrdinalIgnoreCase)); if (mediaSourceItem == null && !Plugin.Instance.PluginConfiguration.AllowUnknownTranscode) { var sources = sessionManagerSession.FullNowPlayingItem.GetMediaSources(false, false, new LibraryOptions()); Logger.Info($"Not found Id {sessionManagerSession.PlayState.MediaSourceId} in IDs ({string.Join(", ", sources.Select(x => x.Id))})"); Logger.Info("Inside Kill Video Unknown"); 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 file has an unknown source not in database. What do I do!?!?! Send help."; await SessionManager.SendMessageCommand(null, sessionManagerSession.Id, new MessageCommand { Header = "Transcoding of Unknown file not found in sources", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); continue; } if (mediaSourceItem == null && Plugin.Instance.PluginConfiguration.AllowUnknownTranscode) { continue; } Logger.Info( $"Height {mediaSourceItem.VideoStream.Height} Width {mediaSourceItem.VideoStream.Width}"); var is4K = mediaSourceItem.VideoStream.Height <= 2160 && mediaSourceItem.VideoStream.Width <= 4096 && mediaSourceItem.VideoStream.Height > 1080 && mediaSourceItem.VideoStream.Width > 1920; 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} - Supports Media Control {sessionManagerSession.Capabilities.SupportsMediaControl} - Supported Commands {string.Join(", ", sessionManagerSession.Capabilities.SupportedCommands)}"); 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 = "4K Stream Video Transcoding Disabled", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); SessionManager.ReportSessionEnded(sessionManagerSession.Id); continue; } 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 = "4K Stream Audio Transcoding Disabled", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); continue; } if (is4K && Plugin.Instance.PluginConfiguration.Allow4KAudioTranscode && sessionManagerSession.TranscodingInfo != null && !sessionManagerSession.TranscodingInfo.IsAudioDirect) { Logger.Info("Inside Allow 4k audio transcode"); Logger.Info( $"Device Id {sessionManagerSession.DeviceId} - UserName {sessionManagerSession.UserName} - ID {sessionManagerSession.Id}"); var text = "Transcoding. Reason(s): " + string.Join(", ", sessionManagerSession.TranscodingInfo.TranscodeReasons) + "Try changing the audio to match your setup and save the CPU. However you can continue to play with a audio transcode."; if (sessionManagerSession.PlayState.PositionTicks <= sessionManagerSession.NowPlayingItem.RunTimeTicks * .05) { await SessionManager.SendMessageCommand(null, sessionManagerSession.Id, new MessageCommand { Header = "4K Stream Audio Transcoding Enabled", Text = prettyText(text) //TimeoutMs = 10000 }, new CancellationToken()); } continue; } } 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()); continue; } } 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()); } }
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()); } }