Example #1
0
        public void AddFile(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            if (MusicController.MusicTracks.Any(item => item.Path == path) == true)
            {
                return;
            }

            ShellObject shellFile = ShellObject.FromParsingName(path);

            string[] creators     = PropertyHandler.GetValues(shellFile.Properties.GetProperty(SystemProperties.System.Music.Artist));
            string   songName     = PropertyHandler.GetValue(shellFile.Properties.GetProperty(SystemProperties.System.Title));
            string   albumName    = PropertyHandler.GetValue(shellFile.Properties.GetProperty(SystemProperties.System.Music.AlbumTitle));
            uint?    trackYear    = PropertyHandler.GetNumber(shellFile.Properties.GetProperty(SystemProperties.System.Media.Year));
            TimeSpan songDuration = PropertyHandler.GetDuration(shellFile.Properties.GetProperty(SystemProperties.System.Media.Duration));


            if (string.IsNullOrEmpty(songName))
            {
                int    pos    = path.LastIndexOf("\\") + 1;
                string result = new string(path.Skip(pos).ToArray());

                songName = result.Replace(System.IO.Path.GetExtension(result), "");
            }

            string finalCreator;

            if (creators != null)
            {
                StringBuilder builder = new StringBuilder();

                foreach (string creatorName in creators)
                {
                    builder.Append($"{creatorName}, ");
                }

                builder.Remove(builder.Length - 2, 1);
                finalCreator = builder.ToString();
            }

            else
            {
                finalCreator = null;
            }


            MusicController.MusicTracks.Add(new MusicTrack(MusicController.MusicTracks.Count, finalCreator, songName, path, songDuration, albumName, trackYear, System.IO.Path.GetExtension(path)));
        }