Beispiel #1
0
        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 Recognize_UnrecognizableFile()
        {
            Settings settings = Settings.Instance;

            var data   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas", "test2.mp3");
            var result = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(data);

            Assert.IsNull(result);
        }
        public void Recognize_TrueFile_flac()
        {
            Settings settings = Settings.Instance;

            var data   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas", "subdirectory", "subsubdirectory", "Robin Schulz - In Your Eyes (feat. Alida).flac");
            var result = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(data);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any(p => p.Title.Contains("In Your Eyes")));
            Assert.IsTrue(result.Any(p => p.Artist.Contains("Alida/Robin Schulz")));
            Assert.IsTrue(result.Any(p => p.Album.Contains("In Your Eyes")));
            Assert.IsTrue(result.Any(p => p.Year == 2020));
        }
        public void Recognize_TrueFile_wma()
        {
            Settings settings = Settings.Instance;

            var data   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas", "subdirectory", "Taio Cruz - Break Your Heart.wma");
            var result = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(data);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any(p => p.Title.Contains("Break Your Heart")));
            Assert.IsTrue(result.Any(p => p.Artist.Contains("Taio Cruz")));
            Assert.IsTrue(result.Any(p => p.Album.Contains("Break Your Heart")));
            Assert.IsTrue(result.Any(p => p.Kind.Contains("Pop")));
            Assert.IsTrue(result.Any(p => p.Year == 2009));
        }
        public void Recognize_TrueFile_m4a()
        {
            Settings settings = Settings.Instance;

            var data   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas", "subdirectory", "05 Meet Her At The Loveparade.m4a");
            var result = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(data);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any(p => p.Title.Contains("Meet Her At The Loveparade")));
            Assert.IsTrue(result.Any(p => p.Artist.Contains("Da Hool")));
            Assert.IsTrue(result.Any(p => p.Album.Contains("Meet Her At The Loveparade")));
            Assert.IsTrue(result.Any(p => p.Kind.Contains("Dance")));
            Assert.IsTrue(result.Any(p => p.Year == 2009));
        }
        public void Recognize_TrueFile_wav()
        {
            Settings settings = Settings.Instance;

            var data   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas", "subdirectory", "Tout le monde Danse.wav");
            var result = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(data);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any(p => p.Title.Contains("Tout le monde danse")));
            Assert.IsTrue(result.Any(p => p.Artist.Contains("Fally Ipupa")));
            Assert.IsTrue(result.Any(p => p.Album.Contains("Tout le monde danse")));
            Assert.IsTrue(result.Any(p => p.Kind.Contains("Rap")));
            Assert.IsTrue(result.Any(p => p.Year == 0));
        }
        public void Recognize_TrueFile_mp3()
        {
            Settings settings = Settings.Instance;

            var data   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datas", "test1.mp3");
            var result = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(data);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any(p => p.Title.Contains("I Like It")));
            Assert.IsTrue(result.Any(p => p.Artist.Contains("Enrique Iglesias")));
            Assert.IsTrue(result.Any(p => p.Album.Contains("Jersey Shore")));
            Assert.IsTrue(result.Any(p => p.Kind.Contains("Dance")));
            Assert.IsTrue(result.Any(p => p.Year == 2010));
        }
        /// <summary>
        /// Launch the analyze function for selected files.
        /// </summary>
        private void Analyse()
        {
            // If the analyze process is not running, launch it.
            if (!isAnalyzeRunning)
            {
                int nbMusics = 0;
                foreach (MusicItem music in Musics)
                {
                    if (music.IsChecked)
                    {
                        nbMusics++;
                    }
                }

                if (nbMusics > 0)
                {
                    PercentProgress   = 0;
                    isAnalyzeRunning  = true;
                    AnalyseButtonText = "Arrêter";

                    Task.Factory.StartNew(() =>
                    {
                        double nbAnalysed = 0;

                        foreach (MusicItem music in Musics)
                        {
                            if (!isAnalyzeRunning)
                            {
                                Console.WriteLine("Stop process");
                                break;
                            }

                            if (music.IsChecked)
                            {
                                IEnumerable <MusicDao> results = null;
                                try
                                {
                                    Settings settings = Settings.Instance;
                                    results           = new MusicTagDetector(settings.ApiHost, settings.ApiKey, settings.SecretKey).Recognize(music.Path);
                                }
                                catch
                                {
                                    music.Status = MusicItemStatus.Error;
                                }

                                nbAnalysed++;
                                PercentProgress = nbAnalysed / nbMusics * 100;

                                if (results != null)
                                {
                                    App.Current.Dispatcher.BeginInvoke(() =>
                                    {
                                        music.Results.Clear();

                                        foreach (MusicDao result in results)
                                        {
                                            AnalyzeResult aResult = new AnalyzeResult(result);
                                            aResult.MatchLevel    = LevenshteinDistance.Compute(aResult.Title, SelectedMusic.Title);

                                            music.AddResult(aResult);
                                        }

                                        music.Status = MusicItemStatus.Analysed;

                                        if (AutoSet)
                                        {
                                            music.SetBestResult();
                                        }
                                    });
                                }
                            }
                        }

                        PercentProgress   = 100;
                        isAnalyzeRunning  = false;
                        AnalyseButtonText = "Analyser";
                    });
                }
                else
                {
                    MessageBox.Show("Veuillez cocher au moins une musique.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else // If the analyze process is running, stop it.
            {
                isAnalyzeRunning  = false;
                AnalyseButtonText = "Analyser";
                PercentProgress   = 0;
            }
        }