private void CloneFolder(VirtualFolder parent, IMediaFolder folder) { foreach (var f in folder.ChildFolders) { var vf = new VirtualFolder(parent, f.Title, f.Id); parent.AdoptFolder(vf); CloneFolder(vf, f); } foreach (var i in folder.ChildItems) { if ((types & i.MediaType) == i.MediaType) { parent.AddResource(i); } } }
private void PartitionChildren(VirtualFolder folder, Prefixer prefixer, int startfrom = 1) { for (var wordcount = startfrom;;) { var curwc = wordcount; var groups = from i in folder.ChildItems.ToList() let prefix = prefixer.GetWordPrefix(GetTitle(i), curwc) where !string.IsNullOrWhiteSpace(prefix) group i by prefix.ToLowerInvariant() into g let gcount = g.LongCount() where gcount > 3 orderby g.LongCount() descending select g; var longest = groups.FirstOrDefault(); if (longest == null) { if (wordcount++ > 5) { return; } continue; } var newfolder = new VirtualFolder(folder, longest.Key); foreach (var item in longest) { folder.RemoveResource(item); newfolder.AddResource(item); } if (newfolder.ChildCount > 100) { PartitionChildren(newfolder, prefixer, wordcount + 1); } if (newfolder.ChildFolders.LongCount() == 1) { foreach (var f in newfolder.ChildFolders.ToList()) { folder.AdoptFolder(f); } } else { folder.AdoptFolder(newfolder); } } }
private IMediaFolder RandomOrRatedTracks(bool isRated) { var result = new VirtualFolder() { Name = isRated ? "Random Rated Tracks" : "Random Tracks", Id = isRated ? "vf:randomratedtracks" : "vf:randomtracks" }; foreach (var randomTrack in RandomTracks(RandomTrackLimit, (short)(isRated ? 1 : 0))) { var t = new Track($"r:t:tk:{randomTrack.ReleaseMedia.Release.Id}:{randomTrack.Id}:{ Guid.NewGuid() }", randomTrack.ReleaseMedia.Release.Artist.Name, randomTrack.ReleaseMedia.Release.Title, randomTrack.ReleaseMedia.MediaNumber, randomTrack.Title, randomTrack.ReleaseMedia.Release.Genres.Select(x => x.Genre.Name).ToCSV(), randomTrack.TrackArtist?.Name, randomTrack.TrackNumber, randomTrack.ReleaseMedia.Release.ReleaseYear, TimeSpan.FromMilliseconds(SafeParser.ToNumber <double>(randomTrack.Duration)), isRated ? $"Rating: { randomTrack.Rating }" : randomTrack.PartTitles, randomTrack.LastUpdated ?? randomTrack.CreatedDate, ReleaseCoverArt(randomTrack.ReleaseMedia.Release.RoadieId)); result.AddResource(t); } return(result); }
private IMediaItem TracksForPlaylist(string id) { var playlistId = SafeParser.ToNumber <int>(id.Replace("vf:tracksforplaylist:", "")); var playlist = DbContext.Playlists.FirstOrDefault(x => x.Id == playlistId); var result = new VirtualFolder() { Name = playlist.Name, Id = id }; foreach (var playlistTrack in TracksForPlaylist(playlist.Id)) { var t = new Track($"r:t:tk:{playlistTrack.ReleaseMedia.Release.Id}:{playlistTrack.Id}:{ Guid.NewGuid() }", playlistTrack.ReleaseMedia.Release.Artist.Name, playlistTrack.ReleaseMedia.Release.Title, playlistTrack.ReleaseMedia.MediaNumber, playlistTrack.Title, playlistTrack.ReleaseMedia.Release.Genres.Select(x => x.Genre.Name).ToCSV(), playlistTrack.TrackArtist?.Name, playlistTrack.TrackNumber, playlistTrack.ReleaseMedia.Release.ReleaseYear, TimeSpan.FromMilliseconds(SafeParser.ToNumber <double>(playlistTrack.Duration)), playlistTrack.PartTitles, playlistTrack.LastUpdated ?? playlistTrack.CreatedDate, ReleaseCoverArt(playlistTrack.ReleaseMedia.Release.RoadieId)); result.AddResource(t); } return(result); }
private IMediaItem ReleasesForCollectionFolder(string id) { var collectionId = SafeParser.ToNumber <int>(id.Replace("vf:releasesforcollection:", "")); var collection = DbContext.Collections.FirstOrDefault(x => x.Id == collectionId); var result = new VirtualFolder() { Name = collection.Name, Id = id }; foreach (var collectionRelease in ReleasesForCollection(collection.Id)) { var fr = new VirtualFolder(result, collectionRelease.Title, $"vf:release:{ collectionRelease.Id }"); foreach (var releaseTrack in TracksForRelease(collectionRelease.Id)) { var t = new Track(releaseTrack.RoadieId.ToString(), releaseTrack.ReleaseMedia.Release.Artist.Name, releaseTrack.ReleaseMedia.Release.Title, releaseTrack.ReleaseMedia.MediaNumber, releaseTrack.Title, releaseTrack.ReleaseMedia.Release.Genres.Select(x => x.Genre.Name).ToCSV(), releaseTrack.TrackArtist?.Name, releaseTrack.TrackNumber, releaseTrack.ReleaseMedia.Release.ReleaseYear, TimeSpan.FromMilliseconds(SafeParser.ToNumber <double>(releaseTrack.Duration)), releaseTrack.PartTitles, releaseTrack.LastUpdated ?? releaseTrack.CreatedDate, null); fr.AddResource(t); } result.AddFolder(fr); } return(result); }