/// <summary> /// We require the command line parameters for the web browser host /// Util should be an implementation of IBrowserSiteUtil /// </summary> /// <param name="util"></param> public void Initialise(SiteUtilBase util) { var browserConfig = (util as IBrowserSiteUtil); if (browserConfig != null) { _automationType = browserConfig.ConnectorEntityTypeName; _username = browserConfig.UserName; _password = browserConfig.Password; } var emulationSite = util as OnlineVideos.Sites.Interfaces.IBrowserVersionEmulation; if (emulationSite != null) { _emulationLevel = emulationSite.EmulatedVersion; } _lastError = string.Empty; _callback.OnBrowserClosing += _callback_OnBrowserHostClosing; _callback.OnBrowserKeyPress += _callback_OnBrowserKeyPress; _callback.OnBrowserWndProc += _callback_OnBrowserWndProc; // Wire up to an existing browser process if one exists var processes = System.Diagnostics.Process.GetProcessesByName("OnlineVideos.WebAutomation.BrowserHost"); if (processes != null && processes.Count() > 0) _browserProcess = processes[0]; }
/// <summary> /// Find and set all configuration fields that do not have their default value /// </summary> /// <param name="siteUtil"></param> public void AddConfigurationValues(Sites.SiteUtilBase siteUtil) { // 1. build a list of all the Fields that are used for OnlineVideosConfiguration List <FieldInfo> fieldInfos = new List <FieldInfo>(); foreach (FieldInfo field in siteUtil.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { object[] attrs = field.GetCustomAttributes(typeof(System.ComponentModel.CategoryAttribute), false); if (attrs.Length > 0 && ((System.ComponentModel.CategoryAttribute)attrs[0]).Category == "OnlineVideosConfiguration") { fieldInfos.Add(field); } } // 2. get a "clean" site by creating it with empty SiteSettings Configuration = new Helpers.StringHash(); Sites.SiteUtilBase cleanSiteUtil = Sites.SiteUtilFactory.CreateFromShortName(UtilName, this); // 3. compare and collect different settings foreach (FieldInfo field in fieldInfos) { object defaultValue = field.GetValue(cleanSiteUtil); object newValue = field.GetValue(siteUtil); if (defaultValue != newValue) { // seems that if default value = false, and newvalue = false defaultvalue != newvalue returns true // so added extra check if (defaultValue == null || !defaultValue.Equals(newValue)) { Configuration.Add(field.Name, newValue.ToString()); } } } }
bool PassesAgeCheck(string fullFileName) { if (!OnlineVideoSettings.Instance.UseAgeConfirmation) { return(true); } if (OnlineVideoSettings.Instance.UseAgeConfirmation && OnlineVideoSettings.Instance.AgeConfirmed) { return(true); } try { // try to find out what site this video belongs to string siteName = Path.GetDirectoryName(fullFileName); siteName = siteName.Substring(siteName.LastIndexOf('\\') + 1); SiteUtilBase util = null; if (OnlineVideoSettings.Instance.SiteUtilsList.TryGetValue(siteName, out util)) { return(!util.Settings.ConfirmAge); } } catch { } return(false); }
public FavoriteCategory(FavoriteDbCategory favCat, SiteUtilBase util, SiteUtilBase favUtil) { Site = util; FavSite = favUtil; FavoriteDbCategory = favCat; Name = favCat.Name; Description = favCat.Description; Thumb = favCat.Thumb; }
public override string GetFileNameForDownload(VideoInfo video, Category category, string url) { const string YouTube = "YouTube"; SiteUtilBase site = this; if (true.Equals(video.Other) && OnlineVideoSettings.Instance.SiteUtilsList.ContainsKey(YouTube)) { site = OnlineVideoSettings.Instance.SiteUtilsList[YouTube]; } return(base.GetFileNameForDownload(video, category, url)); }
public void BuildSiteUtilsList() { SiteUtilsList.Clear(); LatestVideosSiteUtilsList.Clear(); if (FavoritesFirst) { AddFavoritesSite(); AddDownloadsSite(); } foreach (SiteSettings siteSettings in SiteSettingsList) { // only need enabled sites if (siteSettings.IsEnabled) { Sites.SiteUtilBase siteutil = SiteUtilFactory.CreateFromShortName(siteSettings.UtilName, siteSettings); if (siteutil != null && !SiteUtilsList.ContainsKey(siteSettings.Name)) { SiteUtilsList.Add(siteSettings.Name, siteutil); } if (siteutil is LatestVideosSiteUtilBase) { LatestVideosSiteUtilsList.Add(siteutil as LatestVideosSiteUtilBase); } } } if (!FavoritesFirst) { AddFavoritesSite(); AddDownloadsSite(); } SiteUtilsWereBuilt = true; Log.Info("Created {0} SiteUtils", SiteUtilsList.Count); }
public override int DiscoverDynamicCategories() { Settings.Categories.Clear(); RssLink cat = null; // add a category for all files if (!cachedCategories.TryGetValue(Translation.Instance.All, out cat)) { cat = new RssLink() { Name = Translation.Instance.All, Url = OnlineVideoSettings.Instance.DownloadDir }; cachedCategories.Add(cat.Name, cat); } Settings.Categories.Add(cat); if (DownloadManager.Instance.Count > 0) { // add a category for all downloads in progress if (!cachedCategories.TryGetValue(Translation.Instance.Downloading, out cat)) { cat = new RssLink() { Name = Translation.Instance.Downloading, Description = Translation.Instance.DownloadingDescription, EstimatedVideoCount = (uint)DownloadManager.Instance.Count }; cachedCategories.Add(cat.Name, cat); } else { cat.EstimatedVideoCount = (uint)DownloadManager.Instance.Count; // refresh the count } Settings.Categories.Add(cat); } foreach (string aDir in Directory.GetDirectories(OnlineVideoSettings.Instance.DownloadDir)) { // try to find a SiteUtil according to the directory name string siteName = Path.GetFileName(aDir); SiteUtilBase util = null; OnlineVideoSettings.Instance.SiteUtilsList.TryGetValue(siteName, out util); DirectoryInfo dirInfo = new DirectoryInfo(aDir); FileInfo[] files = dirInfo.GetFiles(); if (files.Length == 0) { try { Directory.Delete(aDir); } catch { } // try to delete empty directories } else { // treat folders without a corresponding site as adult site if ((util == null && (!OnlineVideoSettings.Instance.UseAgeConfirmation || OnlineVideoSettings.Instance.AgeConfirmed)) || ((util != null && !util.Settings.ConfirmAge) || !OnlineVideoSettings.Instance.UseAgeConfirmation || OnlineVideoSettings.Instance.AgeConfirmed)) { if (!cachedCategories.TryGetValue(siteName + " - " + Translation.Instance.DownloadedVideos, out cat)) { cat = new RssLink(); cat.Name = siteName + " - " + Translation.Instance.DownloadedVideos; cat.Description = util != null ? util.Settings.Description : ""; ((RssLink)cat).Url = aDir; cat.Thumb = Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, @"Icons\" + siteName + ".png"); cachedCategories.Add(cat.Name, cat); } cat.EstimatedVideoCount = (uint)files.Count(f => IsPossibleVideo(f.Name)); Settings.Categories.Add(cat); } } } // need to always get the categories, because when adding new fav video from a new site, a removing the last one for a site, the categories must be refreshed Settings.DynamicCategoriesDiscovered = false; return(Settings.Categories.Count); }
public static SiteUtilBase CloneFreshSiteFromExisting(SiteUtilBase site) { return(OnlineVideosAppDomain.PluginLoader.CloneFreshSiteFromExisting(site)); }
public override int DiscoverDynamicCategories() { Settings.Categories.Clear(); List <KeyValuePair <string, uint> > lsSiteIds = OnlineVideoSettings.Instance.FavDB.GetSiteIds(); if (lsSiteIds == null || lsSiteIds.Count == 0) { return(0); } uint sumOfAllVideos = (uint)lsSiteIds.Sum(s => s.Value); if (sumOfAllVideos > 0) // only add the "ALL" category if we have single favorite videos in addition to favorites categories { RssLink all = null; if (!cachedCategories.TryGetValue(Translation.Instance.All, out all)) { all = new RssLink(); all.Name = Translation.Instance.All; all.Url = string.Empty; cachedCategories.Add(all.Name, all); } all.EstimatedVideoCount = sumOfAllVideos; Settings.Categories.Add(all); } foreach (var lsSiteId in lsSiteIds) { SiteUtilBase util = null; if (OnlineVideoSettings.Instance.SiteUtilsList.TryGetValue(lsSiteId.Key, out util)) { SiteSettings aSite = util.Settings; if (aSite.IsEnabled && (!aSite.ConfirmAge || !OnlineVideoSettings.Instance.UseAgeConfirmation || OnlineVideoSettings.Instance.AgeConfirmed)) { RssLink cat = null; if (!cachedCategories.TryGetValue(aSite.Name + " - " + Translation.Instance.Favourites, out cat)) { cat = new RssLink(); cat.Name = aSite.Name + " - " + Translation.Instance.Favourites; cat.Description = aSite.Description; cat.Url = aSite.Name; cat.Thumb = System.IO.Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, @"Icons\" + aSite.Name + ".png"); cachedCategories.Add(cat.Name, cat); } cat.EstimatedVideoCount = lsSiteId.Value; Settings.Categories.Add(cat); // create subcategories if any var favCats = OnlineVideoSettings.Instance.FavDB.GetFavoriteCategories(aSite.Name); if (favCats.Count > 0) { cat.HasSubCategories = true; cat.SubCategoriesDiscovered = true; cat.SubCategories = new List <Category>(); if (lsSiteId.Value > 0) // only add the "ALL" category if we have single favorite videos in addition to favorites categories { cat.SubCategories.Add(new RssLink() { Name = Translation.Instance.All, Url = aSite.Name, ParentCategory = cat, EstimatedVideoCount = lsSiteId.Value }); } foreach (var favCat in favCats) { FavoriteCategory fc = new FavoriteCategory(favCat, util, this) { ParentCategory = cat }; if (String.IsNullOrEmpty(fc.Description)) { string[] parts = favCat.RecursiveName.Split('|'); if (parts.Length > 1) { fc.Description = String.Join(" / ", parts, 0, parts.Length - 1); } } cat.SubCategories.Add(fc); } } } } } // need to always get the categories, because when adding new fav video from a new site, a removing the last one for a site, the categories must be refreshed Settings.DynamicCategoriesDiscovered = false; return(Settings.Categories.Count); }
public override List <String> GetMultipleVideoUrls(VideoInfo video, bool inPlaylist = false) { SiteUtilBase util = OnlineVideoSettings.Instance.SiteUtilsList[(video as FavoriteDbVideoInfo).SiteName]; return(util.GetMultipleVideoUrls(video, inPlaylist)); }
public SiteUtilBase CloneFreshSiteFromExisting(SiteUtilBase site) { // create new instance of this site with reset settings SerializableSettings s = new SerializableSettings() { Sites = new BindingList<SiteSettings>() }; s.Sites.Add(site.Settings); System.IO.MemoryStream ms = new System.IO.MemoryStream(); s.Serialize(ms); ms.Position = 0; SiteSettings originalSettings = SerializableSettings.Deserialize(new StreamReader(ms))[0]; return CreateUtilFromShortName(site.Settings.UtilName, originalSettings); }
public WindowSiteSettings(SiteUtilBase site) : this() { this.site = site; GenerateOptions(); }
private void Back_Executed(object sender, ExecutedRoutedEventArgs e) { if (IsFullScreen) { ToggleFullscreen(sender, e); } else { if (CurrentFilter != "") { FilterItems(char.MinValue); return; } ImageDownloader.StopDownload = true; if (SelectedCategory == null) { listViewMain.ItemsSource = ViewModels.SiteList.GetSitesView(this, SelectedSite.Settings.Name); (listViewMain.ItemContainerGenerator.ContainerFromIndex(listViewMain.SelectedIndex) as ListBoxItem).Focus(); SelectedSite = null; } else { if (detailsView.Visibility == System.Windows.Visibility.Visible) { listViewMain.Visibility = System.Windows.Visibility.Visible; detailsView.Visibility = System.Windows.Visibility.Hidden; (listViewMain.ItemContainerGenerator.ContainerFromIndex(listViewMain.SelectedIndex) as ListBoxItem).Focus(); } else { waitCursor.Visibility = System.Windows.Visibility.Visible; if (SelectedCategory.ParentCategory == null) { Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( delegate() { if (!SelectedSite.Settings.DynamicCategoriesDiscovered) SelectedSite.DiscoverDynamicCategories(); return null; }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, Translation.Instance.GettingDynamicCategories)) { SelectedSite.Settings.Categories.RaiseListChangedEvents = false; listViewMain.ItemsSource = ViewModels.CategoryList.GetCategoriesView(this, SelectedSite.Settings.Categories, SelectedCategory.Name); if (listViewMain.SelectedIndex >= 0) { (listViewMain.ItemContainerGenerator.ContainerFromIndex(listViewMain.SelectedIndex) as ListBoxItem).Focus(); } ImageDownloader.GetImages<Category>(SelectedSite.Settings.Categories); } SelectedCategory = null; } ); } else { Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( delegate() { if (!SelectedCategory.ParentCategory.SubCategoriesDiscovered) SelectedSite.DiscoverSubCategories(SelectedCategory.ParentCategory); return null; }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, Translation.Instance.GettingDynamicCategories)) { listViewMain.ItemsSource = ViewModels.CategoryList.GetCategoriesView(this, SelectedCategory.ParentCategory.SubCategories, SelectedCategory.Name); (listViewMain.ItemContainerGenerator.ContainerFromIndex(listViewMain.SelectedIndex) as ListBoxItem).Focus(); ImageDownloader.GetImages<Category>(SelectedCategory.ParentCategory.SubCategories); } SelectedCategory = SelectedCategory.ParentCategory; } ); } } } } }
void ShowContextMenuForSite(ViewModels.Site siteViewModel) { SiteUtilBase selectedSite = siteViewModel.Model; var p = listViewMain.PointToScreen(new Point(20, 10)); var dlg = new WindowSiteSettings(selectedSite) { Width = listViewMain.ActualWidth - 40, Height = listViewMain.ActualHeight - 20, Owner = this, Left = p.X, Top = p.Y }; dlg.lblHeading.Content = string.Format("{0}: {1}", Translation.Instance.Actions, selectedSite.Settings.Name); if (dlg.ShowDialog() == true) { var newUtilInstance = SiteUtilFactory.CloneFreshSiteFromExisting(selectedSite); OnlineVideoSettings.Instance.SiteUtilsList[newUtilInstance.Settings.Name] = newUtilInstance; (OnlineVideoSettings.Instance.UserStore as UserSettings).SaveAll(); // refresh current site viewmodel with new site instance SelectedSite = newUtilInstance; var c = listViewMain.ItemsSource as System.Windows.Data.ListCollectionView; c.EditItem(siteViewModel); siteViewModel.Model = newUtilInstance; c.CommitEdit(); } }
void SiteSelected(SiteUtilBase site) { waitCursor.Visibility = System.Windows.Visibility.Visible; Log.Info("Entering Site: '{0}'", site.Settings.Name); Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( delegate() { if (!site.Settings.DynamicCategoriesDiscovered) site.DiscoverDynamicCategories(); return null; }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, Translation.Instance.GettingDynamicCategories)) { SelectedSite = site; if (SelectedSite.Settings.Categories != null && SelectedSite.Settings.Categories.Count > 0 && SelectedSite.Settings.Categories[SelectedSite.Settings.Categories.Count - 1] is NextPageCategory) { SelectedSite.Settings.Categories[SelectedSite.Settings.Categories.Count - 1].ThumbnailImage = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images\\NextPage.png"); } SelectedSite.Settings.Categories.RaiseListChangedEvents = false; listViewMain.ItemsSource = ViewModels.CategoryList.GetCategoriesView(this, SelectedSite.Settings.Categories); SelectAndFocusItem(); ImageDownloader.GetImages<Category>(SelectedSite.Settings.Categories); } } ); }
public static SiteUtilBase CloneFreshSiteFromExisting(SiteUtilBase site) { return OnlineVideosAppDomain.PluginLoader.CloneFreshSiteFromExisting(site); }