/// <summary> /// /// </summary> /// <param name="style"></param> /// <param name="artistName">This name will be matched to disk folders ignoring accents and case</param> public ArtistFolder(MusicOptions options, MusicStyles style, string artistName) //: base(options, style) { this.artistName = artistName; musicOptions = options; musicStyle = style; log = ApplicationLoggerFactory.CreateLogger <ArtistFolder>(); }
public AudioFile(MusicOptions musicOptions, MusicStyles musicStyle, FileInfo fi) //: base(musicOptions, musicStyle) { this.File = fi; this.musicOptions = musicOptions; log = ApplicationLoggerFactory.CreateLogger(this.GetType()); this.musicStyle = musicStyle; }
//public static async Task SaveCustomTags(this IEnumerable<PerformanceTEO> list) //{ // Debug.Assert(list.Count() != 0); // //Debug.Assert(list.Select(x => x.PathToMusicFiles).Distinct(StringComparer.CurrentCultureIgnoreCase).Count() == 1); // var tagFile = "";// Path.Combine(list.First().PathToMusicFiles, MusicTags.TagFile); // var customList = new List<WesternClassicalMusicTags>(); // foreach (var item in list) // { // var performers = new List<string>(); // foreach (var performer in item.PerformerTag.Values.Where(x => x.Selected)) // { // performers.Add(performer.Value); // } // foreach (var file in item.MovementList) // { // var cpt = new WesternClassicalMusicTags // { // //Album = item.AlbumTag.GetValue<string>(),// .GetStringValue(), // Composer = item.ComposerTag.GetValue<string>(),//.GetStringValue(), // Composition = item.CompositionTag.GetValue<string>(),//.GetStringValue(), // Orchestra = item.OrchestraTag.GetValue<string>(),//.GetStringValue(), // Conductor = item.ConductorTag.GetValue<string>(),//.GetStringValue(), // //Year = item.YearTag.GetValue<int>(),//.GetNumericValue(), // Performers = performers, // Filename = file.File, // TrackNumber = file.TrackNumberTag.GetValue<int>(),//.GetNumericValue(),// file.TrackNumber, // Title = file.TitleTag.GetValue<string>(),//.GetStringValue(), // file.Title, // }; // customList.Add(cpt); // } // } // var text = customList.ToJson(true); // await System.IO.File.WriteAllTextAsync(tagFile, text); //} public static async Task <PopularAlbumTEO> ToPopularAlbumTEO(this Work work, MusicOptions musicOptions) { var teo = new PopularAlbumTEO(musicOptions); await teo.Load(work); return(teo); }
/// <summary> /// Get a list of PathData instances using music style and artist name /// returns an item for each disk source where the style matches and a folder for the artist exists /// </summary> /// <param name="musicOptions"></param> /// <param name="musicStyle"></param> /// <param name="artistName"></param> /// <returns></returns> public static PathData[] GetPathDataList(MusicOptions musicOptions, MusicStyles musicStyle, string artistName) { var list = new List <PathData>(); var style = GetStyleInfo(musicOptions, musicStyle); if (style != null) { //foreach (var rootFolder in new MusicSources(musicOptions).OrderBy(s => s.IsGenerated).ThenBy(s => s.DiskRoot)) foreach (var rootFolder in new MusicSources(musicOptions)) { foreach (var setting in style.Settings) { if (!style.Filter || style.IncludeArtists.Any(x => x.IsEqualIgnoreAccentsAndCase(artistName))) { if (PathExists(rootFolder, setting, artistName)) { var pd = new PathData { DiskRoot = rootFolder.DiskRoot, MusicStyle = musicStyle, StylePath = setting.Path, ArtistPath = artistName, IsGenerated = rootFolder.IsGenerated, IsCollections = string.Compare(artistName, "collections", true) == 0 }; list.Add(pd); } } } } } return(list.ToArray()); }
public WesternClassicalAlbumSet(MusicDb db, MusicOptions musicOptions, IEnumerable <MusicFile> musicFiles, TaskItem taskItem) : base(db, musicOptions, MusicStyles.WesternClassical, musicFiles, taskItem) { this.ArtistName = OpusType == OpusType.Collection ? "Various Composers" : MusicOptions.ReplaceAlias(FirstFile.Musician); this.AlbumName = FirstFile.OpusName; this.YearNumber = FirstFile.GetYear() ?? 0; }
public TaskBase(MusicOptions options, long taskId, string connectionString, BlockingCollection <TaskQueueItem> taskQueue) { musicOptions = options; this.taskId = taskId; this.connectionString = connectionString; this.taskQueue = taskQueue; log = ApplicationLoggerFactory.CreateLogger(GetType()); }
private IEnumerable <string> GetConductors() { return(MusicFiles .Where(x => x.GetConductor() != null) .Select(x => MusicOptions.ReplaceAlias(x.GetConductor())) .Distinct(comparer) .OrderBy(x => x.GetLastName())); }
private IEnumerable <string> GetOrchestras() { return(MusicFiles .Where(x => x.GetOrchestra() != null) .Select(x => MusicOptions.ReplaceAlias(x.GetOrchestra())) .Distinct(comparer) .OrderBy(x => x)); }
protected void Music(string text) { Music music = KickStarter.stateHandler.GetMusicEngine(); if (music == null) { return; } string[] components = text.Split(','); string trackName = components[0].Trim().ToLower(); MusicOptions options = defaultMusicOptions; if (components.Length > 2) { options = GetMusicOptions(components); } else { if (trackName == "stop") { options.method = MusicAction.Stop; } else if (trackName == "resume") { options.method = MusicAction.ResumeLastStopped; } } if (options.method == MusicAction.Play) { foreach (MusicStorage track in KickStarter.settingsManager.musicStorages) { if (track.audioClip.name.ToLower() == trackName) { music.Play(track.ID, options.loop, options.queue, options.transitionTime, options.resume); } } } else if (options.method == MusicAction.Crossfade) { foreach (MusicStorage track in KickStarter.settingsManager.musicStorages) { if (track.audioClip.name.ToLower() == trackName) { music.Crossfade(track.ID, options.loop, options.queue, options.transitionTime, options.resume); } } } else if (options.method == MusicAction.Stop) { music.StopAll(options.transitionTime); } else if (options.method == MusicAction.ResumeLastStopped) { music.ResumeLastQueue(options.transitionTime, options.resume); } }
public TaskRunner(IServiceProvider sp, IOptions <MusicOptions> options, IConfiguration cfg, IWebHostEnvironment environment, ILogger <TaskRunner> logger) : base(logger) { this.serviceProvider = sp; this.options = options.Value; maxConsumerThreads = Math.Max(1, this.options.MaxTaskThreads); connectionString = environment.LocaliseConnectionString(cfg.GetConnectionString("MusicDb")); }
public TaskPublisher(TaskRunner runner, IServiceProvider sp, IConfiguration cfg, IWebHostEnvironment environment, IOptions <MusicOptions> mso, ILogger <TaskPublisher> logger) : base(logger) { this.taskRunner = runner; this.serviceProvider = sp; this.musicOptions = mso.Value; connectionString = environment.LocaliseConnectionString(cfg.GetConnectionString("MusicDb")); //this.BeforeTaskStartsAsync = OnStartup; }
public TaskHost(IServiceProvider sp, MusicOptions options, BlockingCollection <TaskQueueItem> taskQueue, string connectionString, CancellationToken cancellationToken) { this.serviceProvider = sp; this.options = options; this.cancellationToken = cancellationToken; this.hostIdentity = ++hostIdentifier; this.log = ApplicationLoggerFactory.CreateLogger($"Fastnet.Apollo.Web.TaskHost{hostIdentity}"); this.connectionString = connectionString; this.taskQueue = taskQueue; }
public static string GetPortraitFile(this Artist artist, MusicOptions musicOptions) { var ln = artist.Name.GetLastName(); bool matchImageFilename(string imageFileName, string artistName) { var imagename = Path.GetFileNameWithoutExtension(imageFileName).ToLower(); return("portrait" == imagename || artist.Name.IsEqualIgnoreAccentsAndCase(imagename) || ln.IsEqualIgnoreAccentsAndCase(imagename)); } bool matchArtistFolder(string sp, string artistName, string folder) { bool _match(string sp, string name) { var artistFolder = Path.Combine(sp, name); if (artistFolder.IsEqualIgnoreAccentsAndCase(folder)) { return(true); } return(false); } if (_match(sp, artistName)) { return(true); } else { if (artistName.StartsWith("The ", StringComparison.CurrentCultureIgnoreCase)) { artistName = artistName.Substring(4); } else { artistName = $"The {artistName}"; } return(_match(sp, artistName)); } } var allStylePaths = artist.ArtistStyles.ToArray() .SelectMany(x => x.StyleId.GetPaths(musicOptions, false, false)); var allArtistPaths = allStylePaths.SelectMany( sp => Directory.EnumerateDirectories(sp) .Where(d => matchArtistFolder(sp, artist.Name, d) || Path.GetFileNameWithoutExtension(d).ToLower() == "$portraits")); var imageFiles = allArtistPaths.SelectMany(x => Directory.EnumerateFiles(x, "*.jpg") .Union(Directory.EnumerateFiles(x, "*.jpeg")) .Union(Directory.EnumerateFiles(x, "*.png"))); var matchedFiles = imageFiles.Where(f => matchImageFilename(f, artist.Name)); return(matchedFiles.OrderByDescending(x => new FileInfo(x).LastWriteTime).FirstOrDefault()); }
public WesternClassicalCompositionSet(MusicDb db, MusicOptions musicOptions, string composerName, string compositionName, IEnumerable <MusicFile> musicFiles, TaskItem taskItem) : base(db, musicOptions, MusicStyles.WesternClassical, musicFiles, taskItem) { var fileNameList = musicFiles.Select(x => Path.GetFileName(x.File)); this.ComposerName = musicOptions.ReplaceAlias(composerName); this.CompositionName = musicOptions.ReplaceAlias(compositionName); //**NB** following calls must remain in this order!! conductors = GetConductors(); orchestras = GetOrchestras(); otherPerformers = GetOtherPerformers(); }
internal PopularMusicAlbumSet(MusicDb db, MusicOptions musicOptions, string artistName, string albumName, IEnumerable <MusicFile> musicFiles, TaskItem taskItem) : base(db, musicOptions, MusicStyles.Popular, musicFiles, taskItem) { this.ArtistName = FirstFile.GetArtistName() ?? artistName; this.AlbumName = FirstFile.GetWorkName() ?? albumName; this.YearNumber = FirstFile.GetYear() ?? 0; if (string.Compare(this.AlbumName, "Greatest Hits", true) == 0) { // prefix with artist name as there are so many called "Greatest Hits" this.AlbumName = $"{ArtistName} Greatest Hits"; } }
/// <summary> /// create a a music set for the given music files in the given music style /// </summary> /// <param name="musicOptions"></param> /// <param name="musicStyle"></param> /// <param name="musicFiles"></param> public MusicSet(MusicDb db, MusicOptions musicOptions, MusicStyles musicStyle, IEnumerable <MusicFile> musicFiles, TaskItem taskItem) { Debug.Assert(musicFiles.Count() > 0); this.log = ApplicationLoggerFactory.CreateLogger(this.GetType()); this.MusicDb = db; this.MusicOptions = musicOptions; this.MusicStyle = musicStyle; this.MusicFiles = musicFiles; this.taskItem = taskItem; this.FirstFile = musicFiles.First(); this.OpusType = FirstFile.OpusType; this.generated = FirstFile.IsGenerated; }
/// <summary> /// files is a set of music files fom the same opus (ie. originalyl from the same disk folder) /// </summary> /// <param name="files"></param> internal MusicSetCollection(MusicOptions musicOptions, MusicDb musicDb, OpusFolder musicFolder, List <MusicFile> files, TaskItem taskItem) { this.musicOptions = musicOptions; this.musicDb = musicDb; this.musicFolder = musicFolder; this.files = files; this.taskItem = taskItem; //Debug.Assert(ValidateMusicFileSet()); var firstFile = files.First(); isCollection = firstFile.OpusType == OpusType.Collection; musicStyle = firstFile.Style; }
public OpusFolder(MusicOptions musicOptions, PathData pathData) { this.log = ApplicationLoggerFactory.CreateLogger <OpusFolder>(); this.mfi = new MusicFolderInformation { MusicOptions = musicOptions, MusicStyle = pathData.MusicStyle, Paths = new PathData[] { pathData }, IncludeSingles = pathData.MusicStyle == MusicStyles.Popular }; this.currentPathData = pathData; if (pathData.OpusPath == null) { this.forSinglesOnly = pathData.MusicStyle == MusicStyles.Popular; } }
/// <summary> /// get the most applicable cover file for the work, according to the rules /// i) jpg is preferred to jpeg which is preferred to png (.xxx below) /// ii) *cover.xxx is preferred to *front.xxx which is preferred *folder.xxx /// </summary> /// <param name="work"></param> /// <param name="musicOptions"></param> /// <param name="musicStyle"></param> /// <param name="folderName"></param> /// <returns></returns> public static string GetCoverFile(this Work work, MusicOptions musicOptions, string folderName = null) { folderName ??= work.Name; string coverFile = null; //var allworkFolders = work.StyleId.FindAllDirectories(musicOptions, work.Artist.Name, work.Name); var allworkFolders = work.StyleId.GetOpusFolders(musicOptions, work.Artist.Type, work.Artist.Name, work.Name); foreach (var pattern in musicOptions.CoverFilePatterns) { coverFile = allworkFolders.SelectMany(p => IO.Directory.EnumerateFiles(p, pattern, IO.SearchOption.AllDirectories)).FirstOrDefault(cf => IO.File.Exists(cf)); if (coverFile != null) { break; } } return(coverFile); }
public LibraryController(/*SchedulerService schedulerService ,*/ IWebHostEnvironment env, IOptions <MusicServerOptions> mso, /*IServiceProvider sp,*/ TaskPublisher tp, TaskRunner tr, IOptionsMonitor <MusicOptions> mo, ILogger <LibraryController> logger, MusicDb mdb) : base(logger, env) { this.musicOptions = mo.CurrentValue; //this.ss = schedulerService;// hs as SchedulerService; mo.OnChangeWithDelay((opt) => { this.musicOptions = opt; }); this.contentRootPath = env.ContentRootPath; this.log = logger; this.musicServerOptions = mso.Value; this.musicDb = mdb; this.taskPublisher = tp; this.taskRunner = tr; }
protected MusicOptions GetMusicOptions(string[] components) { MusicOptions options = defaultMusicOptions; for (int i = 2; i < components.Length; i++) { string option = components[i].Trim().ToLower(); if (option.EndsWith("loop")) { options.loop = TagState(option); } else if (option.EndsWith("queue")) { options.queue = TagState(option); } else if (option.EndsWith("resume")) { options.resume = TagState(option); } else if (option.EndsWith("wait")) { options.wait = TagState(option); } else if (option.StartsWith("fade")) { string[] fadeComponents = option.Split('='); if (fadeComponents.Length == 2) { options.transitionTime = (float)Convert.ToDouble(fadeComponents[1]); } } else if (option == "play") { options.method = MusicAction.Play; } else if (option == "crossfade") { options.method = MusicAction.Crossfade; } } return(options); }
public static CatalogueSearcher GetSearcher(MusicOptions options, MusicStyles style, MusicDb musicDb, ILogger log = null) { CatalogueSearcher cs = null; switch (style) { case MusicStyles.Popular: cs = new PopularSearcher(); break; case MusicStyles.WesternClassical: cs = new WesternClassicalSearcher(); break; } cs.Options = options; cs.MusicStyle = style; cs.MusicDb = musicDb; cs.log = log; return(cs); }
private IEnumerable <string> GetOtherPerformers() { var _names = new List <string>(); foreach (var mf in MusicFiles) { var list = mf.GetPerformers() .Select(x => MusicOptions.ReplaceAlias(x)) .Except(new string[] { MusicOptions.ReplaceAlias(mf.Musician) }, comparer) ; _names.AddRange(list); } //names = names.Distinct(comparer).ToList(); _names = _names.Distinct(comparer).ToList(); var g1 = _names.GroupBy(x => x.GetLastName()); var names = new List <string>(); foreach (var item in g1) { if (!ComposerName.EndsWithIgnoreAccentsAndCase(item.Key)) { names.Add(item.OrderByDescending(x => x.Length).First()); } } names = names //.Distinct(comparer) .OrderBy(x => x.GetLastName()) //.ThenBy(x => x) .ToList(); foreach (var orchestra in orchestras) { names = RemoveName(names, orchestra).ToList(); } foreach (var conductor in conductors) { names = RemoveName(names, conductor).ToList(); } return(names); }
//public static string GetMostRecentOpusCoverFile(this MusicStyles musicStyle, MusicOptions musicOptions, Work work, string opusPath = null) //{ // return musicStyle.GetMostRecentOpusCoverFile(musicOptions, work.Artist.Type, work.Artist.Name, opusPath ??= work.Name); //} public static string GetMostRecentOpusCoverFile(this Work work, MusicOptions musicOptions) { //var musicFiles = work.Tracks.SelectMany(t => t.MusicFiles) // .Where(mf => !mf.IsGenerated).AsEnumerable(); var folders = new List <string>(); foreach (var mf in work.Tracks.SelectMany(t => t.MusicFiles) .Where(mf => !mf.IsGenerated)) { var pathFragments = new List <string>(new string[] { mf.DiskRoot, mf.StylePath }); if (work.Type == OpusType.Collection) { pathFragments.Add("Collections"); } pathFragments.AddRange(mf.OpusPath.Split("\\")); //if(mf.IsMultiPart) //{ // pathFragments.Add(mf.PartName); //} folders.Add(Path.Combine(pathFragments.ToArray())); } IEnumerable <string> imageFiles = null; try { foreach (var pattern in musicOptions.CoverFilePatterns) { foreach (var path in folders) { imageFiles = imageFiles?.Union(Directory.EnumerateFiles(path, pattern, SearchOption.AllDirectories)) ?? Directory.EnumerateFiles(path, pattern, SearchOption.AllDirectories); } } return(imageFiles.OrderByDescending(x => new FileInfo(x).LastWriteTime).FirstOrDefault()); } catch (Exception xe) { log.Error(xe, $"called with [W-{work.Id}] {work.Name}, imagefiles: {imageFiles?.Count().ToString() ?? "null"}"); } return(null); }
protected async Task <Artist> GetArtistAsync(string name) { Debug.Assert(MusicDb != null); name = MusicOptions.ReplaceAlias(name); Artist artist = FindArtist(name); if (artist == null) { artist = new Artist { UID = Guid.NewGuid(), Name = name, Type = ArtistType.Artist, OriginalName = name, }; artist.ArtistStyles.Add(new ArtistStyle { Artist = artist, StyleId = MusicStyle }); log.Debug($"{taskItem} new artist instance for {name}, {artist.Id}"); if (this is PopularMusicAlbumSet && OpusType == OpusType.Collection) { artist.Type = ArtistType.Various; } await MusicDb.Artists.AddAsync(artist); await MusicDb.SaveChangesAsync(); } if (artist.Type != ArtistType.Various) { // var artistFoldername = OpusType == OpusType.Collection ? null : FirstFile.OpusPath.Split('\\')[0];// Path.GetFileName(Path.GetDirectoryName(FirstFile.File)); var portrait = artist.GetPortraitFile(MusicOptions); if (portrait != null) { artist.Portrait = await portrait.GetImage(); } } artist.LastModified = DateTimeOffset.Now; return(artist); }
private static IEnumerable <string> GetFoldersAcrossStyles(MusicOptions musicOptions, IEnumerable <MusicStyles> musicStyles, string folderName) { try { var stylePaths = new List <string>(); foreach (var ms in musicStyles) { stylePaths.AddRange(ms.GetPaths(musicOptions, false, false)); } var t1 = stylePaths.Select(x => IO.Path.Combine(x, folderName)); var t2 = t1.Where(x => IO.Directory.Exists(x)); var t3 = stylePaths.Select(x => IO.Path.Combine(x, folderName)) .Where(x => IO.Directory.Exists(x)); return(stylePaths.Select(x => IO.Path.Combine(x, folderName)) .Where(x => IO.Directory.Exists(x))); } catch (Exception) { Debugger.Break(); throw; } }
public static IEnumerable <string> GetPortraitPaths(MusicOptions musicOptions, MusicStyles style) { var pathList = new List <string>(); var styleInfo = GetStyleInfo(musicOptions, style); if (styleInfo != null) { foreach (var source in new MusicSources(musicOptions)) { if (!source.IsGenerated) { foreach (var path in styleInfo.Settings.Select(s => s.Path)) { var portraitPath = Path.Combine(source.DiskRoot, path, "$Portraits"); if (Directory.Exists(portraitPath)) { pathList.Add(portraitPath); } } } } } return(pathList); }
public static async Task <WesternClassicalAlbumTEO> ToWesternClassicalAlbumTEO(this Performance performance, MusicOptions musicOptions) { await Task.Delay(0); var works = performance.Movements.Select(x => x.Work).Distinct(); var work = works.First(); return(await work.ToWesternClassicalAlbumTEO(musicOptions)); }
public static async Task <WesternClassicalAlbumTEO> ToWesternClassicalAlbumTEO(this Work work, MusicOptions musicOptions) { var teo = new WesternClassicalAlbumTEO(musicOptions); await teo.Load(work); return(teo); }
/// <summary> /// Constructor which takes a value parameter. /// </summary> /// <param name="value">The value for the MusicSetting object.</param> public MusicSetting(MusicOptions value) : base(default(SettingType), null, null, null) { // TODO: Remove null values from constructor to implement }
public CataloguePath(MusicOptions options, long taskId, string connectionString, BlockingCollection <TaskQueueItem> taskQueue, PlayManager pm) : base(options, taskId, connectionString, taskQueue) { this.playManager = pm; }
public HomeController(IOptions<MusicOptions> options, ILogger<HomeController> logger, IHostingEnvironment env) : base(env) { this.Options = options.Value; this.logger = logger; }
public ScanController(IMusicRepository mr, IOptions<MusicOptions> options, ILogger<ScanController> logger, IHostingEnvironment env) : base(env) { this.musicRepository = mr; this.logger = logger; this.Options = options.Value; }