Example #1
0
        public static IFileFinder BuildForToFileName(int successful, int failed)
        {
            int numberOfFiles = successful + failed;

            IMP3File[] files = new IMP3File[numberOfFiles];

            for (int i = 0; i < successful; i++)
            {
                var artist = "Artist" + i;
                var title  = "Song" + i;
                files[i] = new MP3FileForTest(artist: artist, title: title);
            }

            for (int i = successful; i < numberOfFiles; i++)
            {
                var artist = "";
                var title  = "";

                if (i % 2 == 0)
                {
                    artist = "Artist" + i;
                }
                else
                {
                    title = "Song" + i;
                }

                files[i] = new MP3FileForTest(artist: artist, title: title);
            }

            return(new FileFinderForTest(files));
        }
Example #2
0
        public bool Rename(IMP3File file)
        {
            var name             = file.Name;
            var indexOfDelimiter = name.IndexOf('-');

            if (indexOfDelimiter == -1)
            {
                return(false);
            }

            var artist = name.Substring(0, indexOfDelimiter).TrimEnd(' ');
            var title  = name.Substring(indexOfDelimiter + 1).TrimStart(' ');

            if (String.IsNullOrEmpty(artist) || String.IsNullOrEmpty(title))
            {
                return(false);
            }

            file.Artist = artist;
            file.Title  = title;

            file.SaveChanges();

            return(true);
        }
Example #3
0
        public void Process(IMP3File mp3File)
        {
            string directory = Path.GetDirectoryName(mp3File.FilePath);
            string newPath   = directory + "\\" + mp3File.Artist + " - " + mp3File.Title + ".mp3";

            mp3File.Move(newPath);
        }
Example #4
0
 public void Process(IMP3File mp3File)
 {
     try
     {
         _logger?.WriteMessage(mp3File.FilePath + " transformation processed", Status.Info);
         _action.Process(mp3File);
         _logger?.WriteMessage(mp3File.FilePath + " transformation complete", Status.Info);
     }
     catch (Exception e)
     {
         _logger?.WriteMessage(e.Message, Status.Error);
         throw;
     }
 }
Example #5
0
        public bool Rename(IMP3File file)
        {
            var artist = file.Artist;
            var title  = file.Title;

            if (String.IsNullOrEmpty(artist) || String.IsNullOrEmpty(title))
            {
                return(false);
            }

            var newName = artist + " - " + title;

            file.Name = newName;

            file.SaveChanges();

            return(true);
        }
Example #6
0
        public static IFileFinder BuildForToTag(int successful, int failed)
        {
            int numberOfFiles = successful + failed;

            IMP3File[] files = new IMP3File[numberOfFiles];

            for (int i = 0; i < successful; i++)
            {
                var name = String.Format("Artist{0} - Song{0}", i);
                files[i] = new MP3FileForTest(name: name);
            }

            for (int i = successful; i < numberOfFiles; i++)
            {
                files[i] = new MP3FileForTest(name: "IncorrectName");
            }

            return(new FileFinderForTest(files));
        }
Example #7
0
        public void Process(IMP3File mp3File)
        {
            string fileName = Path.GetFileNameWithoutExtension(mp3File.FilePath);

            if (fileName == null)
            {
                throw new IOException("MP3 file should have a name");
            }

            string[] fileParts = fileName.Split(new string[] { " - ", "." }, StringSplitOptions.RemoveEmptyEntries);
            if (fileParts.Length < 2)
            {
                throw new IOException("File name does not contain enough information");
            }
            if (fileParts.Length > 2)
            {
                throw new IOException("File name contains extra information");
            }

            mp3File.Artist = fileParts[0];
            mp3File.Title  = fileParts[1];
            mp3File.Save();
        }
Example #8
0
 public void AddFile(string name, IMP3File file) => Files.Add(name, file);