/// <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);
            }
        }
示例#2
0
        /// <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);
            }
        }
示例#3
0
        /// <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 Emby 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
                };
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error sending watching status update", ex, null);
            }
        }
示例#4
0
        /// <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);
            }
        }