public void Setup() { _mockMp3Node = MockRepository.GenerateStub <Mp3Node>(); _mockMp3Node.AlbumName = SomeAlbumName; _mockMp3Node.ArtistName = SomeArtistName; _mockMp3Node.FileName = SomeFileName; _mockFileManager = MockRepository.GenerateStub <FileManager>(); _mockFileManager.Stub(system => system.GetMp3FilePaths(SomeStartDirectory, true)).Return(new List <string> { SomeFileName }); _mockMp3TagLibrary = MockRepository.GenerateStub <artistAlbumCatalog>(); _mockMp3TagLibrary.Stub(hierarchy => hierarchy.Artists).Return(new List <string> { SomeArtistName }); _mockMp3TagLibrary.Stub(tagsHierarchy => tagsHierarchy.GetAlbumsForArtist(SomeArtistName)).Return( new List <string> { SomeAlbumName }); _mockMp3TagLibrary.Stub( mp3TagsHierarchy => mp3TagsHierarchy.GetSongsForAlbumOfArtist(SomeAlbumName, SomeArtistName)).Return( new List <Mp3Node> { }); _mockMp3FileReader = MockRepository.GenerateStub <Mp3FileReader>(); _mockMp3FileReader.Stub(reader => reader.RetrieveTagsFromMp3Files(new List <string> { SomeFileName })).Return( new List <Mp3Node> { new Mp3Node { AlbumName = SomeAlbumName, ArtistName = SomeArtistName, FileName = SomeFileName } }); _HiveOrganizer = new HiveOrganizer.Mp3LibraryGenerator(SomeStartDirectory, SomeStartDirectory, _mockMp3TagLibrary); ConsoleWriter writer = new ConsoleWriter(); _HiveOrganizer.CreateFoldersForArtists(writer); }
static void Main(string[] args) { ConsoleWriter consoleWriter = new ConsoleWriter(); consoleWriter.WriteLine("Welcome to the Hive MP3 Library Sorter!"); // TagLib.File file = TagLib.File.Create(@"c:\testmp3\01 Egg Raid On Mojo.mp3"); // consoleWriter.WriteLine(file.Tag); //var a = new HiveOrganizer.HiveOrganizer(new fileManager(), @"c:\testmp3", new Mp3TagsHierarchy(), new Mp3FileReader()); //a.CreateFoldersForArtists(); /* END OF ORIGINAL FILE */ // Define some locals List <string> allowed = new List <string>(); allowed.Add(".flac"); allowed.Add(".mp3"); allowed.Add(".m4a"); string startIn = "", destination = ""; bool errors = false; // Print welcome message consoleWriter.WriteLine("This tool indexes your music " + Environment.NewLine + "specified by fileformat. Everything is based on your IDv3 tags. " + Environment.NewLine + "If your tags don't match, the tool will mess up the copying. Be " + Environment.NewLine + "very careful with your indexing scope!"); consoleWriter.WriteLine(Environment.NewLine); // Print allowed formats consoleWriter.WriteLine("Allowed file formats supported are:"); foreach (string format in allowed) { consoleWriter.WriteLine(string.Format(@" - {0}", format)); } consoleWriter.WriteLine(Environment.NewLine); // Display start location folder dialog consoleWriter.WriteLine("Where are your music files? Select the source folder... "); FolderBrowserDialog startInDialog = new FolderBrowserDialog(); startInDialog.Description = "Select the source folder where your music files are located"; startInDialog.ShowNewFolderButton = false; startInDialog.RootFolder = Environment.SpecialFolder.MyComputer; if (startInDialog.ShowDialog() != DialogResult.OK) { consoleWriter.WriteLine("User abort. Exiting..."); Environment.Exit(0); } startIn = startInDialog.SelectedPath; consoleWriter.WriteLine(string.Format(@"The path to your music files is {0}", startIn)); consoleWriter.Write(Environment.NewLine); // Display target location folder dialog consoleWriter.WriteLine("Define a destination for the renamed tracks..."); // windows form dialog to select Folder destination FolderBrowserDialog targetLocationDialog = new FolderBrowserDialog(); targetLocationDialog.Description = "Select the destination folder to copy the files to"; targetLocationDialog.ShowNewFolderButton = true; targetLocationDialog.RootFolder = Environment.SpecialFolder.MyComputer; if (targetLocationDialog.ShowDialog() != DialogResult.OK) { consoleWriter.WriteLine("User abort. Exiting..."); Environment.Exit(0); } destination = targetLocationDialog.SelectedPath; consoleWriter.WriteLine(string.Format(@"Chosen destination path is {0}", destination)); consoleWriter.Write(Environment.NewLine); consoleWriter.WriteLine("Start indexing and organizing procedure. Press S to start, Q to Quit."); System.ConsoleKeyInfo response; do { response = Console.ReadKey(); if (response.Key == ConsoleKey.S) { break; } else if (response.Key == ConsoleKey.Q) { consoleWriter.WriteLine("User abort. Exiting..."); Environment.Exit(0); } } while (true); consoleWriter.Write(Environment.NewLine); consoleWriter.Write(Environment.NewLine); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // Inspect the files and build the Hive metadata library artistAlbumCatalog tagLibrary = new artistAlbumCatalog(); var Hive = new HiveOrganizer.Mp3LibraryGenerator(startIn, destination, tagLibrary); consoleWriter.WriteLine(string.Format("{0} artists found", tagLibrary.Artists.Count)); consoleWriter.WriteLine(divider); foreach (string artist in tagLibrary.Artists) { IList <string> albums = tagLibrary.GetAlbumsForArtist(artist); consoleWriter.WriteLine(divider); consoleWriter.WriteLine("Artist: " + artist + "\tAlbum count: " + albums.Count); IList <HiveOrganizer.Mp3Node> songs; foreach (string album in albums) { songs = tagLibrary.GetSongsForAlbumOfArtist(album, artist); consoleWriter.WriteLine("\tAlbum: " + album + "\tTracks: " + songs.Count); } } consoleWriter.Write(Environment.NewLine); consoleWriter.WriteLine("Press the ENTER key to your library and copy files to their new folder structure."); Console.ReadLine(); try { Hive.CreateFoldersForArtists(consoleWriter); } catch (Exception e) { consoleWriter.WriteLine(e.Message); consoleWriter.WriteLine(e.StackTrace); errors = true; } consoleWriter.Write(Environment.NewLine); stopwatch.Stop(); // Print some nice stats if (!errors) { //consoleWriter.WriteLine(string.Format(@"{0} tracks were renamed and moved to the target location.", organizer.Files.Count)); consoleWriter.WriteLine(string.Format(@"All tracks were indexed and organized in {0}.", stopwatch.Elapsed)); consoleWriter.Write(Environment.NewLine); } // And wait for last user input consoleWriter.WriteLine("Done! Press the ENTER key to complete..."); Console.ReadLine(); }