private void PopulateTraktDetails()
        {
            try
            {
                Trakt_ShowRepository repShows = new Trakt_ShowRepository();
                Show = repShows.GetByTraktID(TraktID);
                if (Show == null)
                {
                    return;
                }

                Trakt_EpisodeRepository repTvEps = new Trakt_EpisodeRepository();
                traktEpisodes = repTvEps.GetByShowID(Show.Trakt_ShowID);

                if (traktEpisodes.Count > 0)
                {
                    List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("Season", false, SortType.eInteger));
                    sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, SortType.eInteger));
                    traktEpisodes = Sorting.MultiSort <Trakt_Episode>(traktEpisodes, sortCriteria);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
示例#2
0
        public override void ProcessCommand()
        {
            try
            {
                CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
                CrossRef_AniDB_Trakt           xref        = repCrossRef.GetByID(CrossRef_AniDB_TraktID);
                if (xref == null)
                {
                    return;
                }

                Trakt_ShowRepository repShow = new Trakt_ShowRepository();
                Trakt_Show           tvShow  = repShow.GetByTraktID(xref.TraktID);
                if (tvShow == null)
                {
                    return;
                }

                string showName = "";
                if (tvShow != null)
                {
                    showName = tvShow.Title;
                }

                XMLService.Send_CrossRef_AniDB_Trakt(xref, showName);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error processing CommandRequest_WebCacheSendXRefAniDBTrakt: {0}" + ex.ToString(), ex);
                return;
            }
        }
