public static Folder GetPlaylistFolder() { if (_playlistFolder == null) { string playListPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); if (!Directory.Exists(playListPath)) { Logger.ReportError("MusicPlugin Error, failed to find special music folder, " + playListPath); return null; } playListPath = Path.Combine(playListPath, "PlayLists"); if (!Directory.Exists(playListPath)) { try { Directory.CreateDirectory(playListPath); } catch (Exception e) { Logger.ReportException("MusicPlugin Error, failed to create playlists folder, " + playListPath,e); return null; } } _playlistFolder = new Folder(); _playlistFolder.Name = Settings.Instance.PlayListFolderName; _playlistFolder.Path = playListPath; _playlistFolder.Id = playListPath.GetMD5(); } return _playlistFolder; }
internal override void Assign(BaseItem baseItem ) { base.Assign(baseItem); folder = (Folder)baseItem; folderChildren.Assign(this, FireChildrenChangedEvents); folder.QuickListChanged += QuickListChanged; folder.UnwatchedCountChanged += AdjustUnwatched; }
public DisplayPreferences(Guid id, Folder folder) { this.Id = id; ArrayList list = new ArrayList(); foreach (ViewType v in Enum.GetValues(typeof(ViewType))) list.Add(ViewTypeNames.GetName(v)); viewType.Options = list; this.viewType.Chosen = ViewTypeNames.GetName(Config.Instance.DefaultViewType); //set our dynamic choice options this.sortDict = folder.SortOrderOptions; this.sortOrders.Options = sortDict.Keys.ToArray(); this.indexDict = folder.IndexByOptions; this.indexBy.Options = folder.IndexByOptions.Keys.ToArray(); showLabels = new BooleanChoice(); showLabels.Value = Config.Instance.DefaultShowLabels; verticalScroll = new BooleanChoice(); verticalScroll.Value = Config.Instance.DefaultVerticalScroll; useBanner = new BooleanChoice(); useBanner.Value = false; useCoverflow = new BooleanChoice(); useCoverflow.Value = false; useBackdrop = new BooleanChoice(); useBackdrop.Value = Config.Instance.ShowBackdrop; customParms = new Dictionary<string, string>(); ListenForChanges(); }
public PlayableItem Create(Folder folder) { PlayableItem playable = null; var playableChildren = folder.RecursiveChildren.Select(i => i as Media).Where(v => v != null && v.IsPlaylistCapable() && v.ParentalAllowed).OrderBy(v => v.Path); playable = new PlayableMediaCollection<Media>(folder.Name, playableChildren, folder.HasVideoChildren); playable.PlayableItems = playableChildren.Select(i => i.Path); foreach (var controller in Kernel.Instance.PlaybackControllers) { if (controller.CanPlay(playable.PlayableItems)) { playable.PlaybackController = controller; return playable; } } return playable; }
public DisplayPreferences(Guid id, Folder folder) { this.Id = id; ArrayList list = new ArrayList(); foreach (ViewType v in Enum.GetValues(typeof(ViewType))) list.Add(ViewTypeNames.GetName(v)); viewType.Options = list; this.viewType.Chosen = ViewTypeNames.GetName(Config.Instance.DefaultViewType); //set our dynamic choice options this.sortDict = folder.SortOrderOptions; this.sortOrders.Options = sortDict.Keys.ToArray(); this.indexDict = folder.IndexByOptions; this.indexBy.Options = folder.IndexByOptions.Keys.ToArray(); showLabels = new BooleanChoice(); showLabels.Value = Config.Instance.DefaultShowLabels; verticalScroll = new BooleanChoice(); verticalScroll.Value = Config.Instance.DefaultVerticalScroll; useBanner = new BooleanChoice(); useBanner.Value = false; useCoverflow = new BooleanChoice(); useCoverflow.Value = false; useBackdrop = new BooleanChoice(); useBackdrop.Value = Config.Instance.ShowBackdrop; sortOrders.ChosenChanged += new EventHandler(sortOrders_ChosenChanged); indexBy.ChosenChanged += new EventHandler(indexBy_ChosenChanged); viewType.ChosenChanged += new EventHandler(viewType_ChosenChanged); showLabels.ChosenChanged += new EventHandler(showLabels_ChosenChanged); verticalScroll.ChosenChanged += new EventHandler(verticalScroll_ChosenChanged); useBanner.ChosenChanged += new EventHandler(useBanner_ChosenChanged); useCoverflow.ChosenChanged += new EventHandler(useCoverflow_ChosenChanged); useBackdrop.ChosenChanged += new EventHandler(useBackdrop_ChosenChanged); thumbConstraint.PropertyChanged += new PropertyChangedEventHandler(thumbConstraint_PropertyChanged); }
public void TestChildCaching() { var rootLocation = MockFolderMediaLocation.CreateMockLocation( @" |Root movie3.avi movie4.avi movie5.avi "); var rootFolder = Kernel.Instance.GetItem <MediaBrowser.Library.Entities.Folder>(rootLocation); rootFolder.Id = Guid.NewGuid(); Assert.AreEqual(3, rootFolder.Children.Count()); var cached = new MediaBrowser.Library.Entities.Folder(); cached.Id = rootFolder.Id; Assert.AreEqual(3, cached.Children.Count()); }
public MBDirectoryWatcher(Folder aFolder, bool watchChanges) { lastRefresh = System.DateTime.Now.AddMilliseconds(-60000); //initialize this this.folder = aFolder; IFolderMediaLocation location = folder.FolderMediaLocation; if (location is VirtualFolderMediaLocation) { //virtual folder this.watchedFolders = ((VirtualFolderMediaLocation)location).VirtualFolder.Folders.ToArray(); } else { if (location != null) { //regular folder if (Directory.Exists(location.Path)) { this.watchedFolders = new string[] { location.Path }; } else { this.watchedFolders = new string[0]; Logger.ReportInfo("Cannot watch non-folder location " + aFolder.Name); } } else { Logger.ReportInfo("Cannot watch non-folder location " + aFolder.Name); return; } } this.fileSystemWatchers = new List<FileSystemWatcher>(); InitFileSystemWatcher(this.watchedFolders, watchChanges); Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ => { InitTimers(); }); //timers only on app thread }
bool RunActionRecursively(Folder folder, Action<BaseItem> action) { try { action(folder); foreach (var item in folder.AllRecursiveChildren.OrderByDescending(i => i.DateModified)) { if (_refreshCanceled) return false; action(item); } return true; } catch (Exception e) { Logger.ReportException("Error during refresh", e); _config.RefreshFailed = true; _config.Save(); return false; } }
internal override void Assign(BaseItem baseItem ) { base.Assign(baseItem); folder = (MediaBrowser.Library.Entities.Folder)baseItem; folderChildren.Assign(this, FireChildrenChangedEvents); }
void RunActionRecursively(Folder folder, Action<BaseItem> action) { action(folder); foreach (var item in folder.RecursiveChildren.OrderByDescending(i => i.DateModified)) { action(item); } }
protected void UpdateQuicklist(Folder item) { item.ResetQuickList(); item.OnQuickListChanged(null); }
private void RefreshPodcasts(Folder podcasts) { podcastList.Items.Clear(); foreach (var item in podcasts.Children) { podcastList.Items.Add(item); } }
public DisplayPreferences(string id, Folder folder) { this.Id = new Guid(id); Folder = folder; ArrayList list = new ArrayList(); foreach (ViewType v in Enum.GetValues(typeof(ViewType))) list.Add(ViewTypeNames.GetName(v)); viewType.Options = list; try { this.viewType.Chosen = folder.DisplayPreferences != null ? folder.DisplayPreferences.ViewType ?? Config.Instance.DefaultViewType.ToString() : Config.Instance.DefaultViewType.ToString(); } catch (ArgumentException) { Logging.Logger.ReportError("Invalid view type stored for {0}. Setting to Poster.", folder.Name ?? folder.GetType().Name); viewType.Chosen = Localization.LocalizedStrings.Instance.GetString("PosterDispPref"); } //set our dynamic choice options this.sortDict = folder.SortOrderOptions; this.sortOrders.Options = sortDict.Keys.ToArray(); this.indexDict = folder.IndexByOptions; this.indexBy.Options = folder.IndexByOptions.Keys.ToArray(); verticalScroll = new BooleanChoice {Value = folder.DisplayPreferences != null && folder.DisplayPreferences.ScrollDirection == ScrollDirection.Vertical}; useBanner = new BooleanChoice(); showLabels = new BooleanChoice(); useCoverflow = new BooleanChoice {Value = false}; useBackdrop = new BooleanChoice {Value = folder.DisplayPreferences != null ? folder.DisplayPreferences.ShowBackdrop : Config.Instance.ShowBackdrop}; if (folder.DisplayPreferences != null) { var width = folder.DisplayPreferences.PrimaryImageWidth > 0 ? folder.DisplayPreferences.PrimaryImageWidth : Config.Instance.DefaultPosterSize.Width; var height = folder.DisplayPreferences.PrimaryImageHeight > 0 ? folder.DisplayPreferences.PrimaryImageHeight : Config.Instance.DefaultPosterSize.Height; customParms = folder.DisplayPreferences.CustomPrefs ?? new Dictionary<string, string>(); thumbConstraint = new SizeRef(new Size(width, height)); useBanner.Value = (customParms.GetValueOrDefault("MBCUseBanner", "false") == "true"); showLabels.Value = (customParms.GetValueOrDefault("MBCShowLabels", "false") == "true"); try { if (Config.Instance.RememberIndexing) indexBy.Chosen = folder.DisplayPreferences.IndexBy; } catch { indexBy.Chosen = Localization.LocalizedStrings.Instance.GetString("NoneDispPref"); } } try { sortOrders.Chosen = folder.DisplayPreferences != null ? folder.DisplayPreferences.SortBy ?? "Name" : "Name"; } catch (ArgumentException) { Logging.Logger.ReportError("Invalid sort by stored for {0}. Setting to Name.", folder.Name ?? folder.GetType().Name); sortOrders.Chosen = Localization.LocalizedStrings.Instance.GetString("NameDispPref"); } ListenForChanges(); }
static void FullRefresh(Folder folder, MetadataRefreshOptions options) { int totalItems = 0; int fastMetadataChanged = 0; int slowMetadataChanged = 0; folder.RefreshMetadata(options); Console.Out.WriteLine(); Console.Out.WriteLine("===[Validate]============================================"); Console.Out.WriteLine(); var validationTime = TimeAction(() => { RunActionRecursively("validate", folder, item => { Folder f = item as Folder; if (f != null) f.ValidateChildren(); }); }); Console.Out.WriteLine(); Console.Out.WriteLine("===[Fast Metadata]======================================="); Console.Out.WriteLine(); var fastMetadataTime = TimeAction(() => { RunActionRecursively("fast metadata", folder, item => { fastMetadataChanged += item.RefreshMetadata(MetadataRefreshOptions.FastOnly) ? 1 : 0; totalItems++; }); }); if (rebuildImageCache) { Console.Out.WriteLine(); Console.Out.WriteLine("===[Recreate ImageCache]================================="); Console.Out.WriteLine(); Console.Out.WriteLine("/i specified - Clearing Image Cache for re-build.."); Console.Out.WriteLine(); try { Console.Out.WriteLine("Deleting ImageCache folder."); Directory.Delete(ApplicationPaths.AppImagePath, true); } catch (Exception ex) { Console.Out.WriteLine("Error trying to delete ImageCache folder. " + ex.Message); } Console.Out.WriteLine("Sleeping 2 seconds."); System.Threading.Thread.Sleep(2000); // give it time to fully delete Console.Out.WriteLine("Continuing."); try { Console.Out.WriteLine("Creating ImageCache folder."); Directory.CreateDirectory(ApplicationPaths.AppImagePath); } catch (Exception ex) { Console.Out.WriteLine("Error trying to create ImageCache folder. " + ex.Message); } Console.Out.WriteLine("Sleeping 2 seconds."); System.Threading.Thread.Sleep(2000); // give it time to fully create Console.Out.WriteLine("Continuing."); } Console.Out.WriteLine(); Console.Out.WriteLine("===[Slow Metadata]======================================="); Console.Out.WriteLine(); var slowMetadataTime = TimeAction(() => { RunActionRecursively("slow metadata", folder, item => { slowMetadataChanged += item.RefreshMetadata(MetadataRefreshOptions.Default) ? 1 : 0; if (rebuildImageCache) { //touch all the images - causing them to be re-cached Console.Out.WriteLine("Caching images for " + item.Name); string ignore = null; if (item.PrimaryImage != null) ignore = item.PrimaryImage.GetLocalImagePath(); if (item.SecondaryImage != null) ignore = item.SecondaryImage.GetLocalImagePath(); if (item.BackdropImages != null) foreach (var image in item.BackdropImages) { ignore = image.GetLocalImagePath(); } if (item.BannerImage != null) ignore = item.BannerImage.GetLocalImagePath(); } }); }); Console.Out.WriteLine(); Console.Out.WriteLine("===[Saving LastFullRefresh]=============================="); Console.Out.WriteLine(); Console.Out.WriteLine("Saving LastFullRefresh in config"); Kernel.Instance.ConfigData.LastFullRefresh = DateTime.Now; Kernel.Instance.ConfigData.Save(); Console.Out.WriteLine(); Console.Out.WriteLine("===[Results]============================================="); Console.Out.WriteLine(); Console.Out.WriteLine("We are done"); Console.Out.WriteLine(); Console.Out.WriteLine("Validation took: " + (new DateTime(validationTime.Ticks)).ToString("HH:mm:ss")); Console.Out.WriteLine("Fast metadata took: " + (new DateTime(fastMetadataTime.Ticks)).ToString("HH:mm:ss")); Console.Out.WriteLine("Slow metadata took: " + (new DateTime(slowMetadataTime.Ticks)).ToString("HH:mm:ss")); Console.Out.WriteLine("Total items in your library: {0}", totalItems); Console.Out.WriteLine(); Console.Out.WriteLine("Fast metadata changed on {0} item's", fastMetadataChanged); Console.Out.WriteLine("Slow metadata changed on {0} item's", slowMetadataChanged); Console.Out.WriteLine(); Console.Out.WriteLine("===[EOF]=================================================="); }
void FullRefresh(Folder folder, MetadataRefreshOptions options) { Kernel.Instance.MajorActivity = true; Information.AddInformationString(CurrentInstance.StringData("FullRefreshMsg")); folder.RefreshMetadata(options); using (new Profiler(CurrentInstance.StringData("FullValidationProf"))) { RunActionRecursively(folder, item => { Folder f = item as Folder; if (f != null) f.ValidateChildren(); }); } using (new Profiler(CurrentInstance.StringData("FastRefreshProf"))) { RunActionRecursively(folder, item => item.RefreshMetadata(MetadataRefreshOptions.FastOnly)); } using (new Profiler(CurrentInstance.StringData("SlowRefresh"))) { RunActionRecursively(folder, item => item.RefreshMetadata(MetadataRefreshOptions.Default)); } Information.AddInformationString(CurrentInstance.StringData("FullRefreshFinishedMsg")); Kernel.Instance.MajorActivity = false; }
public ApiGenreFolder(BaseItem item, string searchParentId = null, string[] includeTypes = null, string[] excludeTypes = null, Folder parent = null) : base(item, searchParentId, includeTypes, excludeTypes, parent) { }
public PersonLetterFolder(string letter, bool?lessThan = null, string searchParentId = null, string[] personTypes = null, string[] includeTypes = null, string[] excludeTypes = null, Folder parent = null) : base(new BaseItem { Name = letter, Id = letter.GetMD5() }, searchParentId, includeTypes, excludeTypes, parent) { PersonTypes = personTypes; UseLessThan = lessThan ?? false; CompareString = String.Compare(letter, "A", StringComparison.Ordinal) < 0 ? "A" : letter; }
public bool ProtectedFolderEntered(Folder folder) { return enteredProtectedFolders.Contains(folder); }
static void FindNewestChildren(Folder folder, SortedList<DateTime, BaseItem> foundNames, int maxSize) { foreach (var item in folder.Children) { // skip folders if (item is Folder) { FindNewestChildren(item as Folder, foundNames, maxSize); } else { DateTime creationTime = item.DateCreated; while (foundNames.ContainsKey(creationTime)) { // break ties creationTime = creationTime.AddMilliseconds(1); } foundNames.Add(creationTime, item); if (foundNames.Count > maxSize) { foundNames.RemoveAt(0); } } } }
void FullRefresh(Folder folder) { using (new Profiler("Full Library Validation")) { RunActionRecursively(folder, item => { Folder f = item as Folder; if (f != null) f.ValidateChildren(); }); } using (new Profiler("Fast Metadata refresh")) { RunActionRecursively(folder, item => item.RefreshMetadata(MetadataRefreshOptions.FastOnly)); } using (new Profiler("Slow Metadata refresh")) { RunActionRecursively(folder, item => item.RefreshMetadata(MetadataRefreshOptions.Default)); } }
public IList<Index> RetrieveIndex(Folder folder, string property, Func<string, BaseItem> constructor) { throw new NotImplementedException(); }
public IList<Index> RetrieveIndex(Folder folder, string property, Func<string, BaseItem> constructor) { bool allowEpisodes = property == "Directors" || property == "ProductionYear"; List<Index> children = new List<Index>(); var cmd = connection.CreateCommand(); //we'll build the unknown items now and leave them out of child table List<BaseItem> unknownItems = new List<BaseItem>(); //create a temporary table of this folder's recursive children to use in the retrievals string tableName = "["+folder.Id.ToString().Replace("-","")+"_"+property+"]"; if (connection.TableExists(tableName)) { connection.Exec("delete from " + tableName); } else { connection.Exec("create temporary table if not exists " + tableName + "(child)"); } cmd.CommandText = "Insert into "+tableName+" (child) values(@1)"; var childParam = cmd.Parameters.Add("@1", DbType.Guid); var containerList = new Dictionary<Guid, IContainer>(); //initialize this for our index SQLInfo.ColDef col = new SQLInfo.ColDef(); Type currentType = null; lock (connection) //can't use delayed writer here - need this table now... { var tran = connection.BeginTransaction(); foreach (var child in folder.RecursiveChildren) { if (child is IShow && !(child is Season) && ((allowEpisodes && !(child is Series)) || (!allowEpisodes && !(child is Episode)))) { if (child is IGroupInIndex) { //add the series object containerList[child.Id] = (child as IGroupInIndex).MainContainer; } //determine if property has any value if (child.GetType() != currentType) { currentType = child.GetType(); col = ItemSQL[currentType].Columns.Find(c => c.ColName == property); } object data = null; if (col.MemberType == MemberTypes.Property) { data = col.PropertyInfo.GetValue(child, null); } else if (col.MemberType == MemberTypes.Field) { data = col.FieldInfo.GetValue(child); } if (data != null) { //Logger.ReportVerbose("Adding child " + child.Name + " to temp table"); childParam.Value = child.Id; cmd.ExecuteNonQuery(); } else { //add to Unknown AddItemToIndex("<Unknown>", unknownItems, containerList, child); } } } tran.Commit(); } //fill in series ContainerDict[tableName] = containerList; //create our Unknown Index - if there were any if (unknownItems.Count > 0) children.Add(new Index(constructor("<Unknown>"), unknownItems)); //now retrieve the values for the main indicies cmd = connection.CreateCommand(); //new command property = property == "Actors" ? "ActorName" : property; //re-map to our name entry if (col.ListType) { //need to get values from list table cmd.CommandText = "select distinct value from list_items where property = '" + property + "' and guid in (select child from " + tableName + ") order by value"; } else { cmd.CommandText = "select distinct " + property + " from items where guid in (select child from " + tableName + ") order by "+property; } using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { //Logger.ReportVerbose("Creating index " + reader[0].ToString() + " on " + folder.Name); object value = reader[0]; children.Add(new Index(constructor(value.ToString()), tableName, property, value)); } } return children; }
public IList<Index> RetrieveIndex(Folder folder, string property, Func<string, BaseItem> constructor) { //compatability with new repo return null; }
static void RunActionRecursively(string desc, Folder folder, Action<BaseItem> action) { Console.Out.WriteLine("Refreshing Folder: " + folder.Path); Console.Out.WriteLine("{0} - {1} : {2} {3} (t) {4}", desc, folder.GetType(), folder.Name, folder.Path, TimeSinceStart()); action(folder); foreach (var item in folder.RecursiveChildren.OrderByDescending(i => i.DateModified)) { Console.Out.WriteLine("{0} - {1} : {2} {3} (t) {4}", desc ,item.GetType(), item.Name, item.Path, TimeSinceStart()); action(item); } }