Beispiel #1
0
        private TraktMovieScrobble CreateMovieScrobbleData(ITrackingInfo info)
        {
            try
            {
                // create scrobble data
                TraktMovieScrobble scrobbleData = new TraktMovieScrobble
                {
                    Title                = info.Title,
                    Year                 = info.Year > 1900 ? info.Year.ToString() : null,
                    IMDBID               = info.ID_IMDB,
                    TMDBID               = info.ID_TMDB,
                    PluginVersion        = TraktSettings.Version,
                    MediaCenter          = "Mediaportal",
                    MediaCenterVersion   = Assembly.GetEntryAssembly().GetName().Version.ToString(),
                    MediaCenterBuildDate = String.Empty,
                    UserName             = TraktSettings.Username,
                    Password             = TraktSettings.Password
                };

                return(scrobbleData);
            }
            catch (Exception e)
            {
                TraktLogger.Error("Error creating scrobble data: {0}", e.Message);
                return(null);
            }
        }
        private void OnStoppedMovie(MFMovie movie)
        {
            if (TraktSettings.AccountStatus != ConnectionState.Connected)
            {
                return;
            }

            if (!TraktSettings.BlockedFilenames.Contains(movie.File) && !TraktSettings.BlockedFolders.Any(f => movie.File.ToLowerInvariant().Contains(f.ToLowerInvariant())))
            {
                TraktLogger.Info("Stopped My Films movie playback: '{0}'", movie.Title);

                CurrentMovie = null;
                StopScrobble();

                // send cancelled watching state
                Thread cancelWatching = new Thread(delegate()
                {
                    TraktMovieScrobble scrobbleData = new TraktMovieScrobble {
                        UserName = TraktSettings.Username, Password = TraktSettings.Password
                    };
                    TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.cancelwatching);
                    TraktAPI.TraktAPI.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "CancelWatching"
                };

                cancelWatching.Start();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Scrobbles a movie from a videoInfo object
        /// </summary>
        /// <returns>returns true if successfully scrobbled</returns>
        public static bool ScrobbleMovie(VideoInfo videoInfo, TraktScrobbleStates state)
        {
            TraktMovieScrobble scrobbleData = CreateMovieScrobbleData(videoInfo);

            if (scrobbleData == null)
            {
                return(false);
            }

            // get duration/position in minutes
            double duration = videoInfo.Runtime > 0.0 ? videoInfo.Runtime : g_Player.Duration / 60;
            double position = g_Player.CurrentPosition / 60;
            double progress = 0.0;

            if (duration > 0.0)
            {
                progress = (position / duration) * 100.0;
            }

            // sometimes with recordings/timeshifting we can get inaccurate player properties
            // adjust if duration is less than a typical movie
            scrobbleData.Duration = (duration < 15.0) ? "60" : Convert.ToInt32(duration).ToString();
            scrobbleData.Progress = (state == TraktScrobbleStates.scrobble) ? "100" : Convert.ToInt32(progress).ToString();

            TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, state);

            return(TraktLogger.LogTraktResponse(response));
        }
        /// <summary>
        /// Creates Scrobble data based on a IMDBMovie object
        /// </summary>
        /// <param name="movie">The movie to base the object on</param>
        /// <returns>The Trakt scrobble data to send</returns>
        public static TraktMovieScrobble CreateScrobbleData(MFMovie movie)
        {
            string username = TraktSettings.Username;
            string password = TraktSettings.Password;

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            TraktMovieScrobble scrobbleData = new TraktMovieScrobble
            {
                Title                = movie.Title,
                Year                 = movie.Year.ToString(),
                IMDBID               = movie.IMDBNumber,
                TMDBID               = movie.TMDBNumber,
                PluginVersion        = TraktSettings.Version,
                MediaCenter          = "Mediaportal",
                MediaCenterVersion   = Assembly.GetEntryAssembly().GetName().Version.ToString(),
                MediaCenterBuildDate = String.Empty,
                UserName             = username,
                Password             = password
            };

            return(scrobbleData);
        }
Beispiel #5
0
        public static TraktMovieScrobble CreateMovieScrobbleData(VideoInfo info)
        {
            try
            {
                // create scrobble data
                TraktMovieScrobble scrobbleData = new TraktMovieScrobble
                {
                    Title                = info.Title,
                    Year                 = info.Year,
                    PluginVersion        = TraktSettings.Version,
                    MediaCenter          = "Mediaportal",
                    MediaCenterVersion   = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString(),
                    MediaCenterBuildDate = String.Empty,
                    UserName             = TraktSettings.Username,
                    Password             = TraktSettings.Password
                };

                return(scrobbleData);
            }
            catch (Exception e)
            {
                TraktLogger.Error("Error creating scrobble data: {0}", e.Message);
                return(null);
            }
        }
        public void StopScrobble()
        {
            if (TraktTimer != null)
            {
                TraktTimer.Dispose();
            }

            if (CurrentProgram == null)
            {
                return;
            }

            if (IsProgramWatched(CurrentProgram) && CurrentProgram.IsScrobbling)
            {
                ScrobbleProgram(CurrentProgram);
            }
            else
            {
                #region cancel watching
                TraktLogger.Info("Stopped playback of tv-live '{0}'", CurrentProgram.ToString());

                Thread cancelWatching = new Thread(delegate(object obj)
                {
                    VideoInfo videoInfo = obj as VideoInfo;
                    if (videoInfo == null)
                    {
                        return;
                    }

                    if (videoInfo.Type == VideoType.Series)
                    {
                        TraktEpisodeScrobble scrobbleData = new TraktEpisodeScrobble {
                            UserName = TraktSettings.Username, Password = TraktSettings.Password
                        };
                        TraktResponse response = TraktAPI.TraktAPI.ScrobbleEpisodeState(scrobbleData, TraktScrobbleStates.cancelwatching);
                        TraktLogger.LogTraktResponse(response);
                    }
                    else
                    {
                        TraktMovieScrobble scrobbleData = new TraktMovieScrobble {
                            UserName = TraktSettings.Username, Password = TraktSettings.Password
                        };
                        TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.cancelwatching);
                        TraktLogger.LogTraktResponse(response);
                    }
                })
                {
                    IsBackground = true,
                    Name         = "CancelWatching"
                };

                cancelWatching.Start(CurrentProgram);
                #endregion
            }

            CurrentProgram = null;
        }
        public bool Scrobble(string filename)
        {
            // check movie is from my films
            if (CurrentMovie == null)
            {
                return(false);
            }

            StopScrobble();

            // create 15 minute timer to send watching status
            #region scrobble timer
            TraktTimer = new Timer(new TimerCallback((stateInfo) =>
            {
                Thread.CurrentThread.Name = "Scrobble";

                MFMovie currentMovie = stateInfo as MFMovie;

                TraktLogger.Info("Scrobbling Movie {0}", currentMovie.Title);

                double duration = g_Player.Duration;
                double progress = 0.0;

                // get current progress of player (in seconds) to work out percent complete
                if (duration > 0.0)
                {
                    progress = (g_Player.CurrentPosition / duration) * 100.0;
                }

                // create Scrobbling Data
                TraktMovieScrobble scrobbleData = CreateScrobbleData(currentMovie);
                if (scrobbleData == null)
                {
                    return;
                }

                // set duration/progress in scrobble data
                scrobbleData.Duration = Convert.ToInt32(duration / 60).ToString();
                scrobbleData.Progress = Convert.ToInt32(progress).ToString();

                // set watching status on trakt
                TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.watching);
                TraktAPI.TraktAPI.LogTraktResponse(response);
            }), CurrentMovie, 3000, 900000);
            #endregion

            return(true);
        }
        private void OnWatchedMovie(MFMovie movie)
        {
            if (TraktSettings.AccountStatus != ConnectionState.Connected)
            {
                return;
            }

            CurrentMovie = null;

            if (!TraktSettings.BlockedFilenames.Contains(movie.File) && !TraktSettings.BlockedFolders.Any(f => movie.File.ToLowerInvariant().Contains(f.ToLowerInvariant())))
            {
                Thread scrobbleMovie = new Thread(delegate(object obj)
                {
                    MFMovie watchedMovie = obj as MFMovie;
                    if (watchedMovie == null)
                    {
                        return;
                    }

                    // show trakt rating dialog
                    ShowRateDialog(watchedMovie);

                    TraktLogger.Info("My Films movie considered watched: '{0}'", watchedMovie.Title);

                    // get scrobble data to send to api
                    TraktMovieScrobble scrobbleData = CreateScrobbleData(watchedMovie);
                    if (scrobbleData == null)
                    {
                        return;
                    }

                    // set duration/progress in scrobble data
                    scrobbleData.Duration = Convert.ToInt32(g_Player.Duration / 60).ToString();
                    scrobbleData.Progress = "100";

                    TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.scrobble);
                    TraktAPI.TraktAPI.LogTraktResponse(response);
                    // UpdateRecommendations();
                })
                {
                    IsBackground = true,
                    Name         = "Scrobble"
                };

                scrobbleMovie.Start(movie);
            }
        }
        private void HandleScrobble(IPlayerSlotController psc, bool starting)
        {
            try
            {
                IPlayerContext pc = PlayerContext.GetPlayerContext(psc);
                if (pc == null)
                {
                    return;
                }

                bool removePsc = HandleTasks(psc, starting);

                AbstractScrobble    scrobbleData;
                TraktScrobbleStates state;
                if (TryCreateScrobbleData(psc, pc, starting, out scrobbleData, out state))
                {
                    ServiceRegistration.Get <ILogger>().Debug("Trakt.tv: [{5}] {0}, Duration {1}, Percent {2}, PSC.Duration {3}, PSC.ResumePosition {4}",
                                                              scrobbleData.Title, scrobbleData.Duration, scrobbleData.Progress, _progressUpdateWorks[psc].Duration, _progressUpdateWorks[psc].ResumePosition, state);

                    TraktMovieScrobble movie = scrobbleData as TraktMovieScrobble;
                    if (movie != null)
                    {
                        TraktAPI.ScrobbleMovieState(movie, state);
                    }

                    TraktEpisodeScrobble episode = scrobbleData as TraktEpisodeScrobble;
                    if (episode != null)
                    {
                        TraktAPI.ScrobbleEpisodeState(episode, state);
                    }
                }

                if (removePsc)
                {
                    lock (_syncObj)
                        _progressUpdateWorks.Remove(psc);
                }
            }
            catch (ThreadAbortException)
            { }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("Trakt.tv: Exception while scrobbling", ex);
            }
        }
