Пример #1
0
        internal Result <List <MusicFileTag> > LoadMusicFilesFromList(List <string> folderContent)
        {
            var musicFileTags = new List <MusicFileTag>();

            foreach (var file in folderContent)
            {
                try
                {
                    // make sure only *.mp3 files are processed
                    FileInfo info = new FileInfo(file);
                    if (info.Extension != ".mp3")
                    {
                        continue;
                    }

                    var tagInfo = File.Create(file);
                    musicFileTags.Add(MusicFileTag.ConvertTagToMusicFileTag(tagInfo.Tag, tagInfo.Name));
                }
                catch (CorruptFileException e)
                {
                    return(HandleError(file, e));
                }
            }

            return(new Result <List <MusicFileTag> >(musicFileTags, Status.Success));
        }
        private void AddFile()
        {
            string filePath = testMode ?
                              Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"../../../File Examples/file_example_1.mp3")) :
                              GetFilePath_OpenDialog("mp3");

            if (filePath != null && File.Exists(filePath) && !BasicFunctions.FileInUse(filePath))
            {
                // check if File is already in list
                bool FileIsInList = false;
                foreach (MusicFileTag FileInList in MusicFileTags)
                {
                    if (FileInList.FilePath == filePath)
                    {
                        FileIsInList = true;
                        MessageBox.Show("This file is already in the list");
                    }
                }
                if (!FileIsInList)
                {
                    MusicFileTag newFile = TaggingLogic.AddFile(filePath);
                    MusicFileTags.Add(newFile);
                    NumberOfFiles++;
                }
            }
            else
            {
                if (BasicFunctions.FileInUse(filePath))
                {
                    MessageBox.Show("Sorry, this file cannot be opened. " +
                                    "Either it is currently in use or this program does not have the necessary rights to read the file.");
                }
            }
        }
Пример #3
0
        internal Result <List <MusicFileTag> > LoadMusicFilesFromRoot(string root)
        {
            var musicFileTags = new List <MusicFileTag>();
            var foldersList   = new List <string>();

            foldersList.Add(root);
            // add subfolders
            foldersList.AddRange(this.GetSubfolders(root));

            Regex reg = new Regex(@"^((?!\._).)*$");

            foreach (var folder in foldersList)
            {
                var folderContent = Directory.GetFiles(folder, "*.mp3")
                                    .Where(path => reg.IsMatch(path))
                                    .ToList();

                foreach (var file in folderContent)
                {
                    try
                    {
                        var tagInfo = File.Create(file);
                        musicFileTags.Add(MusicFileTag.ConvertTagToMusicFileTag(tagInfo.Tag, tagInfo.Name));
                    }
                    catch (CorruptFileException e)
                    {
                        return(HandleError(file, e));
                    }
                }
            }

            return(new Result <List <MusicFileTag> >(musicFileTags, Status.Success));
        }
 private void Save(MusicFileTag musicFileTag)
 {
         Result result = Logic.SaveTagToFile(musicFileTag);
         if (result.Status == Status.Success)
             SetNotification("Tags saved", "Green");
         else
             SetNotification(result.Message, "Red");
 }
Пример #5
0
        public void SaveTagToFile(MusicFileTag tag)
        {
            if (String.IsNullOrEmpty(tag.FilePath))
            {
                return;
            }

            File tagInfo = MusicFileTag.ConvertMusicFileTagToTag(tag);

            tagInfo.Save();
        }
Пример #6
0
        private void RenameFile(MusicFileTag tag)
        {
            string CurrentFName = System.IO.Path.GetFileNameWithoutExtension(tag.FilePath);

            if (CurrentFName == tag.FileName)
            {
                return;
            }

            FileInfo currentFile = new FileInfo(tag.FilePath);

            currentFile.MoveTo(currentFile.Directory.FullName + "\\" + tag.FileName + currentFile.Extension);
        }
Пример #7
0
        public Result SaveTagToFile(MusicFileTag tag)
        {
            if (String.IsNullOrEmpty(tag.FilePath))
            {
                return(new Result("No FilePath specified", Status.Error));
            }

            File tagInfo = MusicFileTag.ConvertMusicFileTagToTag(tag);

            tagInfo.Save();
            RenameFile(tag);
            return(new Result("", Status.Success));
        }
Пример #8
0
        public static MusicFileTag AddFile(string path)
        {
            if (System.IO.File.Exists(path))
            {
                var tagInfo = File.Create(path);

                TagLib.Id3v1.Tag id3v1Tag = tagInfo.GetTag(TagTypes.Id3v1) as TagLib.Id3v1.Tag;
                TagLib.Id3v2.Tag id3v2Tag = tagInfo.GetTag(TagTypes.Id3v2) as TagLib.Id3v2.Tag;

                return(MusicFileTag.ConvertTagToMusicFileTag(id3v1Tag, id3v2Tag, path));
            }
            else
            {
                MessageBox.Show("Couldn't find:\n" + path);
                return(null);
            }
        }
Пример #9
0
        public ObservableCollection <MusicFileTag> LoadPlaylist(string filePath)
        {
            ObservableCollection <MusicFileTag> NewMusicFileTags = new ObservableCollection <MusicFileTag>();

            Stream fileContentStream = new FileStream(filePath, FileMode.Open);

            M3uContent  content  = new M3uContent();
            M3uPlaylist playlist = content.GetFromStream(fileContentStream);

            List <string> paths = playlist.GetTracksPaths();

            foreach (var file in paths)
            {
                MusicFileTag newMusicFile = AddFile(file);
                if (newMusicFile != null)
                {
                    NewMusicFileTags.Add(newMusicFile);
                }
            }

            return(NewMusicFileTags);
        }
Пример #10
0
        public Result SaveTagsExtractedFromFilename(string pattern, MusicFileTag tag)
        {
            List <string> filenameComponents = tag.FileName.Split('-').Select(x => { return(x.Trim()); }).ToList();
            var           patternComponents  = pattern.Split('-').Select(x => { return(x.Trim()); }).ToList();

            if (pattern.Contains(artist))
            {
                var index = patternComponents.IndexOf(artist);
                tag.Artist = filenameComponents[index];
            }
            if (pattern.Contains(title))
            {
                var index = patternComponents.IndexOf(title);
                tag.Title = filenameComponents[index];
            }
            if (pattern.Contains(year))
            {
                var index = patternComponents.IndexOf(year);
                tag.Year = Convert.ToUInt32(filenameComponents[index]);
            }
            if (pattern.Contains(album))
            {
                var index = patternComponents.IndexOf(album);
                tag.Album = filenameComponents[index];
            }
            if (pattern.Contains(track))
            {
                var index = patternComponents.IndexOf(track);
                tag.Track = Convert.ToUInt32(filenameComponents[index]);
            }
            if (pattern.Contains(genre))
            {
                var index = patternComponents.IndexOf(genre);
                tag.Genre = filenameComponents[index];
            }

            return(SaveTagToFile(tag));
        }
Пример #11
0
 public void SetItemToShow(MusicFileTag fileTag)
 {
     MusicfileTag = fileTag;
 }