/// <summary> /// Returns all Categories for a given Site /// </summary> /// <param name="siteName"></param> /// <returns></returns> internal List <Category> GetSiteCategories(string siteName) { SiteUtilBase site; if (!OnlineVideoSettings.Instance.SiteUtilsList.TryGetValue(siteName, out site)) { return(new List <Category>()); } if (!site.Settings.DynamicCategoriesDiscovered) { try { site.DiscoverDynamicCategories(); } catch (Exception ex) { Logger.Error("OnlineVideosManager: Error in DiscoverDynamicCategories", ex); } } List <Category> categories = site.Settings.Categories.ToList(); // be clever and already download the Thumbs in the background ImageDownloader.GetImages(categories); return(categories); }
void ShowDetails(List <DetailVideoInfo> choices) { DetailsVideosList = new List <VideoViewModel>(); choices.ForEach(r => { r.CleanDescriptionAndTitle(); DetailsVideosList.Add(new VideoViewModel(r, SelectedCategory != null ? SelectedCategory.Category : null, SelectedSite.Site.Settings, true)); }); ImageDownloader.GetImages <DetailVideoInfo>(choices); IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); workflowManager.NavigatePushAsync(Guids.WorkflowStateDetails, new NavigationContextConfig() { NavigationContextDisplayLabel = SelectedVideo.Title }); }
void ExecuteCustomContextMenuEntry(Sites.ContextMenuEntry entry) { var ovMainModel = ServiceRegistration.Get <IWorkflowManager>().GetModel(Guids.WorkFlowModelOV) as OnlineVideosWorkflowModel; var site = OnlineVideoSettings.Instance.SiteUtilsList[SiteName]; BackgroundTask.Instance.Start <OnlineVideos.Sites.ContextMenuExecutionResult>( () => { return(site.ExecuteContextMenuEntry(Category, VideoInfo, entry)); }, (success, result) => { if (success) { if (!string.IsNullOrEmpty(result.ExecutionResultMessage)) { //todo: show message - but also execute the two following if statements } if (result.RefreshCurrentItems) { // discover and show videos of this category BackgroundTask.Instance.Start <List <VideoInfo> >( () => { return(site.GetVideos(Category)); }, (success2, videos) => { if (success2) { ovMainModel.VideosList.Clear(); videos.ForEach(r => { r.CleanDescriptionAndTitle(); ovMainModel.VideosList.Add(new VideoViewModel(r, Category, SiteName, SiteUtilName, false)); }); if (site.HasNextPage) { ovMainModel.VideosList.Add(new VideoViewModel(Translation.Instance.NextPage, "NextPage.png")); } ovMainModel.VideosList.FireChange(); ImageDownloader.GetImages <VideoInfo>(videos); } }, Translation.Instance.GettingCategoryVideos); } if (result.ResultItems != null && result.ResultItems.Count > 0) { ovMainModel.ShowSearchResults(result.ResultItems, entry.DisplayText); } } }, entry.DisplayText); }
void ShowCategories(IList <Category> categories, string navigationLabel) { CategoriesList = new ItemsList(); foreach (Category c in categories) { CategoriesList.Add(new CategoryViewModel(c)); } ImageDownloader.GetImages <Category>(categories); IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); workflowManager.NavigatePushTransientAsync( WorkflowState.CreateTransientState(Guids.WorkflowStateCategoriesName, navigationLabel, false, "categories", false, WorkflowType.Workflow), new NavigationContextConfig()); }
void ShowCategories(IList <Category> categories, string navigationLabel) { CategoriesList = new ItemsList(); foreach (Category c in categories) { CategoriesList.Add(new CategoryViewModel(c)); } ImageDownloader.GetImages <Category>(categories); IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); workflowManager.NavigatePushAsync(Guids.WorkflowStateCategories, new NavigationContextConfig() { NavigationContextDisplayLabel = navigationLabel }); }
void ShowVideos(CategoryViewModel category, List <VideoInfo> videos) { SelectedCategory = category; VideosList = new ItemsList(); videos.ForEach(r => { r.CleanDescriptionAndTitle(); VideosList.Add(new VideoViewModel(r, SelectedCategory != null ? SelectedCategory.Category : null, SelectedSite.Site.Settings, false)); }); if (SelectedSite.Site.HasNextPage) { VideosList.Add(new VideoViewModel(Translation.Instance.NextPage, "NextPage.png")); } ImageDownloader.GetImages <VideoInfo>(videos); IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>(); workflowManager.NavigatePushAsync(Guids.WorkflowStateVideos, new NavigationContextConfig() { NavigationContextDisplayLabel = SelectedCategory.Name }); }
void VisibilityChanged(object sender, EventArgs e) { ImageDownloader.StopDownload = true; if (Visibility == System.Windows.Visibility.Hidden) { if (changedXml) { (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.ItemsSource = null; if (newDlls) { OnlineVideoSettings.Reload(); TranslationLoader.SetTranslationsToSingleton(); GC.Collect(); GC.WaitForFullGCComplete(); newDlls = false; } OnlineVideoSettings.Instance.BuildSiteUtilsList(); (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.ItemsSource = ViewModels.SiteList.GetSitesView(App.Current.MainWindow as OnlineVideosMainWindow); changedXml = false; } (App.Current.MainWindow as OnlineVideosMainWindow).SelectAndFocusItem(rememberedIndex); } else if (Visibility == System.Windows.Visibility.Visible) { // deselect any site on the main view but remember the index rememberedIndex = (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.SelectedIndex; (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.SelectedIndex = -1; var sitesView = ViewModels.GlobalSiteList.GetSitesView(App.Current.MainWindow as OnlineVideosMainWindow); lvSites.ItemsSource = sitesView; ImageDownloader.GetImages <ViewModels.GlobalSite>(sitesView.SourceCollection as IList <ViewModels.GlobalSite>); GridViewSort.ApplySort(lvSites.Items, "LastUpdated", lvSites, FindColumnHeader(lvSites, "LastUpdated"), ListSortDirection.Descending); // focus the first item when this list becomes visible /use dispatcher to let WPF create the items first) Dispatcher.BeginInvoke((Action)(() => { var itemToFocus = lvSites.ItemContainerGenerator.ContainerFromIndex(0) as ListViewItem; if (itemToFocus != null) { itemToFocus.Focus(); } }), DispatcherPriority.Loaded); } }
/// <summary> /// Gets all Videos for a given Category /// </summary> /// <param name="siteName"></param> /// <param name="categoryRecursiveName"></param> /// <returns></returns> internal List <VideoInfo> GetCategoryVideos(string siteName, string categoryRecursiveName) { List <VideoInfo> output = new List <VideoInfo>(); SiteUtilBase site; if (!OnlineVideoSettings.Instance.SiteUtilsList.TryGetValue(siteName, out site)) { return(output); } string[] categories = categoryRecursiveName.Split(new string[] { " / " }, StringSplitOptions.None); Category baseCategory = GetSiteCategories(siteName).Single(x => x.Name == categories.First()); Category lastCategory = null; // if the base category doesn't have any subcategories directly return the videos if (categories.Length == 1) { List <VideoInfo> videos = site.GetVideos(baseCategory).ToList(); // be clever and already download the Thumbs in the background ImageDownloader.GetImages(videos); return(videos); } for (int i = 1; i < categories.Length; i++) { lastCategory = lastCategory == null?GetSubCategories(siteName, baseCategory.RecursiveName()).Single(x => x.Name == categories[i]) : GetSubCategories(siteName, lastCategory.RecursiveName()).Single(x => x.Name == categories[i]); } List <VideoInfo> videos2 = site.GetVideos(lastCategory).ToList(); // be clever and already download the Thumbs in the background ImageDownloader.GetImages(videos2); return(videos2); }
public void ChangeModelContext(NavigationContext oldContext, NavigationContext newContext, bool push) { // reload a site when going away from configuring it and settings were changed if (oldContext.WorkflowState.StateId == Guids.WorkflowStateSiteSettings && FocusedSite.UserSettingsChanged) { FocusedSite.RecreateSite(); // save Site Settings (OnlineVideoSettings.Instance.UserStore as Configuration.UserSiteSettingsStore).SaveAll(); } // going to sites view if (newContext.WorkflowState.StateId == Guids.WorkflowStateSites) { SelectedCategory = null; CategoriesList = null; } // going from categories to categories view else if (newContext.WorkflowState.StateId == Guids.WorkflowStateCategories && oldContext.WorkflowState.StateId == Guids.WorkflowStateCategories) { // going up in hierarchy if (oldContext.Predecessor == newContext) { CategoriesList = new ItemsList(); if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null) { SelectedCategory.Category.ParentCategory.SubCategories.ForEach(c => CategoriesList.Add(new CategoryViewModel(c))); ImageDownloader.GetImages <Category>(SelectedCategory.Category.ParentCategory.SubCategories); SelectedCategory = new CategoryViewModel(SelectedCategory.Category.ParentCategory); } else { foreach (Category c in SelectedSite.Site.Settings.Categories) { CategoriesList.Add(new CategoryViewModel(c)); } ImageDownloader.GetImages <Category>(SelectedSite.Site.Settings.Categories); SelectedCategory = null; } } } // going from videos to categories view else if (newContext.WorkflowState.StateId == Guids.WorkflowStateCategories && oldContext.WorkflowState.StateId == Guids.WorkflowStateVideos) { VideosList = null; CategoriesList = new ItemsList(); if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null) { SelectedCategory.Category.ParentCategory.SubCategories.ForEach(c => CategoriesList.Add(new CategoryViewModel(c))); ImageDownloader.GetImages <Category>(SelectedCategory.Category.ParentCategory.SubCategories); } else { foreach (Category c in SelectedSite.Site.Settings.Categories) { CategoriesList.Add(new CategoryViewModel(c)); } ImageDownloader.GetImages <Category>(SelectedSite.Site.Settings.Categories); } if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null) { SelectedCategory = new CategoryViewModel(SelectedCategory.Category.ParentCategory); } else { SelectedCategory = null; } } // going from details to videos view else if (newContext.WorkflowState.StateId == Guids.WorkflowStateVideos && oldContext.WorkflowState.StateId == Guids.WorkflowStateDetails) { DetailsVideosList = null; } }
public void SelectVideo(VideoViewModel videoModel) { if (BackgroundTask.Instance.IsExecuting) { return; } if (videoModel.VideoInfo == null) { // discover and append next page videos BackgroundTask.Instance.Start <List <VideoInfo> >( () => { return(SelectedSite.Site.GetNextPageVideos()); }, (success, nextPageVideos) => { if (success) { VideosList.Remove(videoModel); int selectNr = VideosList.Count; nextPageVideos.ForEach(r => { r.CleanDescriptionAndTitle(); VideosList.Add(new VideoViewModel(r, SelectedCategory != null ? SelectedCategory.Category : null, SelectedSite.Site.Settings, false) { Selected = VideosList.Count == selectNr }); }); if (SelectedSite.Site.HasNextPage) { VideosList.Add(new VideoViewModel(Translation.Instance.NextPage, "NextPage.png")); } VideosList.FireChange(); ImageDownloader.GetImages <VideoInfo>(nextPageVideos); } }, Translation.Instance.GettingNextPageVideos); } else { if (SelectedSite.Site is Sites.IChoice && videoModel.VideoInfo.HasDetails) { // get details videos and show details view BackgroundTask.Instance.Start <List <DetailVideoInfo> >( () => { return(((Sites.IChoice)SelectedSite.Site).GetVideoChoices(videoModel.VideoInfo)); }, (success, choices) => { if (success) { SelectedVideo = videoModel; ShowDetails(choices); } }, Translation.Instance.GettingVideoDetails); } else { // get playback urls and play or show dialog to select playback options BackgroundTask.Instance.Start <List <string> >( () => { return(SelectedSite.Site.GetMultipleVideoUrls(videoModel.VideoInfo)); }, (success, urls) => { if (success) { if (SelectedSite.Site.Settings.Player != PlayerType.Browser) { Helpers.UriUtils.RemoveInvalidUrls(urls); } // if no valid urls were returned show error msg if (urls == null || urls.Count == 0) { ServiceRegistration.Get <IDialogManager>().ShowDialog("[OnlineVideos.Error]", "[OnlineVideos.UnableToPlayVideo]", DialogType.OkDialog, false, DialogButtonType.Ok); } else { SelectedVideo = videoModel; SelectedVideo.ChoosePlaybackOptions(urls[0], (url) => { urls[0] = url; SelectedVideo.Play(urls); }); } } }, Translation.Instance.GettingPlaybackUrlsForVideo); } } }
public void SelectCategory(CategoryViewModel categoryModel) { if (BackgroundTask.Instance.IsExecuting) { return; } if (categoryModel.Category is NextPageCategory) { // discover and append next page categories BackgroundTask.Instance.Start <bool>( () => { SelectedSite.Site.DiscoverNextPageCategories(categoryModel.Category as NextPageCategory); return(true); }, (success, result) => { if (success) { int selectNr = CategoriesList.Count - 1; CategoriesList.Clear(); IList <Category> catList = categoryModel.Category.ParentCategory == null ? (IList <Category>)SelectedSite.Site.Settings.Categories : categoryModel.Category.ParentCategory.SubCategories; foreach (Category c in catList) { CategoriesList.Add(new CategoryViewModel(c) { Selected = CategoriesList.Count == selectNr }); } ImageDownloader.GetImages <Category>(catList); CategoriesList.FireChange(); } }, Translation.Instance.GettingNextPageVideos); } else { if (categoryModel.Category.HasSubCategories) { if (!categoryModel.Category.SubCategoriesDiscovered) { // discover and show subcategories BackgroundTask.Instance.Start <bool>( () => { SelectedSite.Site.DiscoverSubCategories(categoryModel.Category); return(true); }, (success, result) => { if (success) { SelectedCategory = categoryModel; ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name); } }, Translation.Instance.GettingDynamicCategories); } else { SelectedCategory = categoryModel; ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name); } } else { // discover and show videos of this category BackgroundTask.Instance.Start <List <VideoInfo> >( () => { return(SelectedSite.Site.GetVideos(categoryModel.Category)); }, (success, videos) => { if (success) { ShowVideos(categoryModel, videos); } }, Translation.Instance.GettingCategoryVideos); } } }
internal List <Category> GetSubCategories(string siteName, string categoryRecursiveName) { List <Category> output = new List <Category>(); SiteUtilBase site; if (!OnlineVideoSettings.Instance.SiteUtilsList.TryGetValue(siteName, out site)) { return(output); } try { if (!site.Settings.DynamicCategoriesDiscovered) { site.DiscoverDynamicCategories(); } string[] categories = categoryRecursiveName.Split(new string[] { " / " }, StringSplitOptions.None); Category baseCategory = GetSiteCategories(siteName).Single(x => x.Name == categories.First()); Category lastCategory = null; // if the base category doesn't have any subcategories the last category is equal to the base category if (categories.Length > 1) { for (int i = 1; i < categories.Length; i++) { lastCategory = lastCategory == null?GetSubCategories(siteName, baseCategory.RecursiveName()).Single(x => x.Name == categories[i]) : GetSubCategories(siteName, lastCategory.RecursiveName()).Single(x => x.Name == categories[i]); } } else { lastCategory = baseCategory; } if (!lastCategory.HasSubCategories) { return(output); } if (!lastCategory.SubCategoriesDiscovered) { try { site.DiscoverSubCategories(lastCategory); } catch (Exception ex) { Logger.Error("OnlineVideosManager: Error in DiscoverSubCategories", ex); } } output = lastCategory.SubCategories; } catch (Exception ex) { Logger.Warn("Error loading Subcategory for site '{0}', Error: {1} StackTrace: {2}", site.Settings.Name, ex.Message, ex.StackTrace); } // be clever and already download the Thumbs in the background ImageDownloader.GetImages(output); return(output); }