public async Task AddTvShow(VideoItem episode) { episode.IsTvShow = true; try { TvShow show = Shows.FirstOrDefault(x => x.ShowTitle == episode.ShowTitle); if (show == null) { // Generate a thumbnail for the show await Locator.MediaLibrary.FetchVideoThumbnailOrWaitAsync(episode); show = new TvShow(episode.ShowTitle); show.Episodes.Add(episode); Shows.Add(show); } else { if (show.Episodes.FirstOrDefault(x => x.Id == episode.Id) == null) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => show.Episodes.Add(episode)); } } } catch (Exception e) { LogHelper.Log(StringsHelper.ExceptionToString(e)); } }
public async Task OnGet() { Shows = await youTubeService.GetShows(); UpcomingShow = Shows.LastOrDefault(show => show.IsInFuture && !show.IsOnAir); OnAirShow = Shows.FirstOrDefault(show => show.IsOnAir); }
public static TmdbShowImages GetShowImages(int?id, bool forceUpdate = false) { if (id == null) { return(null); } // if its in our cache return it var showImages = Shows.FirstOrDefault(s => s.Id == id); if (showImages != null) { if (forceUpdate) { return(showImages); } // but only if the request is not very old if (DateTime.Now.Subtract(new TimeSpan(TraktSettings.TmdbShowImageMaxCacheAge, 0, 0, 0, 0)) < Convert.ToDateTime(showImages.RequestAge)) { return(showImages); } TraktLogger.Info("Show image cache expired. TMDb ID = '{0}', Request Age = '{1}'", id, showImages.RequestAge); RemoveShowImagesFromCache(showImages); } // get movie images from tmdb and add to the cache showImages = TmdbAPI.TmdbAPI.GetShowImages(id.ToString()); AddShowImagesToCache(showImages); return(showImages); }
public static Boolean RemoveFavoriteShow(Area show) { var toDelete = Shows.FirstOrDefault(s => s.ID == show.ID); if (toDelete == null) { return(false); } Shows.Remove(toDelete); Helpers.Settings.FavoriteShows = JsonConvert.SerializeObject(Shows); FavoritesDirty = true; return(true); }
public void RemoveShow(Show show) { var foundShow = Shows?.FirstOrDefault(x => x.Id == show?.Id); if (foundShow is null) { return; } if (!HasAlreadyShow(foundShow)) { ; } Shows.Remove(foundShow); }
/// <summary> /// Load movies asynchronously /// </summary> public override async Task LoadShowsAsync(bool reset = false) { await LoadingSemaphore.WaitAsync(); StopLoadingShows(); if (reset) { Shows.Clear(); Page = 0; } var watch = Stopwatch.StartNew(); Page++; if (Page > 1 && Shows.Count == MaxNumberOfShows) { Page--; LoadingSemaphore.Release(); return; } Logger.Info( $"Loading shows favorite page {Page}..."); HasLoadingFailed = false; try { IsLoadingShows = true; var imdbIds = await UserService.GetFavoritesShows(Page); if (!NeedSync) { var shows = new List <ShowLightJson>(); await imdbIds.shows.ParallelForEachAsync(async imdbId => { try { var show = await ShowService.GetShowLightAsync(imdbId); if (show != null) { show.IsFavorite = true; shows.Add(show); } } catch (Exception ex) { Logger.Error(ex); } }); var updatedShows = shows.OrderBy(a => a.Title) .Where(a => (Genre == null || a.Genres.Contains(Genre.EnglishName)) && a.Rating.Percentage >= Rating * 10); foreach (var show in updatedShows.Except(Shows.ToList(), new ShowLightComparer())) { var pair = Shows .Select((value, index) => new { value, index }) .FirstOrDefault(x => string.CompareOrdinal(x.value.Title, show.Title) > 0); if (pair == null) { Shows.Add(show); } else { Shows.Insert(pair.index, show); } } } else { var showsToDelete = Shows.Select(a => a.ImdbId).Except(imdbIds.allShows); var showsToAdd = imdbIds.allShows.Except(Shows.Select(a => a.ImdbId)); foreach (var movie in showsToDelete.ToList()) { Shows.Remove(Shows.FirstOrDefault(a => a.ImdbId == movie)); } var shows = showsToAdd.ToList(); var showsToAddAndToOrder = new List <ShowLightJson>(); await shows.ParallelForEachAsync(async imdbId => { try { var show = await ShowService.GetShowLightAsync(imdbId); if ((Genre == null || show.Genres.Contains(Genre.EnglishName)) && show.Rating.Percentage >= Rating * 10) { showsToAddAndToOrder.Add(show); } } catch (Exception ex) { Logger.Error(ex); } }); foreach (var show in showsToAddAndToOrder.Except(Shows.ToList(), new ShowLightComparer())) { var pair = Shows .Select((value, index) => new { value, index }) .FirstOrDefault(x => string.CompareOrdinal(x.value.Title, show.Title) > 0); if (pair == null) { Shows.Add(show); } else { Shows.Insert(pair.index, show); } } } IsLoadingShows = false; IsShowFound = Shows.Any(); CurrentNumberOfShows = Shows.Count; MaxNumberOfShows = imdbIds.nbShows; await UserService.SyncShowHistoryAsync(Shows).ConfigureAwait(false); } catch (Exception exception) { Page--; Logger.Error( $"Error while loading shows favorite page {Page}: {exception.Message}"); HasLoadingFailed = true; Messenger.Default.Send(new ManageExceptionMessage(exception)); } finally { NeedSync = false; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Info( $"Loaded shows favorite page {Page} in {elapsedMs} milliseconds."); LoadingSemaphore.Release(); } }
/// <summary> /// Load movies asynchronously /// </summary> public override async Task LoadShowsAsync(bool reset = false) { await LoadingSemaphore.WaitAsync(); StopLoadingShows(); if (reset) { Shows.Clear(); Page = 0; } var watch = Stopwatch.StartNew(); Page++; if (Page > 1 && Shows.Count == MaxNumberOfShows) { Page--; LoadingSemaphore.Release(); return; } Logger.Info( $"Loading shows favorite page {Page}..."); HasLoadingFailed = false; try { IsLoadingShows = true; var imdbIds = await UserService.GetFavoritesShows(Page); if (!_needSync) { var shows = new List <ShowJson>(); await imdbIds.shows.ParallelForEachAsync(async imdbId => { var show = await ShowService.GetShowAsync(imdbId); if (show != null) { show.IsFavorite = true; shows.Add(show); } }); var updatedShows = shows.OrderBy(a => a.Title) .Where(a => (Genre != null ? a.Genres.Any( genre => genre.ToLowerInvariant() == Genre.EnglishName.ToLowerInvariant()) : a.Genres.TrueForAll(b => true)) && a.Rating.Percentage >= Rating * 10); Shows.AddRange(updatedShows.Except(Shows.ToList(), new ShowComparer())); } else { var showsToDelete = Shows.Select(a => a.ImdbId).Except(imdbIds.allShows); var showsToAdd = imdbIds.allShows.Except(Shows.Select(a => a.ImdbId)); foreach (var movie in showsToDelete.ToList()) { Shows.Remove(Shows.FirstOrDefault(a => a.ImdbId == movie)); } var shows = showsToAdd.ToList(); await shows.ParallelForEachAsync(async imdbId => { var show = await ShowService.GetShowAsync(imdbId); if ((Genre != null ? show.Genres.Any( genre => genre.ToLowerInvariant() == Genre.EnglishName.ToLowerInvariant()) : show.Genres.TrueForAll(b => true)) && show.Rating.Percentage >= Rating * 10) { DispatcherHelper.CheckBeginInvokeOnUI(() => { Shows.Add(show); }); } }); } IsLoadingShows = false; IsShowFound = Shows.Any(); CurrentNumberOfShows = Shows.Count; MaxNumberOfShows = imdbIds.nbShows; await UserService.SyncShowHistoryAsync(Shows); } catch (Exception exception) { Page--; Logger.Error( $"Error while loading shows favorite page {Page}: {exception.Message}"); HasLoadingFailed = true; Messenger.Default.Send(new ManageExceptionMessage(exception)); } finally { Shows.Sort((a, b) => String.Compare(a.Title, b.Title, StringComparison.Ordinal)); _needSync = false; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Info( $"Loaded shows favorite page {Page} in {elapsedMs} milliseconds."); LoadingSemaphore.Release(); } }
public Show GetShowByTitle(int siteTypeId, string title) { title = title.ToLower(); return(Shows.FirstOrDefault(s => s.SiteTypeId == siteTypeId && (s.Title.ToLower() == title || s.OriginalTitle.ToLower() == title || s.Title.ToLower() + " (" + s.OriginalTitle + ")" == title))); }