Esempio n. 1
0
        private void MergeSeasons(InternalSeries from)
        {
            foreach (var season in from.Seasons)
            {
                var matchingSeason = Seasons.FirstOrDefault(t => t.SeasonNumber == season.SeasonNumber);
                if (matchingSeason == null)
                {
                    Seasons.Add(season);
                }
                else
                {
                    matchingSeason.AirDate       = string.IsNullOrEmpty(matchingSeason.AirDate) ? season.AirDate : matchingSeason.AirDate;
                    matchingSeason.Name          = matchingSeason.Name ?? season.Name;
                    matchingSeason.Summary       = matchingSeason.Summary ?? season.Summary;
                    matchingSeason.EpisodesCount = matchingSeason.EpisodesCount == 0
                        ? season.EpisodesCount
                        : matchingSeason.EpisodesCount;

                    if (season.Episodes != null && season.Episodes.Count > 0 && matchingSeason.Episodes != null)
                    {
                        MergeEpisodes(matchingSeason, season);
                    }
                }
            }
        }
Esempio n. 2
0
        public static TmdbSeasonImages GetSeasonImages(int?id, int season, bool forceUpdate = false)
        {
            if (id == null)
            {
                return(null);
            }

            // if its in our cache return it
            var seasonImages = Seasons.FirstOrDefault(s => s.Id == id && s.Season == season);

            if (seasonImages != null)
            {
                if (forceUpdate)
                {
                    return(seasonImages);
                }

                // but only if the request is not very old
                if (DateTime.Now.Subtract(new TimeSpan(TraktSettings.TmdbSeasonImageMaxCacheAge, 0, 0, 0, 0)) < Convert.ToDateTime(seasonImages.RequestAge))
                {
                    return(seasonImages);
                }

                TraktLogger.Info("Season image cache expired. TMDb ID = '{0}', Season = '{1}', Request Age = '{2}'", id, season, seasonImages.RequestAge);
                RemoveSeasonImagesFromCache(seasonImages, season);
            }

            // get movie images from tmdb and add to the cache
            seasonImages = TmdbAPI.TmdbAPI.GetSeasonImages(id.ToString(), season);
            AddSeasonImagesToCache(seasonImages, id, season);

            return(seasonImages);
        }
Esempio n. 3
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);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void RefreshByShowId(long showId, int selectedSeason = 1)
        {
            IsLoading = true;

            _tvshowtimeApiService.GetShow(showId, string.Empty, true)
            .Subscribe(async(showResponse) =>
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    LastLoadingDate = DateTime.Now;

                    Seasons.Clear();

                    Show = showResponse.Show;
                    RaisePropertyChanged(nameof(Show));

                    foreach (var episode in Show.Episodes)
                    {
                        var seasonGroup = Seasons.FirstOrDefault(s => s.SeasonNumber == episode.Season);
                        if (seasonGroup == null)
                        {
                            seasonGroup = new ShowSeasonGroup {
                                SeasonNumber = episode.Season
                            };
                            Seasons.Add(seasonGroup);
                        }

                        seasonGroup.Episodes.Add(episode);
                    }

                    RaisePropertyChanged(nameof(MinSeasonNumber));
                    RaisePropertyChanged(nameof(MaxSeasonNumber));

                    SelectedSeason = Seasons.FirstOrDefault(s => s.SeasonNumber == selectedSeason);

                    IsLoading = false;
                });
            },
                       async(error) =>
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    IsLoading = false;
                });

                _toastNotificationService.ShowErrorNotification("An error happened. Please retry later.");
            });
        }
        private void ButtonRemoveSeason_OnClick(object sender, RoutedEventArgs e)
        {
            string       messageBoxText = $"Do you really want to delete season \"{SeasonComboBox.SelectedItem}\"?";
            const string caption        = "Season Editor";

            var messageBoxResult = MessageBox.Show(messageBoxText, caption, MessageBoxButton.YesNo, MessageBoxImage.Warning);

            switch (messageBoxResult)
            {
            case MessageBoxResult.Yes:
                _dataView.RemoveSeason(SelectedSeason);
                SelectedSeason = Seasons.FirstOrDefault();
                OnPropertyChanged(nameof(SelectedSeason));
                SeasonComboBox.SelectedItem = SelectedSeason;
                break;
            }
        }
