public void ExecuteCopyNewSongsCommand() { if (NewSongsList.Count == 0) { return; } string outputDir = string.Empty; if (OneDirectoryDroped) { outputDir = OneDirectoryName; } else { outputDir = "MP3_Output"; } foreach (Song song in NewSongsList) { if (ExistingSongs.Count(sng => sng.Artist == song.Artist & sng.Title == song.Title) == 0) { CopyNewSongsToOutputFolder(song, outputDir); Repository.AddSong(song); song.ExistEarlier = true; } } if (Directory.Exists($".\\{outputDir}")) { Process.Start($".\\{outputDir}\\"); } else { MessageBox.Show("Что то пошло не так и не создалась папка для файлов"); } }
private ObservableCollection <Song> CreateListOfSongs(List <string> filesList) { ObservableCollection <Song> songs = new ObservableCollection <Song>(); foreach (var filePath in filesList) { using (var mp3 = new Mp3(filePath)) { Id3Tag tag = null; Id3Tag tag_1x = null; Id3Tag tag_2x = null; try { tag_1x = mp3.GetTag(Id3TagFamily.Version1X); } catch (Exception e) { Logging(e); } try { tag_2x = mp3.GetTag(Id3TagFamily.Version2X); } catch (Exception e) { Logging(e); } if (tag_2x != null) { tag = tag_2x; } else { tag = tag_1x; } if (string.IsNullOrEmpty(tag.Title)) { MessageBox.Show($"Трек {filePath} не содержит в себе название трека в MP3 TAG"); } else { var unixTime = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; //Чтение даты из времени создания файла в папке //var unixTime = (int)(File.GetCreationTimeUtc(filePath) - new DateTime(1970, 1, 1)).TotalSeconds; string artist; if (tag.Artists.Value.Count > 0 && tag.Artists.Value[0].Length < 50) { artist = tag.Artists.Value[0]; } else if (!string.IsNullOrEmpty(tag.Band.Value)) { artist = tag.Band.Value; } else { artist = ""; } Song newSong = new Song(artist, tag.Title, unixTime, filePath); if (ExistingSongs.Count(xx => xx.Title == newSong.Title & xx.Artist == newSong.Artist) > 0) { newSong.ExistEarlier = true; } songs.Add(newSong); } } } return(songs); }