예제 #1
0
        public bool Init(AnimeEpisode aniepisode)
        {
            try
            {
                if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password))
                {
                    return(false);
                }

                username = ServerSettings.Trakt_Username;
                password = Utils.CalculateSHA1(ServerSettings.Trakt_Password, Encoding.Default);

                imdb_id = "";
                AnimeSeries ser = aniepisode.GetAnimeSeries();
                if (ser == null)
                {
                    return(false);
                }

                CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
                CrossRef_AniDB_Trakt           xref        = repCrossRef.GetByAnimeID(ser.AniDB_ID);
                if (xref == null)
                {
                    return(false);
                }

                Trakt_ShowRepository repShows = new Trakt_ShowRepository();
                Trakt_Show           show     = repShows.GetByTraktID(xref.TraktID);
                if (show == null)
                {
                    return(false);
                }
                if (!show.TvDB_ID.HasValue)
                {
                    return(false);
                }

                tvdb_id = show.TvDB_ID.Value.ToString();
                title   = show.Title;
                year    = show.Year;

                int retEpNum = 0, retSeason = 0;
                GetTraktEpisodeNumber(aniepisode, show, xref.TraktSeasonNumber, ref retEpNum, ref retSeason);
                if (retEpNum < 0)
                {
                    return(false);
                }

                episode = retEpNum.ToString();
                season  = retSeason.ToString();

                AniDB_Episode aniep = aniepisode.AniDB_Episode;
                if (aniep != null)
                {
                    TimeSpan t         = TimeSpan.FromSeconds(aniep.LengthSeconds + 14);
                    int      toMinutes = int.Parse(Math.Round(t.TotalMinutes).ToString());
                    duration = toMinutes.ToString();
                }
                else
                {
                    duration = "25";
                }

                progress = "100";

                plugin_version       = "0.4";
                media_center_version = "1.2.0.1";
                media_center_date    = "Dec 17 2010";
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return(false);
            }

            return(true);
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                string aid     = Utils.GetParam("AnimeID");
                int    animeid = 0;
                int.TryParse(aid, out animeid);

                if (animeid <= 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                string uname = Utils.GetParam("uname");
                if (uname.Trim().Length == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
                CrossRef_AniDB_Trakt           xref        = null;

                // check for admin approved
                List <CrossRef_AniDB_Trakt> recs = repCrossRef.GetByAnimeIDApproved(animeid);
                if (recs.Count > 0)
                {
                    xref = recs[0];                                 // should only be one
                }
                // check for user specific
                if (xref == null)
                {
                    recs = repCrossRef.GetByAnimeIDUser(animeid, uname);
                    if (recs.Count > 0)
                    {
                        xref = recs[0];                                     // should only be one
                    }
                }

                // check for other users (anonymous)
                if (xref == null)
                {
                    // check for other users (anonymous)
                    recs = repCrossRef.GetByAnimeID(animeid);
                    if (recs.Count == 0)
                    {
                        Response.Write(Constants.ERROR_XML);
                        return;
                    }

                    // find the most popular result

                    List <CrossRefTraktStat> results = new List <CrossRefTraktStat>();
                    foreach (CrossRef_AniDB_Trakt xrefloc in recs)
                    {
                        bool found = false;
                        foreach (CrossRefTraktStat stat in results)
                        {
                            if (stat.TraktID.Equals(xrefloc.TraktID, StringComparison.InvariantCultureIgnoreCase) && stat.TraktSeason == xrefloc.TraktSeasonNumber)
                            {
                                found = true;
                                stat.ResultCount++;
                            }
                        }
                        if (!found)
                        {
                            CrossRefTraktStat stat = new CrossRefTraktStat();
                            stat.ResultCount = 1;
                            stat.TraktID     = xrefloc.TraktID;
                            stat.TraktSeason = xrefloc.TraktSeasonNumber;
                            stat.CrossRef    = xrefloc;
                            results.Add(stat);
                        }
                    }

                    CrossRefTraktStat mostPopular = null;
                    foreach (CrossRefTraktStat stat in results)
                    {
                        if (mostPopular == null)
                        {
                            mostPopular = stat;
                        }
                        else
                        {
                            if (stat.ResultCount > mostPopular.ResultCount)
                            {
                                mostPopular = stat;
                            }
                        }
                    }

                    xref = mostPopular.CrossRef;
                }

                CrossRef_AniDB_TraktResult result = new CrossRef_AniDB_TraktResult(xref);
                string ret = Utils.ConvertToXML(result, typeof(CrossRef_AniDB_TraktResult));
                Response.Write(ret);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return;
            }
        }