Esempio n. 6
0
        public PlayersMainViewModel()
        {
            players = new ObservableCollection <PlayerInTeam>(NBAContext.Instance.PlayerInTeam);
            teams   = new ObservableCollection <Team>(NBAContext.Instance.Team);
            seasons = new ObservableCollection <Season>(NBAContext.Instance.Season);
            players.CollectionChanged += (sender, e) =>
            {
                UpdateEntities();
            };
            filteredPlayers = new PagedEnumerable <PlayerInTeam>(players, MAX_PAGE_SIZE);

            filterSeason = Seasons.FirstOrDefault();
            filterTeam   = Teams.FirstOrDefault();
            //UpdateEntities();
            SetFirstCharInNameFilterAll = new ActionCommand(() => FirstCharInNameFilter = null);
            SetFirstCharInNameFilterA   = new ActionCommand(() => FirstCharInNameFilter = 'A');
            SetFirstCharInNameFilterB   = new ActionCommand(() => FirstCharInNameFilter = 'B');
            SetFirstCharInNameFilterC   = new ActionCommand(() => FirstCharInNameFilter = 'C');
            SetFirstCharInNameFilterD   = new ActionCommand(() => FirstCharInNameFilter = 'D');
            SetFirstCharInNameFilterE   = new ActionCommand(() => FirstCharInNameFilter = 'E');
            SetFirstCharInNameFilterF   = new ActionCommand(() => FirstCharInNameFilter = 'F');
            SetFirstCharInNameFilterG   = new ActionCommand(() => FirstCharInNameFilter = 'G');
            SetFirstCharInNameFilterH   = new ActionCommand(() => FirstCharInNameFilter = 'H');
            SetFirstCharInNameFilterI   = new ActionCommand(() => FirstCharInNameFilter = 'I');
            SetFirstCharInNameFilterJ   = new ActionCommand(() => FirstCharInNameFilter = 'J');
            SetFirstCharInNameFilterK   = new ActionCommand(() => FirstCharInNameFilter = 'K');
            SetFirstCharInNameFilterL   = new ActionCommand(() => FirstCharInNameFilter = 'L');
            SetFirstCharInNameFilterM   = new ActionCommand(() => FirstCharInNameFilter = 'M');
            SetFirstCharInNameFilterN   = new ActionCommand(() => FirstCharInNameFilter = 'N');
            SetFirstCharInNameFilterP   = new ActionCommand(() => FirstCharInNameFilter = 'P');
            SetFirstCharInNameFilterQ   = new ActionCommand(() => FirstCharInNameFilter = 'Q');
            SetFirstCharInNameFilterR   = new ActionCommand(() => FirstCharInNameFilter = 'R');
            SetFirstCharInNameFilterS   = new ActionCommand(() => FirstCharInNameFilter = 'S');
            SetFirstCharInNameFilterT   = new ActionCommand(() => FirstCharInNameFilter = 'T');
            SetFirstCharInNameFilterU   = new ActionCommand(() => FirstCharInNameFilter = 'U');
            SetFirstCharInNameFilterV   = new ActionCommand(() => FirstCharInNameFilter = 'V');
            SetFirstCharInNameFilterW   = new ActionCommand(() => FirstCharInNameFilter = 'W');
            SetFirstCharInNameFilterX   = new ActionCommand(() => FirstCharInNameFilter = 'X');
            SetFirstCharInNameFilterY   = new ActionCommand(() => FirstCharInNameFilter = 'Y');
            SetFirstCharInNameFilterZ   = new ActionCommand(() => FirstCharInNameFilter = 'Z');
            GoFirstPageCommand          = new ActionCommand(() => CurrentPageNum = 0);
            GoPriviusPageCommand        = new ActionCommand(() => CurrentPageNum--);
            GoNextPageCommand           = new ActionCommand(() => CurrentPageNum++);
            GoLastPageCommand           = new ActionCommand(() => CurrentPageNum = PageCount);
        }
        public FilmsEditingViewModel(Film film)
        {
            CurrentFilm = film;


            if (film.Id != 0)
            {
                OriginalFilm = DbMethods.GetFilmFromDbById(film.Id);
                NotifyOfPropertyChange(() => CanSelectSeason);
            }
            Seasons = film.Id != 0
                ? new BindableCollection <Season>(OriginalFilm.Seasons)
                : new BindableCollection <Season>();
            SelectedSeason = Seasons.FirstOrDefault();

            NotifyOfPropertyChange(() => CreateFilmVisibility);
            NotifyOfPropertyChange(() => SaveChangesVisibility);
        }
        private void ButtonAddSeason_OnClick(object sender, RoutedEventArgs e)
        {
            var newSeasonWindow = new NewSeasonWindow();
            var dialogResult    = newSeasonWindow.ShowDialog();

            if (dialogResult != true)
            {
                return;
            }

            var newSeason = new Season
            {
                Name        = newSeasonWindow.NewSeason.Name,
                Description = newSeasonWindow.NewSeason.Description,
                StartDate   = newSeasonWindow.NewSeason.StartDate,
                EndDate     = newSeasonWindow.NewSeason.EndDate
            };

            _dataView.AddSeason(newSeason);
            SelectedSeason = Seasons.FirstOrDefault(s => s.Name == newSeason.Name);
            OnPropertyChanged(nameof(SelectedSeason));
            SeasonComboBox.SelectedItem = SelectedSeason;
        }
