private async void SendPlaybackNotification(string type, PlaybackProgressEventArgs e) { var user = e.Users.FirstOrDefault(); if (user != null && !GetOptions().IsEnabledToMonitorUser(type, user.Id.ToString("N"))) { return; } var item = e.MediaInfo; if (e.Item != null && e.Item.IsThemeMedia) { // Don't report theme song or local trailer playback return; } var notification = new NotificationRequest { NotificationType = type }; if (e.Item != null) { notification.Variables["ItemName"] = GetItemName(e.Item); } else { notification.Variables["ItemName"] = item.Name; } notification.Variables["UserName"] = user == null ? "Unknown user" : user.Name; notification.Variables["AppName"] = e.ClientName; notification.Variables["DeviceName"] = e.DeviceName; await SendNotification(notification, null).ConfigureAwait(false); }
void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e) { string key = e.DeviceId + "-" + e.Users[0].Id.ToString("N") + "-" + e.Item.Id.ToString("N"); if (playback_trackers != null && playback_trackers.ContainsKey(key)) { try { PlaybackTracker tracker = playback_trackers[key]; DateTime now = DateTime.Now; if (now.Subtract(tracker.LastUpdated).TotalSeconds > 20) // update every 20 seconds { tracker.LastUpdated = now; _logger.LogInformation("Processing playback tracker : {Key}", key); List <string> event_log = tracker.ProcessProgress(e); if (event_log.Count > 0) { _logger.LogDebug("ProcessProgress : {Events}", string.Join("", event_log)); } if (tracker.TrackedPlaybackInfo != null) { _repository.UpdatePlaybackAction(tracker.TrackedPlaybackInfo); } } } catch (Exception exp) { playback_trackers.Remove(key); throw new Exception("Error saving playback state: " + exp.Message); } } else { _logger.LogDebug("Playback progress did not have a tracker : {Key}", key); } }
void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) { var item = e.MediaInfo; if (item == null) { //_logger.Warn("PlaybackStart reported with null media info."); return; } if (e.Users.Count == 0) { return; } var username = e.Users.First().Name; CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserStartedPlayingItemWithValues"), username, item.Name), Type = "PlaybackStart", ShortOverview = string.Format(_localization.GetLocalizedString("AppDeviceValues"), e.ClientName, e.DeviceName) }); }
private async void PlaybackStart(object?sender, PlaybackProgressEventArgs e) { foreach (var user in e.Users) { var userConfig = GetUserConfig(user.Id); if (userConfig == null) { _logger.LogDebug("{Username}: No configuration", user.Username); continue; } if (string.IsNullOrEmpty(userConfig.CmdPlaybackStart)) { _logger.LogDebug("{Username}: No configured PlaybackStart command", user.Username); continue; } _logger.LogInformation("{Username}: Running command \"{CmdPlaybackStart}\"", user.Username, userConfig.CmdPlaybackStart); try { var command = Command.Run( userConfig.CmdPlaybackStart.Split(" ")[0], userConfig.CmdPlaybackStart.Split(" ")[1..],
async void _device_PlaybackProgress(object sender, PlaybackProgressEventArgs e) { try { var info = StreamParams.ParseFromUrl(e.MediaInfo.Url, _libraryManager); if (info.Item != null) { var progress = GetProgressInfo(e.MediaInfo, info); await _sessionManager.OnPlaybackProgress(progress).ConfigureAwait(false); } } catch (Exception ex) { _logger.ErrorException("Error reporting progress", ex); } }
public string buildJson_Playback(PluginConfiguration.Hook hooks, SessionInfo sessionInfo, PlaybackProgressEventArgs playbackData, string trigger) { if ((trigger == "Paused" || trigger == "Resumed") && string.IsNullOrEmpty(sessionInfo.NowPlayingItem.ToString())) { return("_redundant_"); } string playbackTicks = (string.IsNullOrEmpty(playbackData.PlaybackPositionTicks.ToString())) ? sessionInfo.PlayState.PositionTicks.ToString() : playbackData.PlaybackPositionTicks.ToString(); string msgPlayback = buildJson_BaseItem(hooks.removeQuotes, hooks.msgHook, sessionInfo.FullNowPlayingItem); return(msgPlayback.Replace("{Event}", testString(hooks.removeQuotes, trigger, true)). Replace("{ServerID}", testString(hooks.removeQuotes, _appHost.SystemId, true)). Replace("{ServerName}", testString(hooks.removeQuotes, _appHost.FriendlyName, true)). Replace("{UserID}", testString(hooks.removeQuotes, sessionInfo.UserId.ToString(), true)). Replace("{UserName}", testString(hooks.removeQuotes, sessionInfo.UserName, true)). Replace("{AppName}", testString(hooks.removeQuotes, sessionInfo.AppName, true)). Replace("{DeviceID}", testString(hooks.removeQuotes, sessionInfo.DeviceId.ToString(), true)). Replace("{DeviceName}", testString(hooks.removeQuotes, sessionInfo.DeviceName, true)). Replace("{DeviceIP}", testString(hooks.removeQuotes, sessionInfo.RemoteEndPoint.ToString(), true)). Replace("{SessionID}", testString(hooks.removeQuotes, sessionInfo.Id, true)). Replace("{SessionPlaybackPositionTicks}", testString(hooks.removeQuotes, playbackTicks, false)). Replace("{TimeStamp}", testString(hooks.removeQuotes, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), true))); }
/// <summary> /// Let Trakt.tv know the user has started to watch something /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void KernelPlaybackStart(object sender, PlaybackProgressEventArgs e) { try { _logger.Info("Playback Started"); if (e.Users == null || !e.Users.Any() || e.Item == null) { _logger.Error("Event details incomplete. Cannot process current media"); return; } // Since MB3 is user profile friendly, I'm going to need to do a user lookup every time something starts var traktUser = UserHelper.GetTraktUser(e.Users.FirstOrDefault()); if (traktUser == null) { _logger.Info("Could not match user with any stored credentials"); return; } _logger.Debug(traktUser.LinkedMbUserId + " appears to be monitoring " + e.Item.Path); var video = e.Item as Video; try { if (video is Movie) { _logger.Debug("Send movie status update"); await _traktApi.SendMovieStatusUpdateAsync(video as Movie, MediaStatus.Watching, traktUser). ConfigureAwait(false); } else if (video is Episode) { _logger.Debug("Send episode status update"); await _traktApi.SendEpisodeStatusUpdateAsync(video as Episode, MediaStatus.Watching, traktUser). ConfigureAwait(false); } } catch (Exception ex) { _logger.ErrorException("Exception handled sending status update", ex); } var playEvent = new ProgressEvent { UserId = e.Users.First().Id, ItemId = e.Item.Id, LastApiAccess = DateTime.UtcNow }; _progressEvents.Add(playEvent); } catch (Exception ex) { _logger.ErrorException("Error sending watching status update", ex, null); } }
private async void OnSessionManagerPlaybackStart(object sender, PlaybackProgressEventArgs e) { await SendData(true).ConfigureAwait(false); }
private async void OnPlaybackStart(object sender, PlaybackProgressEventArgs e) { await PlaybackEvent(HookEvent.Play, e.Item, e.Session, e.Users); SetDeviceState(e.DeviceId, DeviceState.Playing); }
private void OnSessionManagerPlaybackStart(object sender, PlaybackProgressEventArgs e) { SendData(true); }
private void OnSessionManagerPlaybackProgress(object sender, PlaybackProgressEventArgs e) { SendData(!e.IsAutomated); }
public static void PlaybackStarted(object sender, PlaybackProgressEventArgs e) { try { if (e.MediaInfo.RunTimeTicks != null && (e.Item.MediaType == MediaType.Video && e.MediaInfo.RunTimeTicks.Value < IntroOrVideoBackDrop)) { return; } string sceneName = string.Empty; var config = new PluginConfiguration(); var profile = config.SavedDeviceProfiles.Find(p => p.Name.Equals(e.DeviceName) && e.ClientName.Equals(p.AppName)); if (ScheduleAllowScene(profile, config)) { switch (e.MediaInfo.Type) { case "Movie": sceneName = profile.MoviesPlaybackStarted; break; case "TvChannel": sceneName = profile.LiveTvPlaybackStarted; break; case "Series": sceneName = profile.SeriesPlaybackStarted; break; case "Season": sceneName = profile.SeriesPlaybackStarted; break; case "Episode": //var info = EpisodeStopEventTimers.Find( // t => t.DeviceName == e.DeviceName && t.AppName == e.ClientName); //if (info != null) //{ // EpisodeStopEventTimers.RemoveAll(t => t.DeviceName == info.DeviceName && t.AppName == info.AppName); // break; //} sceneName = profile.SeriesPlaybackStarted; break; case "Album": sceneName = profile.MusicPlaybackStarted; break; case "Artist": sceneName = profile.MusicPlaybackStarted; break; case "Audio": sceneName = profile.MusicPlaybackStarted; break; default: sceneName = string.Empty; break; } } else { return; } if (sceneName.Equals(string.Empty)) { return; } RunScene(sceneName, config); } catch { } }
private static void PlaybackUnPaused(PlaybackProgressEventArgs e, PluginConfiguration config) { try { string sceneName = string.Empty; var profile = config.SavedDeviceProfiles.Find(p => p.Name.Equals(e.DeviceName) && e.ClientName.Equals(p.AppName)); if (ScheduleAllowScene(profile, config)) { switch (e.MediaInfo.Type) { case "Movie": sceneName = profile.MoviesPlaybackUnPaused; break; case "TvChannel": sceneName = profile.LiveTvPlaybackUnPaused; break; case "Series": sceneName = profile.SeriesPlaybackUnPaused; break; case "Season": sceneName = profile.SeriesPlaybackUnPaused; break; case "Episode": sceneName = profile.SeriesPlaybackUnPaused; break; case "Album": sceneName = profile.MusicPlaybackUnPaused; break; case "Artist": sceneName = profile.MusicPlaybackUnPaused; break; case "Audio": sceneName = profile.MusicPlaybackUnPaused; break; default: sceneName = string.Empty; break; } } else { return; } if (sceneName.Equals(string.Empty)) { return; } RunScene(sceneName, config); } catch { } }
public async System.Threading.Tasks.Task StartPlaybackTimer(PlaybackProgressEventArgs e) { _logger.Info("StartPlaybackTimer : Entered"); await System.Threading.Tasks.Task.Delay(20000); try { var session = _sessionManager.GetSession(e.DeviceId, e.ClientName, ""); if (session != null) { string event_playing_id = e.Item.Id.ToString("N"); string event_user_id = e.Users[0].Id.ToString("N"); string session_playing_id = ""; if (session.NowPlayingItem != null) { session_playing_id = session.NowPlayingItem.Id.ToString("N"); } string session_user_id = ""; _logger.Info("session.RemoteEndPoint : " + session.RemoteEndPoint); if (session.UserId != null) { session_user_id = ((Guid)session.UserId).ToString("N"); } string play_method = "na"; if (session.PlayState != null && session.PlayState.PlayMethod != null) { play_method = session.PlayState.PlayMethod.Value.ToString(); } if (session.PlayState != null && session.PlayState.PlayMethod == MediaBrowser.Model.Session.PlayMethod.Transcode) { if (session.TranscodingInfo != null) { string video_codec = "direct"; if (session.TranscodingInfo.IsVideoDirect == false) { video_codec = session.TranscodingInfo.VideoCodec; } string audio_codec = "direct"; if (session.TranscodingInfo.IsAudioDirect == false) { audio_codec = session.TranscodingInfo.AudioCodec; } play_method += " (v:" + video_codec + " a:" + audio_codec + ")"; } } string item_name = GetItemName(e.Item); string item_id = e.Item.Id.ToString("N"); string item_type = e.MediaInfo.Type; _logger.Info("StartPlaybackTimer : event_playing_id = " + event_playing_id); _logger.Info("StartPlaybackTimer : event_user_id = " + event_user_id); _logger.Info("StartPlaybackTimer : session_playing_id = " + session_playing_id); _logger.Info("StartPlaybackTimer : session_user_id = " + session_user_id); _logger.Info("StartPlaybackTimer : play_method = " + play_method); _logger.Info("StartPlaybackTimer : e.ClientName = " + e.ClientName); _logger.Info("StartPlaybackTimer : e.DeviceName = " + e.DeviceName); _logger.Info("StartPlaybackTimer : ItemName = " + item_name); _logger.Info("StartPlaybackTimer : ItemId = " + item_id); _logger.Info("StartPlaybackTimer : ItemType = " + item_type); PlaybackInfo play_info = new PlaybackInfo(); play_info.Id = Guid.NewGuid().ToString("N"); play_info.Date = DateTime.Now; play_info.ClientName = e.ClientName; play_info.DeviceName = e.DeviceName; play_info.PlaybackMethod = play_method; play_info.UserId = event_user_id; play_info.ItemId = item_id; play_info.ItemName = item_name; play_info.ItemType = item_type; if (event_playing_id == session_playing_id && event_user_id == session_user_id) { _logger.Info("StartPlaybackTimer : All matches, playback registered"); // update tracker with playback info string key = e.DeviceId + "-" + e.Users[0].Id.ToString("N") + "-" + e.Item.Id.ToString("N"); if (playback_trackers.ContainsKey(key)) { _logger.Info("Playback tracker found, adding playback info : " + key); PlaybackTracker tracker = playback_trackers[key]; tracker.TrackedPlaybackInfo = play_info; _logger.Info("Saving playback tracking activity in DB"); _repository.AddPlaybackAction(tracker.TrackedPlaybackInfo); } else { _logger.Info("Playback trackler not found : " + key); } } else { _logger.Info("StartPlaybackTimer : Details do not match for play item"); } } else { _logger.Info("StartPlaybackTimer : session Not Found"); } } catch (Exception exception) { _logger.Info("StartPlaybackTimer : Error = " + exception.Message + "\n" + exception.StackTrace); } _logger.Info("StartPlaybackTimer : Exited"); }
private void PlaybackStart(object sender, PlaybackProgressEventArgs e) { // ReSharper disable once ComplexConditionExpression if (e.MediaInfo.RunTimeTicks != null && (e.Item.MediaType == MediaType.Video && e.MediaInfo.RunTimeTicks.Value < IntroOrVideoBackDrop)) { return; } if (e.IsPaused) { return; } var config = Plugin.Instance.Configuration; //No profile, move on if (!config.SaveSmartThingsProfiles.Exists(p => p.DeviceName.Equals(e.DeviceName) && p.AppName.Equals(e.ClientName))) { return; } logger.Info("Samsung Smart Things Reports Playback Started"); var profile = config.SaveSmartThingsProfiles.FirstOrDefault(p => p.DeviceName.Equals(e.DeviceName) && p.AppName.Equals(e.ClientName)); logger.Info($"Samsung Smart Things Found Profile Device: { e.DeviceName }"); if (!ScheduleAllowScene(profile)) { logger.Info($"Samsung Smart Things profile not allowed to run at this time: { profile?.DeviceName }"); return; } var sceneName = string.Empty; switch (e.MediaInfo.Type) { case "Movie": sceneName = profile?.MoviesPlaybackStarted; break; case "TvChannel": sceneName = profile?.LiveTvPlaybackStarted; break; case "Series": sceneName = profile?.TvPlaybackStarted; break; case "Season": sceneName = profile?.TvPlaybackStarted; break; case "Episode": sceneName = profile?.TvPlaybackStarted; break; } logger.Info($"Samsung Smart Things Reports { e.MediaInfo.Type } will trigger Playback Started Scene on { e.DeviceName }"); RunScene(sceneName, config, "PlaybackStarted"); }
void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e) { SendData(!e.IsAutomated); }
void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) { SendData(true); }
/// <summary> /// Add playback progress data. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="playbackProgressEventArgs">The playback progress event args.</param> /// <returns>The modified data object.</returns> public static Dictionary <string, object> AddPlaybackProgressData(this Dictionary <string, object> dataObject, PlaybackProgressEventArgs playbackProgressEventArgs) { dataObject[nameof(playbackProgressEventArgs.PlaybackPositionTicks)] = playbackProgressEventArgs.PlaybackPositionTicks ?? 0; dataObject["PlaybackPosition"] = TimeSpan.FromTicks(playbackProgressEventArgs.PlaybackPositionTicks ?? 0).ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture); dataObject[nameof(playbackProgressEventArgs.MediaSourceId)] = playbackProgressEventArgs.MediaSourceId; dataObject[nameof(playbackProgressEventArgs.IsPaused)] = playbackProgressEventArgs.IsPaused; dataObject[nameof(playbackProgressEventArgs.IsAutomated)] = playbackProgressEventArgs.IsAutomated; dataObject[nameof(playbackProgressEventArgs.DeviceId)] = playbackProgressEventArgs.DeviceId; dataObject[nameof(playbackProgressEventArgs.DeviceName)] = playbackProgressEventArgs.DeviceName; dataObject[nameof(playbackProgressEventArgs.ClientName)] = playbackProgressEventArgs.ClientName; return(dataObject); }
public async Task StartPlaybackTimer(PlaybackProgressEventArgs e) { _logger.LogInformation("StartPlaybackTimer : Entered"); await Task.Delay(20000); try { var session = _sessionManager.GetSession(e.DeviceId, e.ClientName, ""); if (session != null) { string event_playing_id = e.Item.Id.ToString("N"); string event_user_id = e.Users[0].Id.ToString("N"); long event_user_id_int = e.Users[0].InternalId; string session_playing_id = ""; if (session.NowPlayingItem != null) { session_playing_id = session.NowPlayingItem.Id.ToString("N"); } string session_user_id = ""; _logger.LogInformation("session.RemoteEndPoint : {RemoteEndPoint}", session.RemoteEndPoint); if (session.UserId != Guid.Empty) { session_user_id = session.UserId.ToString("N"); } string play_method = "na"; if (session.PlayState != null && session.PlayState.PlayMethod != null) { play_method = session.PlayState.PlayMethod.Value.ToString(); } if (session.PlayState != null && session.PlayState.PlayMethod == MediaBrowser.Model.Session.PlayMethod.Transcode) { if (session.TranscodingInfo != null) { string video_codec = "direct"; if (session.TranscodingInfo.IsVideoDirect == false) { video_codec = session.TranscodingInfo.VideoCodec; } string audio_codec = "direct"; if (session.TranscodingInfo.IsAudioDirect == false) { audio_codec = session.TranscodingInfo.AudioCodec; } play_method += " (v:" + video_codec + " a:" + audio_codec + ")"; } } string item_name = GetItemName(e.Item); string item_id = e.Item.Id.ToString("N"); string item_type = e.MediaInfo.Type; _logger.LogInformation("StartPlaybackTimer : event_playing_id = {EventPlayingId}", event_playing_id); _logger.LogInformation("StartPlaybackTimer : event_user_id = {EventUserId}", event_user_id); _logger.LogInformation("StartPlaybackTimer : event_user_id_int = {EventUserIdInternal}", event_user_id_int); _logger.LogInformation("StartPlaybackTimer : session_playing_id = {SessionPlayingId}", session_playing_id); _logger.LogInformation("StartPlaybackTimer : session_user_id = {SessionUserId}", session_user_id); _logger.LogInformation("StartPlaybackTimer : play_method = {PlayMethod}", play_method); _logger.LogInformation("StartPlaybackTimer : e.ClientName = {ClientName}", e.ClientName); _logger.LogInformation("StartPlaybackTimer : e.DeviceName = {DeviceName}", e.DeviceName); _logger.LogInformation("StartPlaybackTimer : ItemName = {ItemName}", item_name); _logger.LogInformation("StartPlaybackTimer : ItemId = {ItemId}", item_id); _logger.LogInformation("StartPlaybackTimer : ItemType = {ItemType}", item_type); PlaybackInfo play_info = new PlaybackInfo { Id = Guid.NewGuid().ToString("N"), Date = DateTime.Now, ClientName = e.ClientName, DeviceName = e.DeviceName, PlaybackMethod = play_method, UserId = event_user_id, ItemId = item_id, ItemName = item_name, ItemType = item_type }; if (event_playing_id == session_playing_id && event_user_id == session_user_id) { _logger.LogInformation("StartPlaybackTimer : All matches, playback registered"); // update tracker with playback info string key = e.DeviceId + "-" + e.Users[0].Id.ToString("N") + "-" + e.Item.Id.ToString("N"); if (playback_trackers.ContainsKey(key)) { _logger.LogInformation("Playback tracker found, adding playback info : {Key}", key); PlaybackTracker tracker = playback_trackers[key]; tracker.TrackedPlaybackInfo = play_info; _logger.LogInformation("Saving playback tracking activity in DB"); _repository.AddPlaybackAction(tracker.TrackedPlaybackInfo); } else { _logger.LogInformation("Playback trackler not found : {Key}", key); } } else { _logger.LogInformation("StartPlaybackTimer : Details do not match for play item"); } } else { _logger.LogInformation("StartPlaybackTimer : session Not Found"); } } catch (Exception ex) { _logger.LogError(ex, "StartPlaybackTimer : Unexpected error occurred"); } _logger.LogInformation("StartPlaybackTimer : Exited"); }
/// <summary> /// Let Trakt.tv know the user has started to watch something /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void KernelPlaybackStart(object sender, PlaybackProgressEventArgs e) { try { _logger.Info("Playback Started"); if (e.Users == null || !e.Users.Any() || e.Item == null) { _logger.Error("Event details incomplete. Cannot process current media"); return; } // Since MB3 is user profile friendly, I'm going to need to do a user lookup every time something starts var traktUser = UserHelper.GetTraktUser(e.Users.FirstOrDefault()); if (traktUser == null) { _logger.Info("Could not match user with any stored credentials"); return; } // Still need to make sure it's a trakt monitored location before sending notice to trakt.tv if (traktUser.TraktLocations == null) { _logger.Info("User does not have any locations configured to monitor"); return; } var locations = traktUser.TraktLocations.Where(location => _fileSystem.ContainsSubPath(location, e.Item.Path)) .Where(location => e.Item is Episode || e.Item is Movie) .ToList(); if (locations.Any()) { _logger.Debug(traktUser.LinkedMbUserId + " appears to be monitoring " + e.Item.Path); foreach (var video in locations.Select(location => e.Item as Video)) { try { if (video is Movie) { _logger.Debug("Send movie status update"); await _traktApi.SendMovieStatusUpdateAsync(video as Movie, MediaStatus.Watching, traktUser). ConfigureAwait(false); } else if (video is Episode) { _logger.Debug("Send episode status update"); await _traktApi.SendEpisodeStatusUpdateAsync(video as Episode, MediaStatus.Watching, traktUser). ConfigureAwait(false); } } catch (Exception ex) { _logger.ErrorException("Exception handled sending status update", ex); } var playEvent = new ProgressEvent { UserId = e.Users.First().Id, ItemId = e.Item.Id, LastApiAccess = DateTime.UtcNow }; _progressEvents.Add(playEvent); } } else { _logger.Debug(traktUser.LinkedMbUserId + " does not appear to be monitoring " + e.Item.Path); } } catch (Exception ex) { _logger.ErrorException("Error sending watching status update", ex, null); } }
async void _device_PlaybackProgress(object sender, PlaybackProgressEventArgs e) { try { var info = GetProgressInfo(e.MediaInfo); await _sessionManager.OnPlaybackProgress(info).ConfigureAwait(false); } catch (Exception ex) { _logger.ErrorException("Error reporting progress", ex); } }
private void PlaybackProgress(object sender, PlaybackProgressEventArgs e) { var config = Plugin.Instance.Configuration; if (config.SavedHueEmbyProfiles.Exists(p => p.DeviceName.Equals(e.Session.DeviceName))) { var profile = config.SavedHueEmbyProfiles.FirstOrDefault(p => p.DeviceName.Equals(e.Session.DeviceName)); if (profile?.MediaItemCredits != null) { if (e.MediaInfo.Type.Equals("Movie") && e.Session.PlayState.PositionTicks > (e.Item.RunTimeTicks - (profile?.MediaItemCreditLength * 10000000))) { PlaybackCredits(e, profile, config); return; } } } //No paused Session and no flagged sessions paused, move on // ReSharper disable once ComplexConditionExpression if (!SessionManager.Sessions.Any(s => s.PlayState.IsPaused) && !PausedSessionsIds.Any()) { return; } foreach (var session in SessionManager.Sessions) { //if (session.Id != e.Session.Id) continue; switch (session.PlayState.IsPaused) { case true: //We don't have a profile for this paused session device, move on if (!config.SavedHueEmbyProfiles.Exists(p => p.DeviceName.Equals(session.DeviceName))) { continue; } // We've already flagged this session, move on if (PausedSessionsIds.Exists(s => s.SessionId.Equals(session.Id))) { continue; } PausedSessionsIds.Add(new PausedSession() { SessionId = session.Id, PausedAt = DateTime.Now }); PlaybackPaused(e, config, session, config.SavedHueEmbyProfiles.FirstOrDefault(p => p.DeviceName.Equals(session.DeviceName))); break; case false: if (PausedSessionsIds.Exists(s => s.SessionId.Equals(session.Id))) { if (PausedSessionsIds.FirstOrDefault(s => s.SessionId == session.Id)?.PausedAt.AddSeconds(5) < DateTime.Now) { PausedSessionsIds.RemoveAll(s => s.SessionId.Equals(session.Id)); PlaybackUnPaused(e, config, config.SavedHueEmbyProfiles.FirstOrDefault(p => p.DeviceName.Equals(session.DeviceName))); } } break; } } }
private async void OnSessionManagerPlaybackProgress(object sender, PlaybackProgressEventArgs e) { await SendData(!e.IsAutomated).ConfigureAwait(false); }
private void _recording_PlaybackProgress(object sender, PlaybackProgressEventArgs e) { slider.Value = (int)(e.ProgressPercentage * 100); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void KernelPlaybackProgress(object sender, PlaybackProgressEventArgs e) { }
void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e) { SendData(false); }
/// <summary> /// Let Trakt.tv know the user has started to watch something /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void KernelPlaybackStart(object sender, PlaybackProgressEventArgs e) { try { _logger.LogInformation("Playback Started"); if (e.Users == null || !e.Users.Any() || e.Item == null) { _logger.LogError("Event details incomplete. Cannot process current media"); return; } foreach (var user in e.Users) { // Since Emby is user profile friendly, I'm going to need to do a user lookup every time something starts var traktUser = UserHelper.GetTraktUser(user); if (traktUser == null) { _logger.LogInformation("Could not match user with any stored credentials"); continue; } if (!traktUser.Scrobble) { continue; } if (!_traktApi.CanSync(e.Item, traktUser)) { continue; } _logger.LogDebug(traktUser.LinkedMbUserId + " appears to be monitoring " + e.Item.Path); var video = e.Item as Video; var progressPercent = video.RunTimeTicks.HasValue && video.RunTimeTicks != 0 ? (float)(e.PlaybackPositionTicks ?? 0) / video.RunTimeTicks.Value * 100.0f : 0.0f; try { if (video is Movie movie) { _logger.LogDebug("Send movie status update"); await _traktApi.SendMovieStatusUpdateAsync( movie, MediaStatus.Watching, traktUser, progressPercent).ConfigureAwait(false); } else if (video is Episode episode) { _logger.LogDebug("Send episode status update"); await _traktApi.SendEpisodeStatusUpdateAsync( episode, MediaStatus.Watching, traktUser, progressPercent).ConfigureAwait(false); } } catch (Exception ex) { _logger.LogError(ex, "Exception handled sending status update"); } } } catch (Exception ex) { _logger.LogError(ex, "Error sending watching status update"); } }
private void embyPlaybackStart(object obj, PlaybackProgressEventArgs e) { _logger.Debug("EMBY PLAYBACK STARTED"); _logger.Debug("Obj: " + _json.SerializeToString(obj)); _logger.Debug("Event: " + _json.SerializeToString(e)); }