Beispiel #10
0
        public bool Scrobble(string filename)
        {
            if (currentVideo == null)
            {
                return(false);
            }

            if (currentVideo.VideoKind == VideoKind.TvSeries)
            {
                TraktLogger.Info("Detected tv series '{0} - {1}x{2}' playing in OnlineVideos", currentVideo.Title, currentVideo.Season.ToString(), currentVideo.Episode.ToString());
            }
            else
            {
                TraktLogger.Info("Detected movie '{0}' playing in OnlineVideos", currentVideo.Title);
            }

            #region scrobble timer
            TraktTimer = new Timer(new TimerCallback((stateInfo) =>
            {
                Thread.CurrentThread.Name = "Scrobble";

                ITrackingInfo videoInfo = stateInfo as ITrackingInfo;

                // get duration in minutes
                double duration = g_Player.Duration / 60;
                double progress = 0.0;

                // get current progress of player
                if (g_Player.Duration > 0.0)
                {
                    progress = (g_Player.CurrentPosition / g_Player.Duration) * 100.0;
                }

                TraktEpisodeScrobble scrobbleEpisodeData = null;
                TraktMovieScrobble scrobbleMovieData     = null;
                TraktResponse response = null;

                if (videoInfo.VideoKind == VideoKind.TvSeries)
                {
                    scrobbleEpisodeData = CreateEpisodeScrobbleData(videoInfo);
                    if (scrobbleEpisodeData == null)
                    {
                        return;
                    }
                    scrobbleEpisodeData.Duration = Convert.ToInt32(duration).ToString();
                    scrobbleEpisodeData.Progress = Convert.ToInt32(progress).ToString();
                    response = TraktAPI.TraktAPI.ScrobbleEpisodeState(scrobbleEpisodeData, TraktScrobbleStates.watching);
                }
                else
                {
                    scrobbleMovieData = CreateMovieScrobbleData(videoInfo);
                    if (scrobbleMovieData == null)
                    {
                        return;
                    }
                    scrobbleMovieData.Duration = Convert.ToInt32(duration).ToString();
                    scrobbleMovieData.Progress = Convert.ToInt32(progress).ToString();
                    response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleMovieData, TraktScrobbleStates.watching);
                }

                TraktAPI.TraktAPI.LogTraktResponse(response);
            }), currentVideo, 3000, 900000);
            #endregion

            return(true);
        }