示例#3
0
        private void PopulateTraktDetails()
        {
            try
            {
                Trakt_ShowRepository repShows = new Trakt_ShowRepository();
                Show = repShows.GetByTraktSlug(TraktID);
                if (Show == null)
                {
                    return;
                }

                Trakt_EpisodeRepository repTvEps = new Trakt_EpisodeRepository();
                traktEpisodes = repTvEps.GetByShowID(Show.Trakt_ShowID).OrderBy(a => a.Season).ThenBy(a => a.EpisodeNumber).ToList();
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
示例#4
0
        public override void ProcessCommand()
        {
            try
            {
                CrossRef_AniDB_TraktV2Repository repCrossRef = new CrossRef_AniDB_TraktV2Repository();
                CrossRef_AniDB_TraktV2           xref        = repCrossRef.GetByID(CrossRef_AniDB_TraktID);
                if (xref == null)
                {
                    return;
                }

                Trakt_ShowRepository repShow = new Trakt_ShowRepository();
                Trakt_Show           tvShow  = repShow.GetByTraktSlug(xref.TraktID);
                if (tvShow == null)
                {
                    return;
                }

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime           anime    = repAnime.GetByAnimeID(xref.AnimeID);
                if (anime == null)
                {
                    return;
                }

                string showName = "";
                if (tvShow != null)
                {
                    showName = tvShow.Title;
                }

                AzureWebAPI.Send_CrossRefAniDBTrakt(xref, anime.MainTitle);
            }
            catch (Exception ex)
            {
                logger.ErrorException(
                    "Error processing CommandRequest_WebCacheSendXRefAniDBTrakt: {0}" + ex.ToString(), ex);
                return;
            }
        }
示例#5
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID);

            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    // first check if the user wants to use the web cache
                    if (ServerSettings.WebCache_Trakt_Get)
                    {
                        try
                        {
                            List <Contract_Azure_CrossRef_AniDB_Trakt> contracts =
                                new List <Contract_Azure_CrossRef_AniDB_Trakt>();

                            List <JMMServer.Providers.Azure.CrossRef_AniDB_Trakt> resultsCache =
                                JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTrakt(AnimeID);
                            if (resultsCache != null && resultsCache.Count > 0)
                            {
                                foreach (JMMServer.Providers.Azure.CrossRef_AniDB_Trakt xref in resultsCache)
                                {
                                    TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(xref.TraktID);
                                    if (showInfo != null)
                                    {
                                        logger.Trace("Found trakt match on web cache for {0} - id = {1}", AnimeID,
                                                     showInfo.title);
                                        TraktTVHelper.LinkAniDBTrakt(AnimeID, (enEpisodeType)xref.AniDBStartEpisodeType,
                                                                     xref.AniDBStartEpisodeNumber,
                                                                     xref.TraktID, xref.TraktSeasonNumber, xref.TraktStartEpisodeNumber, true);
                                        return;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.ErrorException(ex.ToString(), ex);
                        }
                    }


                    // lets try to see locally if we have a tvDB link for this anime
                    // Trakt allows the use of TvDB ID's or their own Trakt ID's
                    CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository();
                    List <CrossRef_AniDB_TvDBV2>    xrefTvDBs       = repCrossRefTvDB.GetByAnimeID(session, AnimeID);
                    if (xrefTvDBs != null && xrefTvDBs.Count > 0)
                    {
                        foreach (CrossRef_AniDB_TvDBV2 tvXRef in xrefTvDBs)
                        {
                            // first search for this show by the TvDB ID
                            List <TraktV2SearchTvDBIDShowResult> searchResults =
                                TraktTVHelper.SearchShowByIDV2(TraktSearchIDType.tvdb,
                                                               tvXRef.TvDBID.ToString());
                            if (searchResults != null && searchResults.Count > 0)
                            {
                                // since we are searching by ID, there will only be one 'show' result
                                TraktV2Show resShow = null;
                                foreach (TraktV2SearchTvDBIDShowResult res in searchResults)
                                {
                                    if (res.ResultType == SearchIDType.Show)
                                    {
                                        resShow = res.show;
                                        break;
                                    }
                                }

                                if (resShow != null)
                                {
                                    TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(resShow.ids.slug);
                                    if (showInfo != null && showInfo.ids != null)
                                    {
                                        // make sure the season specified by TvDB also exists on Trakt
                                        Trakt_ShowRepository repShow   = new Trakt_ShowRepository();
                                        Trakt_Show           traktShow = repShow.GetByTraktSlug(session, showInfo.ids.slug);
                                        if (traktShow != null)
                                        {
                                            Trakt_SeasonRepository repSeasons  = new Trakt_SeasonRepository();
                                            Trakt_Season           traktSeason = repSeasons.GetByShowIDAndSeason(session,
                                                                                                                 traktShow.Trakt_ShowID,
                                                                                                                 xrefTvDBs[0].TvDBSeasonNumber);
                                            if (traktSeason != null)
                                            {
                                                logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}",
                                                             AnimeID, showInfo.title);
                                                TraktTVHelper.LinkAniDBTrakt(AnimeID,
                                                                             (AniDBAPI.enEpisodeType)tvXRef.AniDBStartEpisodeType,
                                                                             tvXRef.AniDBStartEpisodeNumber, showInfo.ids.slug,
                                                                             tvXRef.TvDBSeasonNumber, tvXRef.TvDBStartEpisodeNumber,
                                                                             true);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // finally lets try searching Trakt directly
                    string searchCriteria          = "";
                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    AniDB_Anime           anime    = repAnime.GetByAnimeID(session, AnimeID);
                    if (anime == null)
                    {
                        return;
                    }

                    searchCriteria = anime.MainTitle;

                    // if not wanting to use web cache, or no match found on the web cache go to TvDB directly
                    List <TraktV2SearchShowResult> results = TraktTVHelper.SearchShowV2(searchCriteria);
                    logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria);
                    if (ProcessSearchResults(session, results, searchCriteria))
                    {
                        return;
                    }


                    if (results.Count == 0)
                    {
                        foreach (AniDB_Anime_Title title in anime.GetTitles(session))
                        {
                            if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper())
                            {
                                continue;
                            }

                            if (searchCriteria.ToUpper() == title.Title.ToUpper())
                            {
                                continue;
                            }

                            results = TraktTVHelper.SearchShowV2(searchCriteria);
                            logger.Trace("Found {0} trakt results for search on {1}", results.Count, title.Title);
                            if (ProcessSearchResults(session, results, title.Title))
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString());
                return;
            }
        }
示例#6
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);
        }
示例#7
0
        public Trakt_Show GetByTraktShow(ISession session)
        {
            Trakt_ShowRepository repTraktShows = new Trakt_ShowRepository();

            return(repTraktShows.GetByTraktSlug(session, TraktID));
        }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID);

            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    // first check if the user wants to use the web cache
                    if (ServerSettings.WebCache_TvDB_Get)
                    {
                        try
                        {
                            CrossRef_AniDB_TraktResult crossRef = XMLService.Get_CrossRef_AniDB_Trakt(AnimeID);
                            if (crossRef != null)
                            {
                                TraktTVShow showInfo = TraktTVHelper.GetShowInfo(crossRef.TraktID);
                                if (showInfo != null)
                                {
                                    logger.Trace("Found trakt match on web cache for {0} - id = {1}", AnimeID, showInfo.title);
                                    TraktTVHelper.LinkAniDBTrakt(AnimeID, crossRef.TraktID, crossRef.TraktSeasonNumber, true);
                                    return;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.ErrorException(ex.ToString(), ex);
                        }
                    }


                    // lets try to see locally if we have a tvDB link for this anime
                    // Trakt allows the use of TvDB ID's or their own Trakt ID's
                    CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository();
                    List <CrossRef_AniDB_TvDBV2>    xrefTvDBs       = repCrossRefTvDB.GetByAnimeID(session, AnimeID);
                    if (xrefTvDBs != null && xrefTvDBs.Count == 1)                      //TODO this is temporary code, until trakt also allows multiple links
                    {
                        TraktTVShow showInfo = TraktTVHelper.GetShowInfo(xrefTvDBs[0].TvDBID);
                        if (showInfo != null)
                        {
                            // make sure the season specified by TvDB also exists on Trakt
                            Trakt_ShowRepository repShow   = new Trakt_ShowRepository();
                            Trakt_Show           traktShow = repShow.GetByTraktID(session, showInfo.TraktID);
                            if (traktShow != null)
                            {
                                Trakt_SeasonRepository repSeasons  = new Trakt_SeasonRepository();
                                Trakt_Season           traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, xrefTvDBs[0].TvDBSeasonNumber);
                                if (traktSeason != null)
                                {
                                    logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}", AnimeID, showInfo.title);
                                    TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true);
                                    return;
                                }
                            }
                        }
                    }

                    // if not lets try the tvdb web cache based on the same reasoning
                    if (ServerSettings.WebCache_TvDB_Get)
                    {
                        List <JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> cacheResults = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTvDB(AnimeID);
                        if (cacheResults != null && cacheResults.Count > 0)
                        {
                            TraktTVShow showInfo = TraktTVHelper.GetShowInfo(cacheResults[0].TvDBID);
                            if (showInfo != null)
                            {
                                // make sure the season specified by TvDB also exists on Trakt
                                Trakt_ShowRepository repShow   = new Trakt_ShowRepository();
                                Trakt_Show           traktShow = repShow.GetByTraktID(session, showInfo.TraktID);
                                if (traktShow != null)
                                {
                                    Trakt_SeasonRepository repSeasons  = new Trakt_SeasonRepository();
                                    Trakt_Season           traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, cacheResults[0].TvDBSeasonNumber);
                                    if (traktSeason != null)
                                    {
                                        logger.Trace("Found trakt match on web cache by using TvDBID {0} - id = {1}", AnimeID, showInfo.title);
                                        TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true);
                                        return;
                                    }
                                }
                            }
                        }
                    }

                    // finally lets try searching Trakt directly
                    string searchCriteria          = "";
                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    AniDB_Anime           anime    = repAnime.GetByAnimeID(session, AnimeID);
                    if (anime == null)
                    {
                        return;
                    }

                    searchCriteria = anime.MainTitle;

                    // if not wanting to use web cache, or no match found on the web cache go to TvDB directly
                    List <TraktTVShow> results = TraktTVHelper.SearchShow(searchCriteria);
                    logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria);
                    if (ProcessSearchResults(session, results, searchCriteria))
                    {
                        return;
                    }


                    if (results.Count == 0)
                    {
                        foreach (AniDB_Anime_Title title in anime.GetTitles(session))
                        {
                            if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper())
                            {
                                continue;
                            }

                            if (searchCriteria.ToUpper() == title.Title.ToUpper())
                            {
                                continue;
                            }

                            results = TraktTVHelper.SearchShow(searchCriteria);
                            logger.Trace("Found {0} trakt results for search on {1}", results.Count, title.Title);
                            if (ProcessSearchResults(session, results, title.Title))
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString());
                return;
            }
        }
