コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void KernelPlaybackStart(object sender, PlaybackProgressEventArgs e)
        {
            try
            {
                _logger.Info("TRAKT: Playback Started");
                // 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.User);

                if (traktUser == null)
                {
                    return;
                }
                // Still need to make sure it's a trakt monitored location before sending notice to trakt.tv
                if (traktUser.TraktLocations == null)
                {
                    return;
                }

                foreach (
                    var location in
                    traktUser.TraktLocations.Where(location => e.Item.Path.Contains(location + "\\")).Where(
                        location => e.Item is Episode || e.Item is Movie))
                {
                    var video = e.Item as Video;


                    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("Trakt: Error sending watching status update", ex, null);
            }
        }
コード例 #2
0
        private async Task EpisodeStatusUpdate(Episode episode, TraktUser traktUser, CancellationToken cancellationToken)
        {
            var traktPlaybackEpisodes = await _traktApi.SendGetPlaybackShowsRequest(traktUser, cancellationToken).ConfigureAwait(false);

            var playbackEpisode = Match.FindMatch(episode, traktPlaybackEpisodes);

            if (playbackEpisode != null)
            {
                try
                {
                    await _traktApi.SendEpisodeStatusUpdateAsync(episode, MediaStatus.Stop, traktUser, 100, cancellationToken).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Exception handled sending status update", ex);
                }
            }
        }
コード例 #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.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");
            }
        }
コード例 #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;
                }

                _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);
            }
        }
コード例 #5
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);
            }
        }