Esempio n. 9
0
 private void GoToNextSeason()
 {
     SelectedSeason = Seasons.FirstOrDefault(s => s.SeasonNumber == SelectedSeason.SeasonNumber + 1);
 }
Esempio n. 10
0
 private void GoToPreviousSeason()
 {
     SelectedSeason = Seasons.FirstOrDefault(s => s.SeasonNumber == SelectedSeason.SeasonNumber - 1);
 }
Esempio n. 11
0
        public void ApplyFilter(bool reset, bool notifications = true)
        {
            if (AllDownloads == null || !AllDownloads.Any())
            {
                Fetch();
                return;
            }

            _mutexFilter.WaitOne();

            FavSeasonData currentFavSeason  = null;
            SeasonData    currentSeasonData = null;
            int           seasonNr          = -1;

            ObservableCollection <FavSeasonData> newSeasons    = new ObservableCollection <FavSeasonData>();
            ObservableCollection <DownloadData>  newNonSeasons = new ObservableCollection <DownloadData>();

            bool setNewEpisodes = false;
            bool setNewUpdates  = false;

            if (_isNewShow)
            {
                notifications = false;
            }
            reset = reset || _isNewShow;
            if (!reset)
            {
                newSeasons    = Seasons;
                newNonSeasons = NonSeasons;
            }

            UploadData currentUpload       = null;
            bool       ignoreCurrentUpload = false;

            foreach (var download in AllDownloads)
            {
                //upload stuff --------------------------------------------------------------------
                if (currentUpload == null || currentUpload != download.Upload)
                {
                    currentUpload       = download.Upload;
                    ignoreCurrentUpload = true;
                    do
                    {
                        UploadLanguage language = currentUpload.Language;
                        if (!Settings.Instance.MarkSubbedAsGerman && currentUpload.Subbed) //dont mark german-subbed as german
                        {
                            language &= ~UploadLanguage.German;                            //remove german
                        }

                        if ((language & FilterLanguage) == 0) //Filter: Language
                        {
                            break;
                        }

                        if (!String.IsNullOrWhiteSpace(FilterRuntime) &&     //Filter: Runtime
                            !(new Regex(FilterRuntime).Match(currentUpload.Runtime).Success))
                        {
                            break;
                        }


                        if (!String.IsNullOrWhiteSpace(FilterSize) &&     //Filter: Size
                            !(new Regex(FilterSize).Match(currentUpload.Size).Success))
                        {
                            break;
                        }

                        if (!String.IsNullOrWhiteSpace(FilterUploader) &&     //Filter: Uploader
                            !(new Regex(FilterUploader).Match(currentUpload.Uploader).Success))
                        {
                            break;
                        }

                        if (!String.IsNullOrWhiteSpace(FilterFormat) &&     //Filter: Format
                            !(new Regex(FilterFormat).Match(currentUpload.Format).Success))
                        {
                            break;
                        }

                        ignoreCurrentUpload = false;
                    } while (false);
                }

                if (ignoreCurrentUpload) //Filter: All upload stuff
                {
                    continue;
                }

                //episode stuff ---------------------

                if (!String.IsNullOrWhiteSpace(FilterName) && //Filter: Name
                    !(new Regex(FilterName).Match(download.Title).Success))
                {
                    continue;
                }

                if (!String.IsNullOrWhiteSpace(FilterHoster))
                {
                    var r   = new Regex(FilterHoster);
                    var dls = download.Links.Keys.Where(hoster => r.Match(hoster).Success).ToList(); //all keys that match the regex
                    if (!dls.Any())                                                                  //Filter: Hoster
                    {
                        continue;
                    }
                    for (int i = download.Links.Keys.Count - 1; i >= 0; i--)
                    {
                        string key = download.Links.Keys.ElementAt(i);
                        if (!dls.Contains(key))
                        {
                            download.Links.Remove(key);
                        }
                    }
                }

                //------------------------------------------

                //Season stuff ------------------------------------------------------------------------------------
                if (currentSeasonData == null || currentSeasonData != download.Upload.Season)
                {
                    currentSeasonData = download.Upload.Season;
                    seasonNr          = -1;
                    Match m2 = new Regex("(?:season|staffel)\\s*(\\d+)", RegexOptions.IgnoreCase).Match(currentSeasonData.Title);
                    if (m2.Success)
                    {
                        int.TryParse(m2.Groups[1].Value, out seasonNr);
                    }
                }

                if (seasonNr == -1)
                {
                    if (newNonSeasons.All(d => d.Title != download.Title))
                    {
                        newNonSeasons.Add(download);
                    }
                    continue;
                }

                if (currentFavSeason == null || currentFavSeason.Number != seasonNr)
                {
                    currentFavSeason = newSeasons.FirstOrDefault(favSeasonData => favSeasonData.Number == seasonNr) ??
                                       new FavSeasonData()
                    {
                        Number = seasonNr, Show = this
                    };

                    if (!newSeasons.Contains(currentFavSeason)) //season not yet added?
                    {
                        newSeasons.Add(currentFavSeason);
                    }
                }

                int episodeNr = -1;

                MatchCollection mts     = new Regex("S0{0,4}" + seasonNr + "\\.?E(\\d+)", RegexOptions.IgnoreCase).Matches(download.Title);
                MatchCollection mts_ep  = new Regex("[^A-Z]E(\\d+)", RegexOptions.IgnoreCase).Matches(download.Title);
                MatchCollection mts_alt = new Regex("\\bE(\\d+)\\b", RegexOptions.IgnoreCase).Matches(download.Title);
                if (mts.Count == 1 && mts_ep.Count == 1)
                //if there is exactly one match for "S<xx>E<yy>" and there is no second "E<zz>" (e.g. S01E01-E12)
                {
                    int.TryParse(mts[0].Groups[1].Value, out episodeNr);
                }
                else if (mts_alt.Count == 1) //if there's exactly one match for the alternative regex
                {
                    int.TryParse(mts_alt[0].Groups[1].Value, out episodeNr);
                }


                if (episodeNr == -1)
                {
                    if (currentFavSeason.NonEpisodes.All(d => d.Title != download.Title))
                    {
                        currentFavSeason.NonEpisodes.Add(download);
                    }
                    continue;
                }

                FavEpisodeData currentFavEpisode = currentFavSeason.Episodes.FirstOrDefault(episodeData => episodeData.Number == episodeNr);

                if (currentFavEpisode == null)
                {
                    currentFavEpisode        = new FavEpisodeData();
                    currentFavEpisode.Season = currentFavSeason;
                    currentFavEpisode.Number = episodeNr;
                    bool existed = false;

                    var oldSeason = Seasons.FirstOrDefault(s => s.Number == currentFavSeason.Number);
                    if (oldSeason != null)
                    {
                        var oldEpisode = oldSeason.Episodes.FirstOrDefault(e => e.Number == currentFavEpisode.Number);
                        if (oldEpisode != null) //we can copy old data to current episode
                        {
                            currentFavEpisode.Watched            = oldEpisode.Watched;
                            currentFavEpisode.Downloaded         = oldEpisode.Downloaded;
                            currentFavEpisode.EpisodeInformation = oldEpisode.EpisodeInformation;
                            existed = true;
                        }
                    }

                    if (notifications && !existed)
                    {
                        currentFavEpisode.NewEpisode = true;
                        setNewEpisodes = true;
                    }

                    currentFavSeason.Episodes.Add(currentFavEpisode);

                    currentFavEpisode.Downloads.Add(download);

                    if (ProviderData != null && (currentFavEpisode.EpisodeInformation == null || reset))
                    {
                        StaticInstance.ThreadPool.QueueWorkItem(() =>
                        {
                            //currentFavEpisode.ReviewInfoReview = SjInfo.ParseSjDeSite(InfoUrl, currentFavEpisode.Season.Number, currentFavEpisode.Number);
                            currentFavEpisode.EpisodeInformation = ProviderManager.GetProvider().GetEpisodeInformation(ProviderData, currentFavEpisode.Season.Number, currentFavEpisode.Number);
                        });
                    }
                }
                else
                {
                    FavEpisodeData oldEpisode = null;
                    var            oldSeason  = Seasons.FirstOrDefault(s => s.Number == currentFavSeason.Number);
                    if (oldSeason != null)
                    {
                        oldEpisode = oldSeason.Episodes.FirstOrDefault(e => e.Number == currentFavEpisode.Number);
                    }

                    if (currentFavEpisode.Downloads.All(d => d.Title != download.Title))
                    {
                        if (notifications && (oldEpisode == null || (!oldEpisode.NewEpisode && oldEpisode.Downloads.All(d => d.Title != download.Title))))
                        {
                            currentFavEpisode.NewUpdate = true;
                            setNewUpdates = true;
                        }
                        currentFavEpisode.Downloads.Add(download);
                    }
                }
            }

            if (reset)
            {
                Seasons.Clear();
                foreach (var season in newSeasons)
                {
                    Seasons.Add(season);
                }
                NonSeasons.Clear();
                foreach (var nonSeason in newNonSeasons)
                {
                    NonSeasons.Add(nonSeason);
                }
            }

            if (setNewEpisodes)
            {
                Notified    = false;
                NewEpisodes = true;
            }
            if (setNewUpdates)
            {
                NewUpdates = true;
            }

            RecalcNumbers();
            _mutexFilter.ReleaseMutex();
        }