Beispiel #11
0
        /// <summary>
        /// Event gets triggered on playback events in OnlineVideos
        /// The TrackVideoPlayback event gets fired on Playback Start, Playback Ended
        /// and Playback Stopped (if percentage watched is greater than 0.8).
        /// </summary>
        private void TrackVideoPlayback(ITrackingInfo info, double percentPlayed)
        {
            if (info.VideoKind == VideoKind.Movie || info.VideoKind == VideoKind.TvSeries)
            {
                // Started Playback
                // Bug in OnlineVideos 0.31 reports incorrect percentage
                if (percentPlayed > 1.0)
                {
                    percentPlayed = 1 / percentPlayed;
                }
                if (percentPlayed < 0.8)
                {
                    currentVideo = info;
                    return;
                }

                // Show Rating Dialog
                ShowRateDialog(info);

                // Playback Ended or Stopped and Considered Watched
                // TrackVideoPlayback event only gets fired on Stopped if > 80% watched
                TraktLogger.Info("Playback of '{0}' is considered watched at {1:0.00}%", info.Title, (percentPlayed * 100).ToString());

                Thread scrobbleThread = new Thread(delegate(object o)
                {
                    ITrackingInfo videoInfo = o as ITrackingInfo;

                    // duration in minutes
                    double duration = g_Player.Duration / 60;
                    double progress = 100.0;

                    TraktEpisodeScrobble scrobbleEpisodeData = null;
                    TraktMovieScrobble scrobbleMovieData     = null;
                    TraktResponse response = null;

                    if (videoInfo.VideoKind == VideoKind.TvSeries)
                    {
                        scrobbleEpisodeData = CreateEpisodeScrobbleData(videoInfo);
                        if (scrobbleEpisodeData == null)
                        {
                            return;
                        }
                        scrobbleEpisodeData.Duration = Convert.ToInt32(duration).ToString();
                        scrobbleEpisodeData.Progress = Convert.ToInt32(progress).ToString();
                        response = TraktAPI.TraktAPI.ScrobbleEpisodeState(scrobbleEpisodeData, TraktScrobbleStates.scrobble);
                    }
                    else
                    {
                        scrobbleMovieData = CreateMovieScrobbleData(videoInfo);
                        if (scrobbleMovieData == null)
                        {
                            return;
                        }
                        scrobbleMovieData.Duration = Convert.ToInt32(duration).ToString();
                        scrobbleMovieData.Progress = Convert.ToInt32(progress).ToString();
                        response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleMovieData, TraktScrobbleStates.scrobble);
                    }

                    TraktAPI.TraktAPI.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Scrobble"
                };

                scrobbleThread.Start(info);
            }
        }
