static void Analyze() { Settings settings = Settings.Instance; Console.WriteLine("Please enter the directory path to analyze : "); var path = PathUtils.Normalize(Console.ReadLine()); if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) { throw new Exception("Not found path"); } var files = new MusicFileDaoDetector().Search(new List <string>() { path }); foreach (var i in files) { IEnumerable <MusicDao> tag = null; try { tag = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(i.Path); } catch (Exception e) { Console.WriteLine("File audio error : " + i.Path); Console.WriteLine(e.Message); continue; } if (tag == null || tag.Count() <= 0) { Console.WriteLine("File not recognized : " + i.Path); continue; } Console.WriteLine("File recognized : " + i.Path); if (tag.Count() == 1) { i.Map(tag.First()); } else { int nbMin = int.MaxValue; MusicDao tagMin = null; foreach (var j in tag) { var nb = LevenshteinDistance.Compute(i.FileName, string.Format("{0} - {1}", j.Artist, j.Title)); if (nb < nbMin) { nbMin = nb; tagMin = j; } } i.Map(tagMin); } i.Save(); } }
public void SearchMusic_UnfoundExtension() { var data = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas"); var result = new MusicFileDaoDetector(new List <MusicFileExtension>() { MusicFileExtension.wave }).SearchInDirectory(data); Assert.IsNull(result); }
public void SearchMusic_RealFiles() { var data = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas"); var result = new MusicFileDaoDetector().SearchInDirectory(data); Assert.IsNotNull(result); var test = result.SingleOrDefault(p => p.FileName.Contains("test1.mp3")); Assert.IsNotNull(test); Assert.IsTrue(test.Extension == MusicFileExtension.mp3); Assert.IsTrue(test.Title.Contains("I Like It")); Assert.IsTrue(test.Kind.Contains("Pop")); Assert.IsTrue(test.Year == 2010); Assert.IsTrue(test.Artist.Contains("Enrique Iglesias")); Assert.IsTrue(test.Album.Contains("I Like It Single")); }
/// <summary> /// Ask to the user to chose a folder and display content. Subfolders are also displayed. /// </summary> private void Browse() { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { FolderPath = fbd.SelectedPath; IEnumerable <MusicFileDao> files = new MusicFileDaoDetector().SearchInDirectory(FolderPath); // Load path files and metas for each Musics.Clear(); IEnumerable <MusicItem> musicFiles = files.Select(p => new MusicItem() { FileName = p.FileName, Path = p.Path, File = p }); foreach (MusicItem file in musicFiles) { Musics.Add(file); } } }
static void RewriteArtist() { Console.WriteLine("Please enter the directory path to analyze : "); var path = PathUtils.Normalize(Console.ReadLine()); if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) { throw new Exception("Not found path"); } var searchValues = new List <string>() { " featuring. ", " featuring ", " Feat. ", " Feat ", " feat. ", " feat ", " And ", " and ", " ft. ", " vs. ", " ft ", " Ft. ", " Ft ", " & ", " X ", " x ", ", ", }; var files = new MusicFileDaoDetector().Search(new List <string>() { path }); var filesErrors = files.Where(p => searchValues.Any(k => p.Artist.Contains(k))).ToList(); foreach (var file in filesErrors) { Console.Clear(); Console.WriteLine("Choose a proposition OR tap 0 to enter it yourself OR leave empty to continue next :"); Console.WriteLine(""); Console.WriteLine(string.Format("Original : {0} - {1}", file.Artist, file.Title)); // Artist modelize var artist = file.Artist; while (searchValues.Any(p => artist.Contains(p))) { var artistList = new List <string>() { }; foreach (var res in artist.Split("/")) { var found = false; foreach (var search in searchValues) { if (res.Contains(search)) { found = true; artistList.AddRange(res.Split(search)); } } if (!found) { artistList.Add(res); } } artist = artistList.Where(p => !string.IsNullOrEmpty(p)).Select(p => p.Trim()).Distinct().ToString("/", false); } Console.WriteLine(string.Format("Nouveau : {0} - {1}", artist, file.Title)); var choice = Console.ReadLine(); if (string.IsNullOrEmpty(choice)) { continue; } if (choice == "0") { Console.WriteLine("Artist : "); file.Artist = Console.ReadLine(); file.Save(); } if (choice == "1") { file.Artist = artist; file.Save(); } } }