Ejemplo n.º 1
0
 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 IMediaAudioResource;
         if (ai == null)
         {
             continue;
         }
         var album = ai.MetaAlbum ?? "Unspecified album";
         albums.GetFolder(album.StemCompareBase()
                          .First()
                          .ToString()
                          .ToUpper(CultureInfo.CurrentUICulture))
         .GetFolder(album.StemNameBase())
         .AddResource(i);
         LinkTriple(artists, ai, ai.MetaArtist, album);
         LinkTriple(performers, ai, ai.MetaPerformer, album);
         var genre = ai.MetaGenre;
         if (genre != null)
         {
             genres.GetFolder(genre.StemNameBase()).AddResource(i);
         }
     }
 }
Ejemplo n.º 2
0
        public override IMediaFolder Transform(IMediaFolder oldRoot)
        {
            var root   = new VirtualClonedFolder(oldRoot);
            var sorted = new SimpleKeyedVirtualFolder(root, Name);

            SortFolder(root, sorted);
            Trace.WriteLine($"sort {sorted.ChildFolders.Count()} - {sorted.ChildItems.Count()}");
            Trace.WriteLine($"root {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);
            }
            Trace.WriteLine($"merg {root.ChildFolders.Count()} - {root.ChildItems.Count()}");
            MergeFolders(root, root);
            Trace.WriteLine($"done {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);
        }