示例#9
0
        public static void MigrateTraktLinks_V1_to_V2()
        {
            try
            {
                AniDB_AnimeRepository   repAnime = new AniDB_AnimeRepository();
                Trakt_EpisodeRepository repEps   = new Trakt_EpisodeRepository();
                Trakt_ShowRepository    repShows = new Trakt_ShowRepository();

                CrossRef_AniDB_TraktRepository   repCrossRefTrakt    = new CrossRef_AniDB_TraktRepository();
                CrossRef_AniDB_TraktV2Repository repCrossRefTraktNew = new CrossRef_AniDB_TraktV2Repository();

                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    List <CrossRef_AniDB_Trakt> xrefsTrakt = repCrossRefTrakt.GetAll();
                    foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt)
                    {
                        CrossRef_AniDB_TraktV2 xrefNew = new CrossRef_AniDB_TraktV2();
                        xrefNew.AnimeID           = xrefTrakt.AnimeID;
                        xrefNew.CrossRefSource    = xrefTrakt.CrossRefSource;
                        xrefNew.TraktID           = xrefTrakt.TraktID;
                        xrefNew.TraktSeasonNumber = xrefTrakt.TraktSeasonNumber;

                        Trakt_Show show = xrefTrakt.GetByTraktShow(session);
                        if (show != null)
                        {
                            xrefNew.TraktTitle = show.Title;
                        }

                        // determine start ep type
                        if (xrefTrakt.TraktSeasonNumber == 0)
                        {
                            xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special;
                        }
                        else
                        {
                            xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Episode;
                        }

                        xrefNew.AniDBStartEpisodeNumber = 1;
                        xrefNew.TraktStartEpisodeNumber = 1;

                        repCrossRefTraktNew.Save(xrefNew);
                    }

                    // create cross ref's for specials
                    foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt)
                    {
                        AniDB_Anime anime = repAnime.GetByAnimeID(xrefTrakt.AnimeID);
                        if (anime == null)
                        {
                            continue;
                        }

                        Trakt_Show show = xrefTrakt.GetByTraktShow(session);
                        if (show == null)
                        {
                            continue;
                        }

                        // this anime has specials
                        if (anime.EpisodeCountSpecial <= 0)
                        {
                            continue;
                        }

                        // this Trakt series has a season 0 (specials)
                        List <int> seasons = repEps.GetSeasonNumbersForSeries(show.Trakt_ShowID);
                        if (!seasons.Contains(0))
                        {
                            continue;
                        }

                        //make sure we are not doubling up
                        CrossRef_AniDB_TraktV2 temp = repCrossRefTraktNew.GetByTraktID(xrefTrakt.TraktID, 0, 1, xrefTrakt.AnimeID, (int)AniDBAPI.enEpisodeType.Special, 1);
                        if (temp != null)
                        {
                            continue;
                        }

                        CrossRef_AniDB_TraktV2 xrefNew = new CrossRef_AniDB_TraktV2();
                        xrefNew.AnimeID                 = xrefTrakt.AnimeID;
                        xrefNew.CrossRefSource          = xrefTrakt.CrossRefSource;
                        xrefNew.TraktID                 = xrefTrakt.TraktID;
                        xrefNew.TraktSeasonNumber       = 0;
                        xrefNew.TraktStartEpisodeNumber = 1;
                        xrefNew.AniDBStartEpisodeType   = (int)AniDBAPI.enEpisodeType.Special;
                        xrefNew.AniDBStartEpisodeNumber = 1;
                        xrefNew.TraktTitle              = show.Title;

                        repCrossRefTraktNew.Save(xrefNew);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Could not MigrateTraktLinks_V1_to_V2: " + ex.ToString(), ex);
            }
        }