void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e) { if (!string.IsNullOrWhiteSpace(e.PlaySessionId)) { PingTranscodingJob(e.PlaySessionId, e.IsPaused); } }
/// <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; } if (!_traktApi.CanSync(e.Item, traktUser)) { return; } _logger.Debug(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) { _logger.Debug("Send movie status update"); await _traktApi.SendMovieStatusUpdateAsync(video as Movie, MediaStatus.Watching, traktUser, progressPercent). ConfigureAwait(false); } else if (video is Episode) { _logger.Debug("Send episode status update"); await _traktApi.SendEpisodeStatusUpdateAsync(video as Episode, MediaStatus.Watching, traktUser, progressPercent). 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); } }
void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) { var item = e.MediaInfo; if (item == null) { //_logger.Warn("PlaybackStart reported with null media info."); return; } var themeMedia = item as IThemeMedia; if (themeMedia != null && themeMedia.IsThemeMedia) { // Don't report theme song or local trailer playback return; } if (e.Users.Count == 0) { return; } var user = e.Users.First(); CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserStartedPlayingItemWithValues"), user.Name, item.Name), Type = "PlaybackStart", ShortOverview = string.Format(_localization.GetLocalizedString("AppDeviceValues"), e.ClientName, e.DeviceName), UserId = user.Id.ToString("N") }); }
/// <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); } }
/// <summary> /// Let trakt.tv know that the user is still actively watching the media. /// /// Event fires based on the interval that the connected client reports playback progress /// to the server. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void KernelPlaybackProgress(object sender, PlaybackProgressEventArgs e) { _logger.Debug("Playback Progress"); if (e.Users == null || !e.Users.Any() || e.Item == null) { _logger.Error("Event details incomplete. Cannot process current media"); return; } var playEvent = _progressEvents.FirstOrDefault(ev => ev.UserId.Equals(e.Users.First().Id) && ev.ItemId.Equals(e.Item.Id)); if (playEvent == null) return; // Only report progress to trakt every 5 minutes if ((DateTime.UtcNow - playEvent.LastApiAccess).TotalMinutes >= 5) { var video = e.Item as Video; var traktUser = UserHelper.GetTraktUser(e.Users.First()); if (traktUser == null) return; try { if (video is Movie) { await _traktApi.SendMovieStatusUpdateAsync(video as Movie, MediaStatus.Watching, traktUser). ConfigureAwait(false); } else if (video is Episode) { await _traktApi.SendEpisodeStatusUpdateAsync(video as Episode, MediaStatus.Watching, traktUser). ConfigureAwait(false); } } catch (Exception ex) { _logger.ErrorException("Exception handled sending status update", ex); } // Reset the value playEvent.LastApiAccess = DateTime.UtcNow; } }
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; var themeMedia = item as IThemeMedia; if (themeMedia != null && themeMedia.IsThemeMedia) { // Don't report theme song or local trailer playback return; } var notification = new NotificationRequest { NotificationType = type }; 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).ConfigureAwait(false); }
void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) { var item = e.MediaInfo; if (item == null) { _logger.Warn("PlaybackStart reported with null media info."); return; } var type = GetPlaybackNotificationType(item.MediaType); SendPlaybackNotification(type, e); }
private void PlaybackStart(object sender, PlaybackProgressEventArgs e) { Plugin.Logger.Debug("Notifications - PlayBack"); if (Plugin.Instance.Configuration.Notifications.PlayBack) { if (e.Users == null || !e.Users.Any() || e.Item == null) { Plugin.Logger.Error("Notifications - Event details incomplete. Cannot process current media"); return; } _pusher.Push(e.Users.FirstOrDefault() + " is watching " + e.Item, 0); } }
private async void SendPlaybackNotification(string type, PlaybackProgressEventArgs e) { var user = e.Users.FirstOrDefault(); var item = e.MediaInfo; if (e.Item != null && e.Item.Parent == null) { // Don't report theme song or local trailer playback // TODO: This will also cause movie specials to not be reported return; } var notification = new NotificationRequest { NotificationType = type, ExcludeUserIds = e.Users.Select(i => i.Id.ToString("N")).ToList() }; 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).ConfigureAwait(false); }
/// <summary> /// Let Last.fm know when a user has started listening to a track /// </summary> private void PlaybackStart(object sender, PlaybackProgressEventArgs e) { //We only care about audio if (!(e.Item is Audio)) return; var user = e.Users.FirstOrDefault(); if (user == null) { Plugin.Logger.Debug("No user"); return; } var lastfmUser = Utils.UserHelpers.GetUser(user); if (lastfmUser == null) { Plugin.Logger.Debug("Could not find last.fm user"); return; } //User doesn't want to scrobble if (!lastfmUser.Options.Scrobble) { Plugin.Logger.Debug("{0} ({1}) does not want to scrobble", user.Name, lastfmUser.Username); return; } if (string.IsNullOrWhiteSpace(lastfmUser.SessionKey)) { Plugin.Logger.Info("No session key present, aborting"); return; } var item = e.Item as Audio; _apiClient.NowPlaying(item, lastfmUser); }