Esempio n. 12
0
        public override void WireMessages()
        {
            Messenger.Default.Register <NotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.ClearEpisodesMsg))
                {
                    Episodes.Clear();
                }

                if (m.Notification.Equals(Constants.Messages.RefreshResumeMsg))
                {
                    var id    = (string)m.Sender;
                    var ticks = (long)m.Target;
                    if (id == SelectedEpisode.Id)
                    {
                        if (SelectedEpisode.UserData == null)
                        {
                            SelectedEpisode.UserData = new UserItemDataDto();
                        }

                        SelectedEpisode.UserData.PlaybackPositionTicks = ticks;

                        SelectedEpisode.HasPlayed();

                        CanResume = SelectedEpisode.CanResume;
                    }
                }
            });

            Messenger.Default.Register <SyncNotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.SyncJobFinishedMsg))
                {
                    switch (m.ItemType.ToLower())
                    {
                    case "episode":
                        if (SelectedEpisode != null && SelectedEpisode.Id == m.ItemId)
                        {
                            SelectedEpisode.IsSynced = true;
                        }

                        if (!Episodes.IsNullOrEmpty())
                        {
                            var episode = Episodes.FirstOrDefault(x => x.Id == m.ItemId);
                            if (episode != null)
                            {
                                episode.IsSynced = true;
                            }
                        }
                        break;

                    case "season":
                        if (SelectedSeason != null)
                        {
                            SelectedSeason.IsSynced = true;
                        }

                        if (!Seasons.IsNullOrEmpty())
                        {
                            var season = Seasons.FirstOrDefault(x => x.Id == m.ItemId);
                            if (season != null)
                            {
                                season.IsSynced = true;
                            }
                        }
                        break;

                    case "series":
                        if (SelectedTvSeries != null)
                        {
                            SelectedTvSeries.IsSynced = true;
                        }
                        break;
                    }
                }
            });
        }
 public TeamDetailViewModel(Team model)
 {
     this.model        = model;
     this.filterSeason = Seasons.FirstOrDefault();
 }