public override IMediaFolder Transform(IMediaFolder oldRoot) { var root = new VirtualClonedFolder(oldRoot); var sorted = new SimpleKeyedVirtualFolder(root, Name); SortFolder(root, sorted); DebugFormat("sort {0} - {1}", sorted.ChildFolders.Count(), sorted.ChildItems.Count()); DebugFormat("root {0} - {1}", root.ChildFolders.Count(), root.ChildItems.Count()); foreach (var f in sorted.ChildFolders.ToList()) { if (f.ChildCount < 2) { foreach (var file in f.ChildItems) { root.AddResource(file); } continue; } var fsmi = f as VirtualFolder; root.AdoptFolder(fsmi); } foreach (var f in sorted.ChildItems.ToList()) { root.AddResource(f); } DebugFormat("merg {0} - {1}", root.ChildFolders.Count(), root.ChildItems.Count()); MergeFolders(root, root); DebugFormat("done {0} - {1}", root.ChildFolders.Count(), root.ChildItems.Count()); if (!cascade || root.ChildFolders.LongCount() <= 50) { return(root); } var cascaded = new DoubleKeyedVirtualFolder(root, "Series"); foreach (var i in root.ChildFolders.ToList()) { var folder = cascaded.GetFolder(i.Title.StemCompareBase().Substring(0, 1).ToUpper()); folder.AdoptFolder(i); } foreach (var i in root.ChildItems.ToList()) { var folder = cascaded.GetFolder(i.Title.StemCompareBase().Substring(0, 1).ToUpper()); folder.AddResource(i); } return(cascaded); }
private static void SortFolder(VirtualFolder folder, TripleKeyedVirtualFolder artists, TripleKeyedVirtualFolder performers, DoubleKeyedVirtualFolder albums, SimpleKeyedVirtualFolder genres) { foreach (var f in folder.ChildFolders.ToList()) { SortFolder(f as VirtualFolder, artists, performers, albums, genres); } foreach (var i in folder.ChildItems.ToList()) { var ai = i as IMetaAudioItem; if (ai == null) { continue; } var album = ai.MetaAlbum; if (album == null) { album = "Unspecified album"; } albums.GetFolder(album.StemCompareBase().First().ToString().ToUpper()).GetFolder(album.StemNameBase()).AddResource(i); LinkTriple(artists, i, ai.MetaArtist, album); LinkTriple(performers, i, ai.MetaPerformer, album); var genre = ai.MetaGenre; if (genre != null) { genres.GetFolder(genre.StemNameBase()).AddResource(i); } } }
public override IMediaFolder Transform(IMediaFolder Root) { var root = new VirtualClonedFolder(Root); var series = new SimpleKeyedVirtualFolder(root, "Series"); SortFolder(root, series); foreach (var f in series.ChildFolders.ToList()) { if (f.ChildCount < 2) { foreach (var file in f.ChildItems) { root.AddResource(file); } continue; } var fsmi = f as VirtualFolder; root.AdoptFolder(fsmi); } if (!cascade || root.ChildFolders.LongCount() <= 50) { return(root); } var cascaded = new DoubleKeyedVirtualFolder(root, "Series"); foreach (var i in root.ChildFolders.ToList()) { var folder = cascaded.GetFolder(i.Title.StemCompareBase().Substring(0, 1).ToUpper()); folder.AdoptFolder(i); } foreach (var i in root.ChildItems.ToList()) { var folder = cascaded.GetFolder(i.Title.StemCompareBase().Substring(0, 1).ToUpper()); folder.AddResource(i); } return(cascaded); }