Example #1
0
        private async Task <TaskItem> AddTask(MusicDb db, MusicStyles style, TaskType type, string taskString, /* bool queueTask = true,*/ bool force = false)
        {
            var existing = db.TaskItems
                           .Where(t => t.Type == type && t.MusicStyle == style &&
                                  t.TaskString.ToLower() == taskString.ToLower() &&
                                  (t.Status == Music.Core.TaskStatus.Pending || t.Status == Music.Core.TaskStatus.InProgress) &&
                                  t.Force == force);

            if (existing.Count() == 0)
            {
                var now = DateTimeOffset.Now;
                var ti  = new TaskItem
                {
                    Type        = type,
                    CreatedAt   = now,
                    ScheduledAt = now,
                    Status      = Music.Core.TaskStatus.Pending,
                    MusicStyle  = style,
                    TaskString  = taskString,
                    Force       = force
                };
                await db.TaskItems.AddAsync(ti);

                await db.SaveChangesAsync();

                taskRunner.QueueTask(ti);
                return(ti);
            }
            else
            {
                log.Debug($"Task type {type} for target {taskString} skipped as alrerady present");
            }
            return(null);
        }
Example #2
0
        public async Task <IActionResult> UpdateWork(MusicStyles style)
        {
            ITEOBase teo = null;

            switch (style)
            {
            case MusicStyles.Popular:
                teo = await this.Request.FromBody <PopularAlbumTEO>();

                break;

            case MusicStyles.WesternClassical:
                teo = await this.Request.FromBody <WesternClassicalAlbumTEO>();

                break;
            }
            var id   = teo.Id;
            var work = await musicDb.Works.FindAsync(id);

            teo.AfterDeserialisation(work);
            teo.SaveChanges(work);
            await teo.SaveMusicTags();

            work.LastModified = DateTimeOffset.Now;
            await musicDb.SaveChangesAsync();

            return(SuccessResult());
        }
Example #3
0
 /// <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>();
 }
Example #4
0
 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;
 }
Example #5
0
        private TaskItem CreateTask(MusicDb db, MusicStyles style, TaskType type, string taskString)
        {
            var existing = db.TaskItems
                           .Where(t => t.Type == type && t.MusicStyle == style &&
                                  t.TaskString.ToLower() == taskString.ToLower() &&
                                  (t.Status == Music.Core.TaskStatus.Pending || t.Status == Music.Core.TaskStatus.InProgress)
                                  );

            if (existing.Count() == 0)
            {
                var now = DateTimeOffset.Now;
                var ti  = new TaskItem
                {
                    Type        = type,
                    CreatedAt   = now,
                    ScheduledAt = now,
                    Status      = Music.Core.TaskStatus.Pending,
                    MusicStyle  = style,
                    TaskString  = taskString
                };
                return(ti);
            }
            else
            {
                log.Information($"Task type {type} for target {taskString} skipped as already present");
            }
            return(null);
        }
Example #6
0
        /// <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());
        }
Example #7
0
        public IActionResult GetAllArtists(MusicStyles style)
        {
            var artists = musicDb.ArtistStyles.Where(x => x.StyleId == style && x.Artist.Type != ArtistType.Various)
                          .Select(x => x.Artist.Id);

            return(SuccessResult(artists));
        }
Example #8
0
        public static IEnumerable <ArtistFolder> GetArtistFolders(this MusicStyles musicStyle, MusicOptions musicOptions, string selectedRootFolder = null)
        {
            var folderList = new List <ArtistFolder>();

            var style = MusicMetaDataMethods.GetStyleInfo(musicOptions, musicStyle);

            if (style != null)
            {
                var list = new List <string>();
                //foreach (var rootFolder in new MusicSources(musicOptions).Where(s => !s.IsGenerated).OrderBy(s => s.DiskRoot))
                foreach (var rootFolder in new MusicSources(musicOptions))
                {
                    foreach (var setting in style.Settings)
                    {
                        var path = Path.Combine(rootFolder.DiskRoot, setting.Path);
                        if (selectedRootFolder == null || path.StartsWithIgnoreAccentsAndCase(selectedRootFolder))
                        {
                            if (Directory.Exists(path))
                            {
                                list.AddRange(Directory.EnumerateDirectories(path).Select(d => Path.GetFileName(d)));
                            }
                        }
                    }
                }
                var list2 = list.Except(new string[] { "collections", "$portraits" }, StringComparer.CurrentCultureIgnoreCase);
                if (style.Filter)
                {
                    list2 = list2.Intersect(style.IncludeArtists, new AccentAndCaseInsensitiveComparer());
                }
                list2      = list2.Distinct(new AccentAndCaseInsensitiveComparer()).OrderBy(x => x);
                folderList = list2.Select(n => new ArtistFolder(musicOptions, musicStyle, n)).ToList();
            }
            return(folderList);
        }
