Beispiel #1
0
        public void RefreshEpisodes()
        {
            allEpisodes = new List <AnimeEpisodeVM>();

            try
            {
                TvDBSummary summ = this.AniDB_Anime.TvSummary;

                // Normal episodes
                foreach (AnimeEpisodeVM ep in JMMServerHelper.GetEpisodesForSeries(this.AnimeSeriesID.Value))
                {
                    ep.SetTvDBInfo(summ);
                    allEpisodes.Add(ep);
                }

                List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>();
                sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeType", false, SortType.eInteger));
                sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, SortType.eInteger));
                allEpisodes = Sorting.MultiSort <AnimeEpisodeVM>(allEpisodes, sortCriteria);
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
Beispiel #2
0
        public void SetTvDBInfo()
        {
            this.RefreshAnime();

            TvDBSummary tvSummary = AniDB_Anime.TvSummary;

            SetTvDBInfo(tvSummary);
        }
Beispiel #3
0
        public void SetTvDBInfo()
        {
            //logger.Trace("SetTvDBInfo: RefreshAnime start: {0} - {1}", this.AnimeSeries.SeriesName, this.EpisodeNumberAndName);
            this.RefreshAnime();

            TvDBSummary tvSummary = AniDB_Anime.TvSummary;

            SetTvDBInfo(tvSummary);
        }
