Ejemplo n.º 1
0
        internal void CopyFrom(TvShowSeason season)
        {
            Season = season.Season;

            var c  = Episodes.Count;
            var ec = season.Episodes.Count;

            while (c > ec)
            {
                Episodes.Remove(Episodes.ElementAt(--c));
            }

            for (var i = 0; i < ec; i++)
            {
                TvShowEpisode episode;
                if (c < i + 1)
                {
                    episode = new TvShowEpisode();
                    Episodes.Add(episode);
                }
                else
                {
                    episode = Episodes.ElementAt(i);
                }

                episode.CopyFrom(season.Episodes.ElementAt(i));
            }
        }
Ejemplo n.º 2
0
        public void MergeEpisodes(IEnumerable <ITvShowEpisodeInfo> episodes, bool subtitlesNeeded)
        {
            episodes = episodes.OrderBy(e => e.Season, new SeasonComparer()).ThenBy(e => e.Episode);

            ITvShowEpisodeInfo lastEpisode = null;

            foreach (var episodeInfo in episodes)
            {
                var season = Seasons.FirstOrDefault(s => s.Season == episodeInfo.Season);
                if (season == null)
                {
                    season = new TvShowSeason {
                        TvShowId = Id, TvShow = this, Season = episodeInfo.Season
                    };
                    Seasons.Add(season);
                }

                var episode = season.Episodes.FirstOrDefault(e => e.Episode == episodeInfo.Episode);
                if (episode == null)
                {
                    episode = new TvShowEpisode {
                        TvShowSeason = season
                    };
                    season.Episodes.Add(episode);
                    episode.Episode                    = episodeInfo.Episode;
                    episode.BackgroundDownload         = AutoDownload;
                    episode.BackgroundSubtitleDownload = AutoDownload && subtitlesNeeded;
                }

                episode.AirDate  = episodeInfo.AirDate;
                episode.Name     = episodeInfo.Name;
                episode.Overview = episodeInfo.Overview;

                lastEpisode = episodeInfo;
            }

            if (lastEpisode != null)
            {
                for (var i = Seasons.Count - 1; i >= 0; i--)
                {
                    var season = Seasons.ElementAt(i);
                    if (season.Season > lastEpisode.Season)
                    {
                        Seasons.Remove(season);
                    }
                    else if (season.Season == lastEpisode.Season)
                    {
                        for (var j = season.Episodes.Count - 1; j >= 0; j--)
                        {
                            var episode = season.Episodes.ElementAt(j);
                            if (episode.Episode > lastEpisode.Episode)
                            {
                                season.Episodes.Remove(episode);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void CopyFrom(IEntity entity)
        {
            var external = Helper.ConvertTo <TvShow>(entity);

            CopyFrom(external);

            AutoDownload   = external.AutoDownload;
            IsActive       = external.IsActive;
            Status         = external.Status;
            LastUpdateDate = external.LastUpdateDate;

            var c  = Seasons.Count;
            var ec = external.Seasons.Count;

            while (c > ec)
            {
                Seasons.Remove(Seasons.ElementAt(--c));
            }

            for (var i = 0; i < ec; i++)
            {
                TvShowSeason season;
                if (c < i + 1)
                {
                    season = new TvShowSeason {
                        TvShowId = Id, TvShow = this
                    };
                    Seasons.Add(season);
                }
                else
                {
                    season = Seasons.ElementAt(i);
                }

                season.CopyFrom(external.Seasons.ElementAt(i));
            }
        }
Ejemplo n.º 4
0
        public void MergeEpisodes(IEnumerable<ITvShowEpisodeInfo> episodes, bool subtitlesNeeded) {
            episodes = episodes.OrderBy(e => e.Season, new SeasonComparer()).ThenBy(e => e.Episode);

            ITvShowEpisodeInfo lastEpisode = null;
            foreach (var episodeInfo in episodes) {
                var season = Seasons.FirstOrDefault(s => s.Season == episodeInfo.Season);
                if (season == null) {
                    season = new TvShowSeason { TvShowId = Id, TvShow = this, Season = episodeInfo.Season };
                    Seasons.Add(season);
                }

                var episode = season.Episodes.FirstOrDefault(e => e.Episode == episodeInfo.Episode);
                if (episode == null) {
                    episode = new TvShowEpisode { TvShowSeason = season };
                    season.Episodes.Add(episode);
                    episode.Episode = episodeInfo.Episode;
                    episode.BackgroundDownload = AutoDownload;
                    episode.BackgroundSubtitleDownload = AutoDownload && subtitlesNeeded;
                }

                episode.AirDate = episodeInfo.AirDate;
                episode.Name = episodeInfo.Name;
                episode.Overview = episodeInfo.Overview;

                lastEpisode = episodeInfo;
            }

            if (lastEpisode != null) {
                for (var i = Seasons.Count - 1; i >= 0; i--) {
                    var season = Seasons.ElementAt(i);
                    if (season.Season > lastEpisode.Season)
                        Seasons.Remove(season);
                    else if (season.Season == lastEpisode.Season) {
                        for (var j = season.Episodes.Count - 1; j >= 0; j--) {
                            var episode = season.Episodes.ElementAt(j);
                            if (episode.Episode > lastEpisode.Episode)
                                season.Episodes.Remove(episode);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected override void CopyFrom(IEntity entity) {
            var external = Helper.ConvertTo<TvShow>(entity);

            CopyFrom(external);

            AutoDownload = external.AutoDownload;
            IsActive = external.IsActive;
            Status = external.Status;
            LastUpdateDate = external.LastUpdateDate;

            var c = Seasons.Count;
            var ec = external.Seasons.Count;
            while (c > ec) Seasons.Remove(Seasons.ElementAt(--c));

            for (var i = 0; i < ec; i++) {
                TvShowSeason season;
                if (c < i + 1) {
                    season = new TvShowSeason {TvShowId = Id, TvShow = this};
                    Seasons.Add(season);
                }
                else
                    season = Seasons.ElementAt(i);

                season.CopyFrom(external.Seasons.ElementAt(i));
            }
        }
Ejemplo n.º 6
0
        internal void CopyFrom(TvShowSeason season) {
            Season = season.Season;

            var c = Episodes.Count;
            var ec = season.Episodes.Count;
            while (c > ec) Episodes.Remove(Episodes.ElementAt(--c));

            for (var i = 0; i < ec; i++) {
                TvShowEpisode episode;
                if (c < i + 1) {
                    episode = new TvShowEpisode();
                    Episodes.Add(episode);
                }
                else
                    episode = Episodes.ElementAt(i);

                episode.CopyFrom(season.Episodes.ElementAt(i));
            }
        }