Example #9
0
        /// <summary>
        /// Finds all opus folders of this name for this artist across all sources
        /// for artists of type "various", artistName is replaced with "Collections"
        /// </summary>
        /// <param name="musicStyle"></param>
        /// <param name="musicOptions"></param>
        /// <param name="type"></param>
        /// <param name="artistName"></param>
        /// <param name="opusPath"></param>
        /// <returns></returns>
        public static IEnumerable <string> GetOpusFolders(this MusicStyles musicStyle, MusicOptions musicOptions, ArtistType type, string artistName, string opusPath)
        {
            var list = new List <string>();

            void AddToList(string opusPath, string artistFolder)
            {
                if (opusPath == null)
                {
                    list.Add(artistFolder);
                }
                else
                {
                    var path2      = Path.Combine(artistFolder, opusPath);
                    var workFolder = Directory.EnumerateDirectories(artistFolder).SingleOrDefault(ap => ap.IsEqualIgnoreAccentsAndCase(path2));
                    if (workFolder != null)
                    {
                        list.Add(workFolder);
                    }
                }
            }

            string getArtistFolder(string stylePath, string name)
            {
                var path1 = Path.Combine(stylePath, type == ArtistType.Various ? "Collections" : name);

                return(Directory.EnumerateDirectories(stylePath).SingleOrDefault(ap => ap.IsEqualIgnoreAccentsAndCase(path1)));
            }

            foreach (var stylePath in musicStyle.GetPaths(musicOptions, false, false))
            {
                //var path1 = Path.Combine(stylePath, type == ArtistType.Various ? "Collections" : artistName);
                //var artistFolder = Directory.EnumerateDirectories(stylePath).SingleOrDefault(ap => ap.IsEqualIgnoreAccentsAndCase(path1));
                var artistFolder = getArtistFolder(stylePath, artistName);
                if (artistFolder != null)
                {
                    AddToList(opusPath, artistFolder);
                }
                else if (type != ArtistType.Various)
                {
                    if (artistName.StartsWith("The ", StringComparison.CurrentCultureIgnoreCase))
                    {
                        artistFolder = getArtistFolder(stylePath, artistName.Substring(4));
                    }
                    else
                    {
                        artistFolder = getArtistFolder(stylePath, $"The {artistName}");
                    }
                    if (artistFolder != null)
                    {
                        AddToList(opusPath, artistFolder);
                    }
                }
            }
            return(list);
        }
Example #10
0
 public static MusicStyleManager Get(MusicDatabase md, MusicStyles style)
 {
     MusicStyleManager ms = null;
     switch (style)
     {
         case MusicStyles.Popular:
             ms = new PopularStyleManager(md);
             break;
     }
     return ms;
 }
Example #11
0
        /// <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;
        }
Example #12
0
 /// <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;
 }
Example #13
0
        public async Task <IActionResult> Search(MusicStyles style, string searchText)
        {
            await Task.Delay(0);

            log.Debug($"Search for {searchText} ...");
            var cs = CatalogueSearcher.GetSearcher(this.musicOptions, style, this.musicDb, this.log);

            using (new TimedAction((t) => log.Debug($"    ... completed in {t.ToString("c")}")))
            {
                var(prefixMode, results) = cs.Search(searchText);
                return(SuccessResult(new { prefixMode, results }));
            }
        }
Example #14
0
        /// <summary>
        /// return a list of valid style paths that exists, i.e. where the style is enabled and for each source that is enabled
        /// (compare with MusicSet version which does test for enabled in either case - should this replace that?)
        /// </summary>
        /// <param name="musicOptions"></param>
        /// <param name="musicStyle"></param>
        /// <param name="includeGenerated">default is false</param>
        /// <param name="includeDisabledStyles">default is false</param>
        /// <returns></returns>
        //public static IEnumerable<string> GetPaths(this MusicStyles musicStyle, MusicOptions musicOptions,
        //    bool excludeGenerated = true)
        public static IEnumerable <string> GetPaths(this MusicStyles musicStyle, MusicOptions musicOptions,
                                                    bool includeGenerated, bool includeDisabledStyles)
        {
            var list = new List <string>();

            if (musicOptions.Styles.Single(x => x.Style == musicStyle).Enabled || includeDisabledStyles == true)
            {
                foreach (var source in musicOptions.Sources.Where(x => x.Enabled && (includeGenerated == true || !x.IsGenerated)))
                {
                    list.AddRange(musicOptions.Styles.Single(x => x.Style == musicStyle)
                                  .Settings.Select(x => Path.Combine(source.DiskRoot, x.Path))
                                  .Where(x => Directory.Exists(x))
                                  );
                }
            }
            return(list);
        }
Example #15
0
        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);
        }