Beispiel #4
0
        public void RefreshEpisodes()
        {
            allEpisodes = new List <VM_AnimeEpisode_User>();

            try
            {
                TvDBSummary summ = Anime.TvSummary;

                // Normal episodes
                foreach (VM_AnimeEpisode_User ep in ShokoServerHelper.GetEpisodesForSeries(AnimeSeriesID))
                {
                    ep.SetTvDBInfo(summ);
                    allEpisodes.Add(ep);
                }
                allEpisodes = allEpisodes.OrderBy(a => a.EpisodeType).ThenBy(a => a.EpisodeNumber).ToList();
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
Beispiel #5
0
        public void RefreshEpisodes()
        {
            allEpisodes = new List <AnimeEpisodeVM>();

            try
            {
                DateTime start = DateTime.Now;
                List <JMMServerBinary.Contract_AnimeEpisode> eps = JMMServerVM.Instance.clientBinaryHTTP.GetEpisodesForSeries(AnimeSeriesID.Value,
                                                                                                                              JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                TimeSpan ts = DateTime.Now - start;
                logger.Info("Got episode data from service: {0} in {1} ms", AniDB_Anime.FormattedTitle, ts.TotalMilliseconds);

                start = DateTime.Now;

                TvDBSummary tvSummary = AniDB_Anime.TvSummary;
                // Normal episodes
                List <AnimeEpisodeVM> specials = new List <AnimeEpisodeVM>();
                foreach (JMMServerBinary.Contract_AnimeEpisode ep in eps)
                {
                    AnimeEpisodeVM epvm = new AnimeEpisodeVM(ep);
                    epvm.SetTvDBInfo(tvSummary);
                    allEpisodes.Add(epvm);
                }

                ts = DateTime.Now - start;
                logger.Info("Got episode contracts: {0} in {1} ms", AniDB_Anime.FormattedTitle, ts.TotalMilliseconds);

                start = DateTime.Now;
                allEpisodes.Sort();
                ts = DateTime.Now - start;
                logger.Info("Sorted episode contracts: {0} in {1} ms", AniDB_Anime.FormattedTitle, ts.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Set the Episode image and overview, also over-write the episode name if user has selected this
        /// </summary>
        /// <param name="dictTvDBEpisodes"></param>
        /// <param name="dictTvDBSeasons"></param>
        /// <param name="dictTvDBSeasonsSpecials"></param>
        /// <param name="tvDBCrossRef"></param>
        public void SetTvDBInfo(TvDBSummary tvSummary)
        {
            TvDBLinkExists  = false;
            TvDBLinkMissing = true;

            #region episode override
            // check if this episode has a direct tvdb over-ride
            if (tvSummary.DictTvDBCrossRefEpisodes.ContainsKey(AniDB_EpisodeID))
            {
                foreach (TvDB_EpisodeVM tvep in tvSummary.DictTvDBEpisodes.Values)
                {
                    if (tvSummary.DictTvDBCrossRefEpisodes[AniDB_EpisodeID] == tvep.Id)
                    {
                        if (string.IsNullOrEmpty(tvep.Overview))
                        {
                            this.EpisodeOverviewLoading = "Episode Overview Not Available";
                        }
                        else
                        {
                            this.EpisodeOverviewLoading = tvep.Overview;
                        }

                        if (string.IsNullOrEmpty(tvep.FullImagePathPlain) || !File.Exists(tvep.FullImagePath))
                        {
                            this.EpisodeImageLoading = @"/Images/EpisodeThumb_NotFound.png";
                            // if there is no proper image to show, we will hide it on the dashboard
                            ShowEpisodeImageInDashboard = false;
                        }
                        else
                        {
                            this.EpisodeImageLoading = tvep.FullImagePath;
                        }

                        if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                        {
                            EpisodeName = tvep.EpisodeName;
                        }

                        TvDBLinkExists  = true;
                        TvDBLinkMissing = false;

                        return;
                    }
                }
            }
            #endregion

            //logger.Trace("SetTvDBInfo: normal episodes start");

            #region normal episodes
            // now do stuff to improve performance
            if (this.EpisodeTypeEnum == JMMClient.EpisodeType.Episode)
            {
                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    //logger.Trace("SetTvDBInfo: sorting TvDB cross refs: {0} records", tvSummary.CrossRefTvDBV2.Count);

                    // find the xref that is right
                    // relies on the xref's being sorted by season number and then episode number (desc)
                    List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, JMMClient.SortType.eInteger));
                    List <CrossRef_AniDB_TvDBVMV2> tvDBCrossRef = Sorting.MultiSort <CrossRef_AniDB_TvDBVMV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                    //logger.Trace("SetTvDBInfo: looking for starting points");

                    bool foundStartingPoint          = false;
                    CrossRef_AniDB_TvDBVMV2 xrefBase = null;
                    foreach (CrossRef_AniDB_TvDBVMV2 xrefTV in tvDBCrossRef)
                    {
                        if (xrefTV.AniDBStartEpisodeType != (int)JMMClient.EpisodeType.Episode)
                        {
                            continue;
                        }
                        if (this.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                        {
                            foundStartingPoint = true;
                            xrefBase           = xrefTV;
                            break;
                        }
                    }

                    //logger.Trace("SetTvDBInfo: looking for starting points - done");

                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {
                        //logger.Trace("SetTvDBInfo: creating dictionary");

                        Dictionary <int, int>            dictTvDBSeasons  = null;
                        Dictionary <int, TvDB_EpisodeVM> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons  = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        //logger.Trace("SetTvDBInfo: creating dictionary - done");

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (this.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {
                                //logger.Trace("SetTvDBInfo: loading episode overview");
                                TvDB_EpisodeVM tvep = dictTvDBEpisodes[episodeNumber];
                                if (string.IsNullOrEmpty(tvep.Overview))
                                {
                                    this.EpisodeOverviewLoading = "Episode Overview Not Available";
                                }
                                else
                                {
                                    this.EpisodeOverviewLoading = tvep.Overview;
                                }

                                //logger.Trace("SetTvDBInfo: loading episode overview - done");

                                if (string.IsNullOrEmpty(tvep.FullImagePathPlain) || !File.Exists(tvep.FullImagePath))
                                {
                                    this.EpisodeImageLoading = @"/Images/EpisodeThumb_NotFound.png";
                                    // if there is no proper image to show, we will hide it on the dashboard
                                    ShowEpisodeImageInDashboard = false;
                                }
                                else
                                {
                                    this.EpisodeImageLoading = tvep.FullImagePath;
                                }

                                //logger.Trace("SetTvDBInfo: episode image - done");

                                if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                {
                                    EpisodeName = tvep.EpisodeName;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            //logger.Trace("SetTvDBInfo: normal episodes finish");

            #region special episodes
            if (this.EpisodeTypeEnum == JMMClient.EpisodeType.Special)
            {
                // find the xref that is right
                // relies on the xref's being sorted by season number and then episode number (desc)
                List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>();
                sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, JMMClient.SortType.eInteger));
                List <CrossRef_AniDB_TvDBVMV2> tvDBCrossRef = Sorting.MultiSort <CrossRef_AniDB_TvDBVMV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                bool foundStartingPoint          = false;
                CrossRef_AniDB_TvDBVMV2 xrefBase = null;
                foreach (CrossRef_AniDB_TvDBVMV2 xrefTV in tvDBCrossRef)
                {
                    if (xrefTV.AniDBStartEpisodeType != (int)JMMClient.EpisodeType.Special)
                    {
                        continue;
                    }
                    if (this.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                    {
                        foundStartingPoint = true;
                        xrefBase           = xrefTV;
                        break;
                    }
                }

                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {
                        Dictionary <int, int>            dictTvDBSeasons  = null;
                        Dictionary <int, TvDB_EpisodeVM> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons  = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (this.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {
                                TvDB_EpisodeVM tvep = dictTvDBEpisodes[episodeNumber];
                                this.EpisodeOverviewLoading = tvep.Overview;

                                if (string.IsNullOrEmpty(tvep.FullImagePathPlain) || !File.Exists(tvep.FullImagePath))
                                {
                                    this.EpisodeImageLoading = @"/Images/EpisodeThumb_NotFound.png";
                                    // if there is no proper image to show, we will hide it on the dashboard
                                    ShowEpisodeImageInDashboard = false;
                                }
                                else
                                {
                                    this.EpisodeImageLoading = tvep.FullImagePath;
                                }

                                if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                {
                                    EpisodeName = tvep.EpisodeName;
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }
Beispiel #7
0
        public void SetTvDBInfo(TvDBSummary tvSummary)
        {
            this.EpisodeOverview = "Episode Overview Not Available";
            this.EpisodeImageLocation = "";

            #region episode override
            // check if this episode has a direct tvdb over-ride
            if (tvSummary.DictTvDBCrossRefEpisodes.ContainsKey(AniDB_EpisodeID))
            {
                foreach (TvDB_EpisodeVM tvep in tvSummary.DictTvDBEpisodes.Values)
                {
                    if (tvSummary.DictTvDBCrossRefEpisodes[AniDB_EpisodeID] == tvep.Id)
                    {
                        if (string.IsNullOrEmpty(tvep.Overview))
                            this.EpisodeOverview = "Episode Overview Not Available";
                        else
                            this.EpisodeOverview = tvep.Overview;

                        if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                        {
                            if (string.IsNullOrEmpty(tvep.OnlineImagePath))
                                this.EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                            else
                                this.EpisodeImageLocation = tvep.OnlineImagePath;
                        }
                        else
                            this.EpisodeImageLocation = tvep.FullImagePath;

                        if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                            EpisodeName = tvep.EpisodeName;

                        return;
                    }
                }
            }
            #endregion

            #region normal episodes
            // now do stuff to improve performance
            if (this.EpisodeTypeEnum == enEpisodeType.Episode)
            {
                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // find the xref that is right
                    // relies on the xref's being sorted by season number and then episode number (desc)
                    List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                    List<CrossRef_AniDB_TvDBVMV2> tvDBCrossRef = Sorting.MultiSort<CrossRef_AniDB_TvDBVMV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                    bool foundStartingPoint = false;
                    CrossRef_AniDB_TvDBVMV2 xrefBase = null;
                    foreach (CrossRef_AniDB_TvDBVMV2 xrefTV in tvDBCrossRef)
                    {
                        if (xrefTV.AniDBStartEpisodeType != (int)enEpisodeType.Episode) continue;
                        if (this.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                        {
                            foundStartingPoint = true;
                            xrefBase = xrefTV;
                            break;
                        }
                    }

                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {

                        Dictionary<int, int> dictTvDBSeasons = null;
                        Dictionary<int, TvDB_EpisodeVM> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (this.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {

                                TvDB_EpisodeVM tvep = dictTvDBEpisodes[episodeNumber];
                                if (string.IsNullOrEmpty(tvep.Overview))
                                    this.EpisodeOverview = "Episode Overview Not Available";
                                else
                                    this.EpisodeOverview = tvep.Overview;

                                if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                                {
                                    if (string.IsNullOrEmpty(tvep.OnlineImagePath))
                                        this.EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                                    else
                                        this.EpisodeImageLocation = tvep.OnlineImagePath;
                                }
                                else
                                    this.EpisodeImageLocation = tvep.FullImagePath;

                                if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                    EpisodeName = tvep.EpisodeName;
                            }
                        }
                    }
                }
            }
            #endregion

            #region special episodes
            if (this.EpisodeTypeEnum == enEpisodeType.Special)
            {
                // find the xref that is right
                // relies on the xref's being sorted by season number and then episode number (desc)
                List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                List<CrossRef_AniDB_TvDBVMV2> tvDBCrossRef = Sorting.MultiSort<CrossRef_AniDB_TvDBVMV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                bool foundStartingPoint = false;
                CrossRef_AniDB_TvDBVMV2 xrefBase = null;
                foreach (CrossRef_AniDB_TvDBVMV2 xrefTV in tvDBCrossRef)
                {
                    if (xrefTV.AniDBStartEpisodeType != (int)enEpisodeType.Special) continue;
                    if (this.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                    {
                        foundStartingPoint = true;
                        xrefBase = xrefTV;
                        break;
                    }
                }

                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {

                        Dictionary<int, int> dictTvDBSeasons = null;
                        Dictionary<int, TvDB_EpisodeVM> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (this.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {
                                TvDB_EpisodeVM tvep = dictTvDBEpisodes[episodeNumber];
                                this.EpisodeOverview = tvep.Overview;

                                if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                                {
                                    if (string.IsNullOrEmpty(tvep.OnlineImagePath))
                                        this.EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                                    else
                                        this.EpisodeImageLocation = tvep.OnlineImagePath;
                                }
                                else
                                    this.EpisodeImageLocation = tvep.FullImagePath;

                                if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                    EpisodeName = tvep.EpisodeName;
                            }
                        }
                    }
                }
            }
            #endregion
        }
Beispiel #8
0
 public void ClearTvDBData()
 {
     tvSummary = null;
 }
        public void SetTvDBInfo(TvDBSummary tvSummary)
        {
            EpisodeOverview      = Translation.EpisodeOverviewNA;
            EpisodeImageLocation = "";

            #region episode override

            // check if this episode has a direct tvdb over-ride
            if (tvSummary.DictTvDBCrossRefEpisodes.ContainsKey(AniDB_EpisodeID))
            {
                foreach (TvDB_Episode tvep in tvSummary.DictTvDBEpisodes.Values)
                {
                    if (tvSummary.DictTvDBCrossRefEpisodes[AniDB_EpisodeID] == tvep.Id)
                    {
                        if (string.IsNullOrEmpty(tvep.Overview))
                        {
                            EpisodeOverview = Translation.EpisodeOverviewNA;
                        }
                        else
                        {
                            EpisodeOverview = tvep.Overview;
                        }

                        if (string.IsNullOrEmpty(tvep.GetFullImagePath()) || !File.Exists(tvep.GetFullImagePath()))
                        {
                            EpisodeImageLocation = string.IsNullOrEmpty(tvep.GetOnlineImagePath()) ? @"/Images/EpisodeThumb_NotFound.png" : tvep.GetOnlineImagePath();
                        }
                        else
                        {
                            EpisodeImageLocation = tvep.GetFullImagePath();
                        }

                        if (VM_ShokoServer.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                        {
                            _epname = tvep.EpisodeName;
                        }

                        return;
                    }
                }
            }

            #endregion

            #region normal episodes

            // now do stuff to improve performance
            if (EpisodeTypeEnum == Shoko.Models.Enums.EpisodeType.Episode)
            {
                if (tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // find the xref that is right
                    // relies on the xref's being sorted by season number and then episode number (desc)
                    List <CrossRef_AniDB_TvDBV2> tvDBCrossRef = tvSummary.CrossRefTvDBV2.OrderByDescending(a => a.AniDBStartEpisodeNumber).ToList();
                    bool foundStartingPoint        = false;
                    CrossRef_AniDB_TvDBV2 xrefBase = null;
                    foreach (CrossRef_AniDB_TvDBV2 xrefTV in tvDBCrossRef)
                    {
                        if (xrefTV.AniDBStartEpisodeType != (int)Shoko.Models.Enums.EpisodeType.Episode)
                        {
                            continue;
                        }
                        if (EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                        {
                            foundStartingPoint = true;
                            xrefBase           = xrefTV;
                            break;
                        }
                    }

                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {
                        Dictionary <int, int>          dictTvDBSeasons  = null;
                        Dictionary <int, TvDB_Episode> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons  = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }
                        if (dictTvDBEpisodes != null && dictTvDBSeasons != null)
                        {
                            if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                            {
                                int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                                if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                                {
                                    TvDB_Episode tvep = dictTvDBEpisodes[episodeNumber];
                                    if (string.IsNullOrEmpty(tvep.Overview))
                                    {
                                        EpisodeOverview = "Episode Overview Not Available";
                                    }
                                    else
                                    {
                                        EpisodeOverview = tvep.Overview;
                                    }

                                    if (string.IsNullOrEmpty(tvep.GetFullImagePath()) || !File.Exists(tvep.GetFullImagePath()))
                                    {
                                        if (string.IsNullOrEmpty(tvep.GetOnlineImagePath()))
                                        {
                                            EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                                        }
                                        else
                                        {
                                            EpisodeImageLocation = tvep.GetOnlineImagePath();
                                        }
                                    }
                                    else
                                    {
                                        EpisodeImageLocation = tvep.GetFullImagePath();
                                    }

                                    if (VM_ShokoServer.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                    {
                                        _epname = tvep.EpisodeName;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            #endregion


            #region special episodes

            if ((EpisodeTypeEnum == Shoko.Models.Enums.EpisodeType.Special) && tvSummary.CrossRefTvDBV2 != null)
            {
                // find the xref that is right
                // relies on the xref's being sorted by season number and then episode number (desc)

                List <CrossRef_AniDB_TvDBV2> tvDBCrossRef = tvSummary.CrossRefTvDBV2.OrderByDescending(a => a.AniDBStartEpisodeNumber).ToList();

                bool foundStartingPoint        = false;
                CrossRef_AniDB_TvDBV2 xrefBase = null;
                foreach (CrossRef_AniDB_TvDBV2 xrefTV in tvDBCrossRef)
                {
                    if (xrefTV.AniDBStartEpisodeType != (int)Shoko.Models.Enums.EpisodeType.Special)
                    {
                        continue;
                    }
                    if (EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                    {
                        foundStartingPoint = true;
                        xrefBase           = xrefTV;
                        break;
                    }
                }

                if (tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    if (foundStartingPoint)
                    {
                        Dictionary <int, int>          dictTvDBSeasons  = null;
                        Dictionary <int, TvDB_Episode> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons  = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }
                        if (dictTvDBEpisodes != null && dictTvDBSeasons != null)
                        {
                            if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                            {
                                int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                                if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                                {
                                    TvDB_Episode tvep = dictTvDBEpisodes[episodeNumber];
                                    EpisodeOverview = tvep.Overview;

                                    if (string.IsNullOrEmpty(tvep.GetFullImagePath()) || !File.Exists(tvep.GetFullImagePath()))
                                    {
                                        if (string.IsNullOrEmpty(tvep.GetOnlineImagePath()))
                                        {
                                            EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                                        }
                                        else
                                        {
                                            EpisodeImageLocation = tvep.GetOnlineImagePath();
                                        }
                                    }
                                    else
                                    {
                                        EpisodeImageLocation = tvep.GetFullImagePath();
                                    }

                                    if (VM_ShokoServer.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                    {
                                        _epname = tvep.EpisodeName;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            #endregion
        }
Beispiel #10
0
        public void SetTvDBInfo(TvDBSummary tvSummary)
        {
            this.EpisodeOverview      = "Episode Overview Not Available";
            this.EpisodeImageLocation = "";

            #region episode override
            // check if this episode has a direct tvdb over-ride
            if (tvSummary.DictTvDBCrossRefEpisodes.ContainsKey(AniDB_EpisodeID))
            {
                foreach (TvDB_EpisodeVM tvep in tvSummary.DictTvDBEpisodes.Values)
                {
                    if (tvSummary.DictTvDBCrossRefEpisodes[AniDB_EpisodeID] == tvep.Id)
                    {
                        if (string.IsNullOrEmpty(tvep.Overview))
                        {
                            this.EpisodeOverview = "Episode Overview Not Available";
                        }
                        else
                        {
                            this.EpisodeOverview = tvep.Overview;
                        }

                        if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                        {
                            if (string.IsNullOrEmpty(tvep.OnlineImagePath))
                            {
                                this.EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                            }
                            else
                            {
                                this.EpisodeImageLocation = tvep.OnlineImagePath;
                            }
                        }
                        else
                        {
                            this.EpisodeImageLocation = tvep.FullImagePath;
                        }

                        if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                        {
                            EpisodeName = tvep.EpisodeName;
                        }

                        return;
                    }
                }
            }
            #endregion

            #region normal episodes
            // now do stuff to improve performance
            if (this.EpisodeTypeEnum == enEpisodeType.Episode)
            {
                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // find the xref that is right
                    // relies on the xref's being sorted by season number and then episode number (desc)
                    List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                    List <CrossRef_AniDB_TvDBVMV2> tvDBCrossRef = Sorting.MultiSort <CrossRef_AniDB_TvDBVMV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                    bool foundStartingPoint          = false;
                    CrossRef_AniDB_TvDBVMV2 xrefBase = null;
                    foreach (CrossRef_AniDB_TvDBVMV2 xrefTV in tvDBCrossRef)
                    {
                        if (xrefTV.AniDBStartEpisodeType != (int)enEpisodeType.Episode)
                        {
                            continue;
                        }
                        if (this.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                        {
                            foundStartingPoint = true;
                            xrefBase           = xrefTV;
                            break;
                        }
                    }

                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {
                        Dictionary <int, int>            dictTvDBSeasons  = null;
                        Dictionary <int, TvDB_EpisodeVM> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons  = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (this.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {
                                TvDB_EpisodeVM tvep = dictTvDBEpisodes[episodeNumber];
                                if (string.IsNullOrEmpty(tvep.Overview))
                                {
                                    this.EpisodeOverview = "Episode Overview Not Available";
                                }
                                else
                                {
                                    this.EpisodeOverview = tvep.Overview;
                                }

                                if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                                {
                                    if (string.IsNullOrEmpty(tvep.OnlineImagePath))
                                    {
                                        this.EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                                    }
                                    else
                                    {
                                        this.EpisodeImageLocation = tvep.OnlineImagePath;
                                    }
                                }
                                else
                                {
                                    this.EpisodeImageLocation = tvep.FullImagePath;
                                }

                                if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                {
                                    EpisodeName = tvep.EpisodeName;
                                }
                            }
                        }
                    }
                }
            }
            #endregion


            #region special episodes
            if (this.EpisodeTypeEnum == enEpisodeType.Special)
            {
                // find the xref that is right
                // relies on the xref's being sorted by season number and then episode number (desc)
                List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>();
                sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                List <CrossRef_AniDB_TvDBVMV2> tvDBCrossRef = Sorting.MultiSort <CrossRef_AniDB_TvDBVMV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                bool foundStartingPoint          = false;
                CrossRef_AniDB_TvDBVMV2 xrefBase = null;
                foreach (CrossRef_AniDB_TvDBVMV2 xrefTV in tvDBCrossRef)
                {
                    if (xrefTV.AniDBStartEpisodeType != (int)enEpisodeType.Special)
                    {
                        continue;
                    }
                    if (this.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                    {
                        foundStartingPoint = true;
                        xrefBase           = xrefTV;
                        break;
                    }
                }

                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {
                        Dictionary <int, int>            dictTvDBSeasons  = null;
                        Dictionary <int, TvDB_EpisodeVM> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons  = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (this.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {
                                TvDB_EpisodeVM tvep = dictTvDBEpisodes[episodeNumber];
                                this.EpisodeOverview = tvep.Overview;

                                if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                                {
                                    if (string.IsNullOrEmpty(tvep.OnlineImagePath))
                                    {
                                        this.EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png";
                                    }
                                    else
                                    {
                                        this.EpisodeImageLocation = tvep.OnlineImagePath;
                                    }
                                }
                                else
                                {
                                    this.EpisodeImageLocation = tvep.FullImagePath;
                                }

                                if (JMMServerVM.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                {
                                    EpisodeName = tvep.EpisodeName;
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }