public EpisodeViewModel(FavEpisodeData favEpisodeData) { _favEpisodeData = favEpisodeData; Photo = (_favEpisodeData.EpisodeInformation == null || String.IsNullOrWhiteSpace(_favEpisodeData.EpisodeInformation.Image)) ? null : new CachedBitmap(_favEpisodeData.EpisodeInformation.Image); NewEpisodeVisible = (_favEpisodeData.NewEpisode) ? Visibility.Visible : Visibility.Collapsed; NewUpdateVisible = (_favEpisodeData.NewUpdate) ? Visibility.Visible : Visibility.Collapsed; DownloadedCheckVisibility = (_favEpisodeData.Downloaded) ? Visibility.Visible : Visibility.Collapsed; WatchedCheckVisibility = (_favEpisodeData.Watched) ? Visibility.Visible : Visibility.Collapsed; _dispatcher = Dispatcher.CurrentDispatcher; favEpisodeData.PropertyChanged += favEpisodeData_PropertyChanged; ShowInfoCommand = new SimpleCommand<object, object>(b => (_favEpisodeData.EpisodeInformation != null && (!String.IsNullOrWhiteSpace(_favEpisodeData.EpisodeInformation.ProviderHomepage)||!String.IsNullOrWhiteSpace( _favEpisodeData.EpisodeInformation.PublisherHomepage))), delegate { var p = new Process(); p.StartInfo.FileName = favEpisodeData.EpisodeInformation.PublisherHomepage != null ? _favEpisodeData.EpisodeInformation.PublisherHomepage : _favEpisodeData.EpisodeInformation.ProviderHomepage; p.Start(); }); StateChangeCommand = new SimpleCommand<object, object>(o => { if (!_favEpisodeData.Downloaded && !_favEpisodeData.Watched) { _favEpisodeData.Downloaded = true; return; } if (_favEpisodeData.Downloaded && !_favEpisodeData.Watched) { _favEpisodeData.Watched = true; return; } _favEpisodeData.Downloaded = false; _favEpisodeData.Watched = false; }); DownloadCommand = new SimpleCommand<object, String>(s => { _favEpisodeData.Downloaded = true; for (int i = 0; i < 10; i++) { try { Clipboard.SetText(s); Clipboard.Flush(); Stats.TrackAction(Stats.TrackActivity.Download); return; } catch { //nah } Thread.Sleep(10); } MessageBox.Show("Couldn't Copy link to clipboard.\n" + s); }); }
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(); }
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(); }