Example #16
0
        public async Task <TaskItem> AddTask(MusicStyles style, TaskType type, string taskString, /*bool queueTask = true,*/ bool force = false)
        {
            using (var db = new MusicDb(connectionString))
            {
                return(await AddTask(db, style, type, taskString, force));

                //var existing = db.TaskItems
                //    .Where(t => t.Type == type && t.MusicStyle == style
                //        && t.TaskString.ToLower() == taskString.ToLower()
                //        && (t.Status == Music.Core.TaskStatus.Pending || t.Status == Music.Core.TaskStatus.InProgress)
                //        && t.Force == force);
                //if (existing.Count() == 0)
                //{
                //    var now = DateTimeOffset.Now;
                //    var ti = new TaskItem
                //    {
                //        Type = type,
                //        CreatedAt = now,
                //        ScheduledAt = now,
                //        Status = Music.Core.TaskStatus.Pending,
                //        MusicStyle = style,
                //        TaskString = taskString,
                //        Force = force
                //    };
                //    await db.TaskItems.AddAsync(ti);
                //    await db.SaveChangesAsync();
                //    if (queueTask)
                //    {
                //        taskRunner.QueueTask(ti);
                //    }
                //    return ti;
                //}
                //else
                //{
                //    log.Debug($"Task type {type} for target {taskString} skipped as alrerady present");
                //}
                //return null;
            }
        }
Example #17
0
        private List <TaskItem> ExpandMusicStyle(MusicStyles style)
        {
            var taskList = new List <TaskItem>();

            foreach (var af in style.GetArtistFolders(musicOptions))
            {
                // check here for $portraits
                // check here for singles - are these causing duplicates/
                var items = ExpandArtistFolder(af);
                taskList.AddRange(items);
            }
            var cf = style.GetCollectionsFolder(musicOptions);

            foreach (var folder in cf.GetOpusFolders())
            {
                var l = ExpandOpusFolder(folder.Folderpath, false);
                if (l != null)
                {
                    taskList.Add(l);
                }
            }
            return(taskList);
        }
Example #18
0
 private void GetSelectedArtists(MusicStyles musicStyle, IEnumerable <string> names)
 {
     foreach (var name in names)
     {
         var af          = new ArtistFolder(musicOptions, musicStyle, name);
         var opusFolders = af.GetOpusFolders();
         if (musicStyle == MusicStyles.Popular)
         {
             log.Information($"{af} has {opusFolders.Count()} album folders (of which {opusFolders.Where(f => f.ForSinglesOnly).Count()} are for singles only");
         }
         else
         {
             log.Information($"{af} has {opusFolders.Count()} album folders");
         }
         foreach (var wf in opusFolders)
         {
             var files = wf.GetFilesOnDisk();
             if (files.Count() > 0)
             {
                 log.Information($"   {wf}, {files.Count()} music files");
             }
         }
     }
 }
Example #19
0
 private async Task  CatalogueFolder(MusicStyles style, string path)
 {
     //D:\Music\flac\Western\Classical\Wolfgang Amadeus Mozart\Concerto for Flute and Harp
     await taskPublisher.AddTask(style, TaskType.DiskPath, path, true);
 }
Example #20
0
 public static CollectionsFolder GetCollectionsFolder(this MusicStyles musicStyle, MusicOptions musicOptions)
 {
     return(new CollectionsFolder(musicOptions, musicStyle));
 }
Example #21
0
 /// <summary>
 /// internal use by WesternClassicalAlbumSet only
 /// </summary>
 /// <param name="musicStyle"></param>
 /// <param name="musicFiles"></param>
 internal PopularMusicAlbumSet(MusicDb db, MusicOptions musicOptions, MusicStyles musicStyle,
                               IEnumerable <MusicFile> musicFiles, TaskItem taskItem) : base(db, musicOptions, musicStyle, musicFiles, taskItem)
 {
 }
 /// <summary>
 /// Gets the best matching chord.
 /// </summary>
 /// <param name="pitchList">The list of pitches.</param>
 /// <param name="basePitch">The pitch of the base tone.</param>
 /// <param name="style">The style of music.</param>
 /// <returns>
 /// The best matching chord.
 /// </returns>
 public IChord GetBestMatchingChord(Pitch[] pitchList, Pitch basePitch = null, MusicStyles style = MusicStyles.Unspecified)
 {
     throw new System.NotImplementedException();
 }
Example #23
0
        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);
        }
Example #24
0
 public Mp3File(MusicOptions musicOptions, MusicStyles style, FileInfo fi) : base(musicOptions, style, fi)
 {
 }
Example #25
0
 public CollectionsFolder(MusicOptions options, MusicStyles style) //: base(options, style)
 {
     musicOptions = options;
     musicStyle   = style;
     log          = ApplicationLoggerFactory.CreateLogger <CollectionsFolder>();
 }
Example #26
0
 public async Task AddTask(MusicStyles style, string artistName, bool force = false)
 {
     await AddTask(style, TaskType.ArtistName, artistName, force);
 }
Example #27
0
 public static StyleInformation GetStyleInfo(MusicOptions musicOptions, MusicStyles musicStyle)
 {
     //StyleInfo si;
     return(musicOptions.Styles.SingleOrDefault(s => s.Style == musicStyle && s.Enabled));
 }
Example #28
0
 private async Task AddPortraitsTask(MusicStyles style)
 {
     await taskPublisher.AddPortraitsTask(style);
 }
Example #29
0
 public async Task AddTask(MusicStyles style, bool force = false)
 {
     await AddTask(style, TaskType.MusicStyle, style.ToString(), force);
 }