Beispiel #12
0
        public void StopScrobble()
        {
            if (TraktTimer != null)
            {
                TraktTimer.Dispose();
            }

            if (CurrentRecording == null)
            {
                return;
            }

            // get current progress of player
            double progress = 0.0;

            if (g_Player.Duration > 0.0)
            {
                progress = (g_Player.CurrentPosition / g_Player.Duration) * 100.0;
            }

            TraktLogger.Debug("Current Position: {0}, Duration: {1}", g_Player.CurrentPosition.ToString(), g_Player.Duration.ToString());
            TraktLogger.Debug(string.Format("Percentage of '{0}' watched is {1}%", CurrentRecording.Title, progress > 100.0 ? "100" : progress.ToString("N2")));

            // if recording is at least 80% complete, consider watched
            // consider watched with invalid progress as well, we should never be exactly 0.0
            if ((progress == 0.0 || progress >= 80.0) && CurrentRecording.IsScrobbling)
            {
                // Show rate dialog
                ShowRateDialog(CurrentRecording);

                #region scrobble
                Thread scrobbleRecording = new Thread(delegate(object obj)
                {
                    VideoInfo videoInfo = obj as VideoInfo;
                    if (videoInfo == null)
                    {
                        return;
                    }

                    TraktLogger.Info("Playback of '{0}' in Argus tv-recording is considered watched.", videoInfo.ToString());

                    if (videoInfo.Type == VideoType.Series)
                    {
                        BasicHandler.ScrobbleEpisode(videoInfo, TraktScrobbleStates.scrobble);
                    }
                    else
                    {
                        BasicHandler.ScrobbleMovie(videoInfo, TraktScrobbleStates.scrobble);
                    }
                })
                {
                    IsBackground = true,
                    Name         = "Scrobble"
                };

                scrobbleRecording.Start(CurrentRecording);
                #endregion
            }
            else
            {
                #region cancel watching
                TraktLogger.Info("Stopped playback of Argus tv-recording '{0}'", CurrentRecording.ToString());

                Thread cancelWatching = new Thread(delegate(object obj)
                {
                    VideoInfo videoInfo = obj as VideoInfo;
                    if (videoInfo == null)
                    {
                        return;
                    }

                    if (videoInfo.Type == VideoType.Series)
                    {
                        TraktEpisodeScrobble scrobbleData = new TraktEpisodeScrobble {
                            UserName = TraktSettings.Username, Password = TraktSettings.Password
                        };
                        TraktResponse response = TraktAPI.TraktAPI.ScrobbleEpisodeState(scrobbleData, TraktScrobbleStates.cancelwatching);
                        TraktLogger.LogTraktResponse(response);
                    }
                    else
                    {
                        TraktMovieScrobble scrobbleData = new TraktMovieScrobble {
                            UserName = TraktSettings.Username, Password = TraktSettings.Password
                        };
                        TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.cancelwatching);
                        TraktLogger.LogTraktResponse(response);
                    }
                })
                {
                    IsBackground = true,
                    Name         = "CancelWatching"
                };

                cancelWatching.Start(CurrentRecording);
                #endregion
            }

            CurrentRecording = null;
        }
Beispiel #13
0
        public void StopScrobble()
        {
            if (TraktTimer != null)
            {
                TraktTimer.Dispose();
            }

            if (CurrentMovie == null)
            {
                return;
            }

            // if movie is atleast XX% complete, consider watched
            if ((g_Player.CurrentPosition / (g_Player.Duration == 0.0 ? CurrentMovie.RunTime * 60.0 : g_Player.Duration)) >= WatchedPercent / 100.0)
            {
                ShowRateDialog(CurrentMovie);

                #region scrobble
                Thread scrobbleMovie = new Thread(delegate(object o)
                {
                    IMDBMovie movie = o as IMDBMovie;
                    if (movie == null)
                    {
                        return;
                    }

                    TraktLogger.Info("MyVideos movie is considered watched '{0}'", movie.Title);

                    // get scrobble data to send to api
                    TraktMovieScrobble scrobbleData = CreateScrobbleData(movie);
                    if (scrobbleData == null)
                    {
                        return;
                    }

                    // set duration/progress in scrobble data
                    Double duration       = g_Player.Duration == 0.0 ? movie.RunTime * 60.0 : g_Player.Duration;
                    scrobbleData.Duration = Convert.ToInt32(duration / 60.0).ToString();
                    scrobbleData.Progress = "100";

                    TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.scrobble);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Scrobble"
                };

                scrobbleMovie.Start(CurrentMovie);
                #endregion
            }
            else
            {
                #region cancel watching
                TraktLogger.Info("Stopped MyVideos movie playback '{0}'", CurrentMovie.Title);

                // stop scrobbling
                Thread cancelWatching = new Thread(delegate()
                {
                    TraktMovieScrobble scrobbleData = new TraktMovieScrobble {
                        UserName = TraktSettings.Username, Password = TraktSettings.Password
                    };
                    TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.cancelwatching);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "CancelWatching"
                };

                cancelWatching.Start();
                #endregion
            }

            CurrentMovie = null;
        }
Beispiel #14
0
        public bool Scrobble(string filename)
        {
            StopScrobble();

            // stop check if not valid player type for plugin handler
            if (g_Player.IsTV || g_Player.IsTVRecording)
            {
                return(false);
            }

            // lookup movie by filename
            IMDBMovie movie  = new IMDBMovie();
            int       result = VideoDatabase.GetMovieInfo(filename, ref movie);

            if (result == -1)
            {
                return(false);
            }

            CurrentMovie = movie;

            // create timer 15 minute timer to send watching status
            #region scrobble timer
            TraktTimer = new Timer(new TimerCallback((stateInfo) =>
            {
                Thread.CurrentThread.Name = "Scrobble";

                IMDBMovie currentMovie = stateInfo as IMDBMovie;

                TraktLogger.Info("Scrobbling Movie {0}", currentMovie.Title);

                // get online runtime if local one unavailable to be retrieved
                double duration = g_Player.Duration == 0.0 ? currentMovie.RunTime * 60.0 : g_Player.Duration;
                double progress = 0.0;

                // get current progress of player (in seconds) to work out percent complete
                if (duration > 0.0)
                {
                    progress = (g_Player.CurrentPosition / duration) * 100.0;
                }

                TraktLogger.Debug(string.Format("Percentage of {0} is {1}%", currentMovie.Title, progress.ToString("N2")));

                // create Scrobbling Data
                TraktMovieScrobble scrobbleData = CreateScrobbleData(currentMovie);
                if (scrobbleData == null)
                {
                    return;
                }

                // set duration/progress in scrobble data
                scrobbleData.Duration = Convert.ToInt32(duration / 60).ToString();
                scrobbleData.Progress = Convert.ToInt32(progress).ToString();

                // set watching status on trakt
                TraktResponse response = TraktAPI.TraktAPI.ScrobbleMovieState(scrobbleData, TraktScrobbleStates.watching);
                TraktLogger.LogTraktResponse(response);
            }), movie, 3000, 900000);
            #endregion

            return(true);
        }
        /// <summary>
        /// Creates Scrobble data based on a DBMovieInfo object
        /// </summary>
        /// <param name="psc"></param>
        /// <param name="pc">PlayerContext</param>
        /// <param name="starting"></param>
        /// <param name="scrobbleData"></param>
        /// <param name="state"></param>
        /// <returns>The Trakt scrobble data to send</returns>
        private bool TryCreateScrobbleData(IPlayerSlotController psc, IPlayerContext pc, bool starting, out AbstractScrobble scrobbleData, out TraktScrobbleStates state)
        {
            scrobbleData = null;
            state        = starting ? TraktScrobbleStates.watching : TraktScrobbleStates.scrobble;
            if (_settings.Settings.Authentication == null)
            {
                return(false);
            }

            string username = _settings.Settings.Authentication.Username;
            string password = _settings.Settings.Authentication.Password;

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(false);
            }

            // For canceling the watching, it is to have no TraktMovieScrobble.
            if (pc.CurrentMediaItem == null)
            {
                if (starting)
                {
                    return(false);
                }
                state = TraktScrobbleStates.cancelwatching;
                return(true);
            }

            bool isMovie  = pc.CurrentMediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID);
            bool isSeries = pc.CurrentMediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID);

            if (!isMovie && !isSeries)
            {
                return(false);
            }

            string title = pc.CurrentPlayer != null ? pc.CurrentPlayer.MediaItemTitle : null;
            IMediaPlaybackControl pmc = pc.CurrentPlayer as IMediaPlaybackControl;
            TimeSpan currentPosition;

            if (pmc != null)
            {
                _progressUpdateWorks[psc].Duration = pmc.Duration;
                currentPosition = pmc.CurrentTime;
            }
            else
            {
                // Player is already removed on stopping, so take the resume position if available
                currentPosition = _progressUpdateWorks[psc].ResumePosition;
            }

            int progress = currentPosition == TimeSpan.Zero ? (starting ? 0 : 100) : Math.Min((int)(currentPosition.TotalSeconds * 100 / _progressUpdateWorks[psc].Duration.TotalSeconds), 100);

            string   value;
            int      iValue;
            DateTime dtValue;
            long     lValue;

            if (isMovie)
            {
                TraktMovieScrobble movie = new TraktMovieScrobble();
                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MovieAspect.ATTR_IMDB_ID, out value) && !string.IsNullOrWhiteSpace(value))
                {
                    movie.IMDBID = value;
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MovieAspect.ATTR_TMDB_ID, out iValue) && iValue > 0)
                {
                    movie.TMDBID = iValue.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MediaAspect.ATTR_RECORDINGTIME, out dtValue))
                {
                    movie.Year = dtValue.Year.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MovieAspect.ATTR_RUNTIME_M, out iValue) && iValue > 0)
                {
                    movie.Duration = iValue.ToString();
                }

                scrobbleData = movie;
            }
            if (isSeries)
            {
                TraktEpisodeScrobble series = new TraktEpisodeScrobble();
                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_IMDB_ID, out value) && !string.IsNullOrWhiteSpace(value))
                {
                    series.IMDBID = value;
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_TVDB_ID, out iValue))
                {
                    series.TVDBID = iValue.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_SERIESNAME, out value) && !string.IsNullOrWhiteSpace(value))
                {
                    series.Title = value;
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_FIRSTAIRED, out dtValue))
                {
                    series.Year = dtValue.Year.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_SEASON, out iValue))
                {
                    series.Season = iValue.ToString();
                }
                List <int> intList;
                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_EPISODE, out intList) && intList.Any())
                {
                    series.Episode = intList.First().ToString(); // TODO: multi episode files?!
                }
                scrobbleData = series;
            }

            // Fallback duration info
            if (string.IsNullOrWhiteSpace(scrobbleData.Duration) && MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, VideoAspect.ATTR_DURATION, out lValue) && lValue > 0)
            {
                scrobbleData.Duration = (lValue / 60).ToString();
            }

            if (string.IsNullOrWhiteSpace(scrobbleData.Title))
            {
                scrobbleData.Title = title;
            }

            scrobbleData.Progress = progress.ToString();
            if (!starting && progress < WATCHED_PERCENT)
            {
                state = TraktScrobbleStates.cancelwatching;
            }

            scrobbleData.PluginVersion        = TraktSettings.Version;
            scrobbleData.MediaCenter          = "MediaPortal 2";
            scrobbleData.MediaCenterVersion   = Assembly.GetEntryAssembly().GetName().Version.ToString();
            scrobbleData.MediaCenterBuildDate = String.Empty;
            scrobbleData.Username             = username;
            scrobbleData.Password             = password;
            return(true);
        }