Beispiel #1
0
        private TraktEpisodeScrobble CreateScrobbleData(FileLocal episode)
        {
            string seriesid   = null;
            int    seasonidx  = 0;
            int    episodeidx = 0;

            if (episode.AnimeEpisodes == null || episode.AnimeEpisodes.Count == 0 || !GetTVDBEpisodeInfo(episode.AnimeEpisodes[0], out seriesid, out seasonidx, out episodeidx))
            {
                TraktLogger.Warning("Unable to scrobble episodes, no AniDb/TVDb reference in database yet. Episode will be manually marked as seen on sync when available.");
                return(null);
            }

            // create scrobble data
            try
            {
                TraktEpisodeScrobble scrobbleData = new TraktEpisodeScrobble
                {
                    Title                = episode.AniDB_File.AnimeSeries.SeriesName,
                    Year                 = GetStartYear(episode.AniDB_File.AnimeSeries),
                    Season               = seasonidx.ToString(),
                    Episode              = episodeidx.ToString(),
                    SeriesID             = seriesid,
                    PluginVersion        = TraktSettings.Version,
                    MediaCenter          = "Mediaportal",
                    MediaCenterVersion   = Assembly.GetEntryAssembly().GetName().Version.ToString(),
                    MediaCenterBuildDate = String.Empty,
                    UserName             = TraktSettings.Username,
                    Password             = TraktSettings.Password
                };

                return(scrobbleData);
            }
            catch
            {
                TraktLogger.Error("Failed to create scrobble data for '{0}'", episode.ToString());
                return(null);
            }
        }
Beispiel #2
0
        public void StopScrobble()
        {
            if (TraktTimer != null)
            {
                TraktTimer.Dispose();
            }

            if (CurrentEpisode == null)
            {
                return;
            }

            #region Scrobble
            Thread scrobbleEpisode = new Thread(delegate(object o)
            {
                FileLocal episode = o as FileLocal;
                if (episode == null)
                {
                    return;
                }

                TraktLogger.Info("My Anime episode considered watched '{0}'", episode.ToString());

                // get scrobble data to send to api
                TraktEpisodeScrobble scrobbleData = CreateScrobbleData(episode);
                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.ScrobbleEpisodeState(scrobbleData, TraktScrobbleStates.scrobble);
                TraktAPI.TraktAPI.LogTraktResponse(response);
            })
            {
                IsBackground = true,
                Name         = "Scrobble"
            };
            #endregion

            // if episode is atleast 90% complete, consider watched
            if ((g_Player.CurrentPosition / g_Player.Duration) >= 0.9)
            {
                ShowRateDialog(CurrentEpisode);
                scrobbleEpisode.Start(CurrentEpisode);
            }
            else
            {
                #region Cancel Watching
                TraktLogger.Info("Stopped My Anime episode playback '{0}'", CurrentEpisode.ToString());

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

                cancelWatching.Start();
            }

            CurrentEpisode = null;
        }
Beispiel #3
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 episode by filename
            List <FileLocal> files = FileLocal.GetAll();
            FileLocal        file  = files.FirstOrDefault(f => f.FileNameFull == filename);

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

            CurrentEpisode = file;
            TraktLogger.Info("Detected episode playing in My Anime: '{0}'", CurrentEpisode.ToString());

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

                FileLocal episode = stateInfo as FileLocal;
                if (episode == null)
                {
                    return;
                }

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

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

                TraktEpisodeScrobble scrobbleData = CreateScrobbleData(CurrentEpisode);
                if (scrobbleData == null)
                {
                    return;
                }

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

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

            return(true);
        }
        private TraktEpisodeScrobble CreateScrobbleData(FileLocal episode)
        {
            string seriesid = null;
            int seasonidx = 0;
            int episodeidx = 0;

            if (episode.AnimeEpisodes == null || episode.AnimeEpisodes.Count == 0 || !GetTVDBEpisodeInfo(episode.AnimeEpisodes[0], out seriesid, out seasonidx, out episodeidx))
            {
                TraktLogger.Warning("Unable to scrobble episodes, no AniDb/TVDb reference in database yet. Episode will be manually marked as seen on sync when available.");
                return null;
            }

            // create scrobble data
            try
            {
                TraktEpisodeScrobble scrobbleData = new TraktEpisodeScrobble
                {
                    Title = episode.AniDB_File.AnimeSeries.SeriesName,
                    Year = GetStartYear(episode.AniDB_File.AnimeSeries),
                    Season = seasonidx.ToString(),
                    Episode = episodeidx.ToString(),
                    SeriesID = seriesid,
                    PluginVersion = TraktSettings.Version,
                    MediaCenter = "Mediaportal",
                    MediaCenterVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(),
                    MediaCenterBuildDate = String.Empty,
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

                return scrobbleData;
            }
            catch
            {
                TraktLogger.Error("Failed to create scrobble data for '{0}'", episode.ToString());
                return null;
            }
        }
        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 episode by filename
            List<FileLocal> files = FileLocal.GetAll();
            FileLocal file = files.FirstOrDefault(f => f.FileNameFull == filename);
            if (file == null) return false;

            CurrentEpisode = file;
            TraktLogger.Info("Detected episode playing in My Anime: '{0}'", CurrentEpisode.ToString());

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

                FileLocal episode = stateInfo as FileLocal;
                if (episode == null) return;

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

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

                TraktEpisodeScrobble scrobbleData = CreateScrobbleData(CurrentEpisode);
                if (scrobbleData == null) return;

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

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

            return true;
        }
        private TraktEpisodeScrobble CreateScrobbleData(FileLocal episode)
        {
            string seriesid = null;
            int seasonidx = 0;
            int episodeidx = 0;

            if (!GetTVDBEpisodeInfo(episode.AnimeEpisodes[0], out seriesid, out seasonidx, out episodeidx)) return null;

            // create scrobble data
            try
            {
                TraktEpisodeScrobble scrobbleData = new TraktEpisodeScrobble
                {
                    Title = episode.AniDB_File.AnimeSeries.SeriesName,
                    Year = GetStartYear(episode.AniDB_File.AnimeSeries),
                    Season = seasonidx.ToString(),
                    Episode = episodeidx.ToString(),
                    SeriesID = seriesid,
                    PluginVersion = TraktSettings.Version,
                    MediaCenter = "Mediaportal",
                    MediaCenterVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(),
                    MediaCenterBuildDate = String.Empty,
                    UserName = TraktSettings.Username,
                    Password = TraktSettings.Password
                };

                return scrobbleData;
            }
            catch
            {
                TraktLogger.Error("Failed to create scrobble data for '{0}'", episode.ToString());
                return null;
            }
        }