Esempio n. 1
0
        public void DownloadTvDBEpisode(TvDB_EpisodeVM episode, bool forceDownload)
        {
            if (string.IsNullOrEmpty(episode.Filename)) return;

            try
            {
                string url = string.Format(Constants.URLS.TvDB_Images, episode.Filename);
                string filename = episode.FullImagePath;

                ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.TvDB_Episode, episode, forceDownload);

                // check if this file has already been downloaded and exists
                if (!req.ForceDownload)
                {
                    // check to make sure the file actually exists
                    if (!File.Exists(episode.FullImagePath))
                    {
                        this.imagesToDownload.Add(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
                        return;
                    }

                    // the file exists so don't download it again
                    return;
                }

                this.imagesToDownload.Add(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
Esempio n. 2
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
        }