Example #1
0
        public void SaveArtists()
        {
            FileInfo[]  musicFiles   = null;
            TagLib.File tagMusicFile = null;
            //string album = "";
            List <string> artists = new List <string>();

            //  DirectoryProcess dProcess = new DirectoryProcess();
            List <DirectoryInfo> dirList = new DirectoryProcess().GetDirectories();

            //Iterate parent directory and all its sub directories.
            foreach (DirectoryInfo dir in dirList)
            {
                //Get music files from the this directory.
                musicFiles = dir.GetFiles(GlobalUserConfig.FileType);

                //Iterate music files.
                foreach (FileInfo musicFile in musicFiles)
                {
                    try
                    {
                        //Create tag music file from music file.
                        tagMusicFile = TagLib.File.Create(musicFile.FullName);

                        artists = GetArtist(tagMusicFile);
                    }
                    catch (Exception errMsg)
                    {
                        throw errMsg;
                    }
                }
            }
        }
        public void process()
        {
            List <DirectoryInfo> lstDirectory = new DirectoryProcess().GetDirectories();
            DirectoryProcess     dirProcess   = new DirectoryProcess();

            foreach (DirectoryInfo dir in lstDirectory)
            {
                FileInfo[] flist     = dir.GetFiles(GlobalUserConfig.SearchPattern); // "*.MP3");
                bool       isValid   = false;
                string     albumName = "";
                foreach (FileInfo finfo in flist)
                {
                    isValid   = false;
                    albumName = "";
                    try
                    {
                        TagLib.File tagFile = TagLib.File.Create(finfo.FullName);

                        if (tagFile.Tag != null)
                        {
                            isValid   = IsValidAlbumName(tagFile);
                            albumName = tagFile.Tag.Album.Trim();
                            if (!IsFolderExist(albumName))
                            {
                                System.IO.Directory.CreateDirectory(@"E:\Songs\Managed Music Folder\" + albumName);
                            }
                        }
                    }
                    catch (Exception errmsg)
                    {
                        throw errmsg;
                    }
                }
            }
        }
Example #3
0
        private void btnFolderName_Click(object sender, EventArgs e)
        {
            GlobalUserConfig config = new GlobalUserConfig();

            GlobalUserConfig.ParentFolderPath = txtPath.Text.Trim();

            List <DirectoryInfo> dir        = null;
            DirectoryProcess     dirProcess = new DirectoryProcess();

            dir = dirProcess.GetDirectories();

            List <string> fName = new List <string>();

            StringBuilder strBuilder = new StringBuilder();

            foreach (var folderName in dir)
            {
                strBuilder.Append("insert into MusicBand (FolderName) values ('");
                strBuilder.Append(folderName.Name.Trim());
                strBuilder.Append("');");
                strBuilder.AppendLine("");
            }
            txtMusicFolderName.Text = strBuilder.ToString();
            //listBox1.DataSource = fName;
        }
Example #4
0
        /// <summary>
        /// From music file extract album,artist, band.
        /// </summary>
        public void Process()
        {
            FileInfo[]  musicFiles   = null;
            TagLib.File tagMusicFile = null;
            //string album = "";
            List <string> artists = new List <string>();

            //  DirectoryProcess dProcess = new DirectoryProcess();
            List <DirectoryInfo> dirList = new DirectoryProcess().GetDirectories();

            MusicArtist artist = new MusicArtist();

            this.listOfMusicFileTagTempData = new List <TemplateMusicFileTag>();

            IterateDirectory(dirList);

            ////Iterate parent directory and all its sub directories.
            //foreach (DirectoryInfo dir in dirList)
            //{
            //    //Get music files from the this directory.
            //    musicFiles = dir.GetFiles(GlobalUserConfig.FileType);

            //    //Iterate music files.
            //    foreach (FileInfo musicFile in musicFiles)
            //    {
            //        try
            //        {
            //            //Create tag music file from music file.
            //            tagMusicFile = TagLib.File.Create(musicFile.FullName);

            //            artists = artist.GetArtist(tagMusicFile);


            //            foreach (string val in artists)
            //            {
            //                if (!this.artistsTagValue.Contains(val))
            //                {
            //                    if(!IsAlreadyExistsInDB(val.Trim()))
            //                    {
            //                    this.artistsTagValue.Add(val.Trim());

            //                    this.listOfMusicFileTagTempData.Add(
            //                        new TemplateMusicFileTag() { ArtistTagVale = val.Trim(), IsAlbum = false, IsArtist = false, IsBand = false });
            //                    }
            //                }
            //            }

            //        }
            //        catch (Exception errMsg)
            //        {
            //            throw errMsg;
            //        }
            //    }

            //}
        }
Example #5
0
        public void Process()
        {
            List <DirectoryInfo> lstDirectory = new DirectoryProcess().GetDirectories();
            DirectoryProcess     dirProcess   = new DirectoryProcess();

            foreach (DirectoryInfo dir in lstDirectory)
            {
                FileInfo[] flist = dir.GetFiles("*.MP3");

                foreach (FileInfo finfo in flist)
                {
                    try
                    {
                        TagLib.File tagFile = TagLib.File.Create(finfo.FullName);

                        int    firstIndex = finfo.Name.IndexOf('_');
                        string result     = finfo.Name.Substring(0, firstIndex);
                        int    value      = 0;
                        Int32.TryParse(result, out value);

                        string newName = "";
                        //if value is > 0 then, first letter in file name has integer value. so remove it.
                        if (value > 0)
                        {
                            try
                            {
                                newName = RemoveDownHyphenFromBeginingOfName(-1, finfo.Name);

                                //  newName = finfo.Name.Remove(0, firstIndex + 1);

                                if (!string.IsNullOrEmpty(newName))
                                {
                                    System.IO.File.Move(@"E:\Songs\ToProcess\" + finfo.Name, @"E:\Songs\Processed\" + newName + ".mp3");
                                }
                            }
                            catch (Exception errmsg)
                            {
                                if (errmsg.Message.Trim() == "Cannot create a file when that file already exists.")
                                {
                                    System.IO.File.Move(@"E:\Songs\ToProcess\" + finfo.Name, @"E:\Songs\ProcessDelete\" + newName + ".mp3"); //"ProcessDelete","");
                                }
                                string errMesg = errmsg.Message;
                            }
                        }
                    }
                    catch (CorruptFileException errmsg)
                    {
                        throw errmsg;
                    }
                }
            }
        }
Example #6
0
        public void Process()
        {
            List <DirectoryInfo> lstDirectory = new DirectoryProcess().GetDirectories();
            DirectoryProcess     dirProcess   = new DirectoryProcess();

            foreach (DirectoryInfo dir in lstDirectory)
            {
                FileInfo[] flist = dir.GetFiles(GlobalUserConfig.SearchPattern);   // "*.MP3");

                foreach (FileInfo finfo in flist)
                {
                }
            }
        }
Example #7
0
        public void Process(FileInfo musicFile)
        {
            DirectoryProcess dirProcess = new DirectoryProcess();

            string currentFilePathAndName = "";
            string musicFileName          = "";
            string artistName             = "";

            TagLib.File tagMusicFile = null;
            tagMusicFile = TagLib.File.Create(musicFile.FullName);
            string artistFolderPath = "";

            musicFileName          = musicFile.Name.Trim();
            currentFilePathAndName = musicFile.FullName.Trim();

            List <string> artists = GlobalUserConfig.GetArtist(tagMusicFile);

            foreach (string val in artists)
            {
                if (IsValidArtist(val.Trim()))
                {
                    artistName = string.IsNullOrEmpty(artistName) ? val.Trim()
                       : artistName + " & " + val;
                }

                //Create folder.
                if (!dirProcess.HasFolderExists(GlobalUserConfig.MusicFilesFolder + artistName))
                {
                    System.IO.Directory.CreateDirectory(GlobalUserConfig.MusicFilesFolder + artistName);
                }

                artistFolderPath = GlobalUserConfig.MusicFilesFolder + artistName + "\\";

                //move music files to folder.
                //check file exists.
                if (!File.Exists(artistFolderPath + musicFileName))
                {
                    System.IO.File.Move(currentFilePathAndName, artistFolderPath + musicFileName);
                }
            }
        }
Example #8
0
        // TruncateMaster truncateMaster = new TruncateMaster();
        public void Process()
        {
            List <DirectoryInfo> lstDirectory = new DirectoryProcess().GetDirectories();
            DirectoryProcess     dirProcess   = new DirectoryProcess();

            foreach (DirectoryInfo dir in lstDirectory)
            {
                FileInfo[] flist = dir.GetFiles("*.mp3");
                foreach (FileInfo finfo in flist)
                {
                    try
                    {
                        //TagLib.File tagFile = TagLib.File.Create(finfo.FullName);

                        //check numeric value at begining of filename.
                        String tmp = finfo.Name.Substring(1, 1);

                        String symbolValue = StretchedMethod.GetFirstCharacter("");// truncateMaster.GetSymbolValue(TruncateMaster.Symbols.UnderscoreHyphen);
                        if (String.Equals(tmp, symbolValue))
                        {
                            String newName = "";
                            newName = finfo.Name.Substring(1, finfo.Name.Length - 1);
                            System.IO.File.Move(finfo.Name, newName);
                        }
                        else if (String.Equals(tmp, symbolValue))
                        {
                            String newName = "";
                            newName = finfo.Name.Substring(1, finfo.Name.Length - 1);
                            System.IO.File.Move(finfo.Name, newName);
                        }
                    }
                    catch (CorruptFileException errmsg)
                    {
                        throw errmsg;
                    }
                }
            }
        }
Example #9
0
        public void Process()
        {
            DirectoryProcess     dProcess = new DirectoryProcess();
            List <DirectoryInfo> dirList  = dProcess.GetDirectories();

            FileInfo[]  musicFiles   = null;
            TagLib.File tagMusicFile = null;

            Simile.Algorithm.AlgorithmFactory algFactory = new Algorithm.AlgorithmFactory();

            string musicTitle    = "";
            string musicFileName = "";

            foreach (DirectoryInfo dir in dirList)
            {
                musicFiles = dir.GetFiles(GlobalUserConfig.FileType);


                foreach (FileInfo finfo in musicFiles)
                {
                    try
                    {
                        FileInfo musicFile = finfo;
                        tagMusicFile  = TagLib.File.Create(musicFile.FullName);
                        musicFileName = musicFile.Name.Trim(); // tagMusicFile.Name.Trim();

                        //if tag is null then avoid the file and get next file.
                        if (tagMusicFile.Tag == null)
                        {
                            continue;
                        }

                        //from music file name remove file extention.
                        musicFileName = algFactory.GetFileNameRemovingFileExtention(musicFileName);

                        var songName = (!string.IsNullOrEmpty(tagMusicFile.Tag.Title)) ? tagMusicFile.Tag.Title.Trim() : musicFileName;

                        if (!string.IsNullOrEmpty(songName)) //tagMusicFile.Tag.Title))
                        {
                            //if title has prefix number then remove it.
                            tagMusicFile.Tag.Title = algFactory.GetPrefixNumberRemoveTitle(songName); //tagMusicFile.Tag.Title.Trim());

                            ////if title has prefix artist or band name then remove it.
                            tagMusicFile = algFactory.RemovePrefixArtistOrBandFromTitle(tagMusicFile);
                        }

                        //if there is no title, then assign file name to title.
                        if (string.IsNullOrEmpty(tagMusicFile.Tag.Title))
                        {
                            tagMusicFile.Tag.Title = algFactory.GetMusicTitle(musicFile, tagMusicFile);
                            tagMusicFile.Save();
                        }

                        #region obsolete
                        ////assign title to file name.
                        // musicFile = algFactory.TitleToFileName(musicFile);
                        // tagMusicFile = TagLib.File.Create(musicFile.FullName);
                        // musicFileName = musicFile.Name.Trim();
                        // //from music file name remove file extention.
                        // musicFileName = algFactory.GetFileNameRemovingFileExtention(musicFileName);

                        //if artist included in file name then remove artist, and keep music title as file name.



                        //Create folder for artist and move files.
                        algFactory.CreateArtistFolderAndMoveFile(musicFile);
                        #endregion
                    }
                    catch (Exception errMsg)
                    {
                        throw errMsg;
                    }
                }
            }
        }
Example #10
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            DistilTitle  distilTitle  = new DistilTitle();
            TitleExtract titleExtract = new TitleExtract();

            GlobalUserConfig config = new GlobalUserConfig();

            GlobalUserConfig.ParentFolderPath = txtPath.Text.Trim();
            DirectoryProcess     dProcess = new DirectoryProcess();
            List <DirectoryInfo> dirList  = dProcess.GetDirectories();

            FileInfo[]  musicFiles   = null;
            TagLib.File tagMusicFile = null;

            Simile.Algorithm.AlgorithmFactory algFactory = new Algorithm.AlgorithmFactory();

            //string newTitle = "";
            // string artistOrBandName = "";
            //  Simile.SimileEnums.GroupCategory grpCategory = SimileEnums.GroupCategory.Unknown;
            Simile.DBProcess.MusicBand   musicBand   = new Simile.DBProcess.MusicBand();
            Simile.DBProcess.MusicArtist musicArtist = new Simile.DBProcess.MusicArtist();

            List <MusicFileViewModel> listMusicFileViewModel = new List <MusicFileViewModel>();
            MusicFileViewModel        musicFileViewModel     = null;

            List <clsErrorRpt> errorRpts = new List <clsErrorRpt>();
            clsErrorRpt        errR      = null;

            foreach (DirectoryInfo dir in dirList)
            {
                musicFiles = dir.GetFiles(GlobalUserConfig.FileType);



                foreach (FileInfo finfo in musicFiles)
                {
                    try
                    {
                        FileInfo musicFile = finfo;

                        //
                        errR          = new clsErrorRpt();
                        errR.FileName = musicFile.Name;
                        errR.Path     = musicFile.FullName;

                        //

                        tagMusicFile = TagLib.File.Create(musicFile.FullName);

                        //if tag is null then avoid the file and get next file.
                        if (tagMusicFile.Tag == null)
                        {
                            continue;
                        }



                        musicFileViewModel          = new MusicFileViewModel();
                        musicFileViewModel.Title    = tagMusicFile.Tag.Title.Trim(); // newTitle.Trim();
                        musicFileViewModel.FileName = musicFile.Name.Trim();
                        musicFileViewModel.Path     = musicFile.DirectoryName.Trim();

                        var artistName = "";
                        var bandName   = "";


                        //----------------------------
                        if (tagMusicFile.Tag.AlbumArtists != null && tagMusicFile.Tag.AlbumArtists.Count() > 0)
                        {
                            string tmpAlbArtists = "";
                            var    test          = tagMusicFile.Tag.AlbumArtists;
                            foreach (var val in test)
                            {
                                tmpAlbArtists += val.Trim();
                            }

                            if (!string.IsNullOrEmpty(tmpAlbArtists))
                            {
                                using (var modelContext = new MusicPlayEntities3())
                                {
                                    Simile.MusicArtist tmpArtist = modelContext.MusicArtists.Where(r => r.ArtistName.ToUpper() == tmpAlbArtists.ToUpper()).FirstOrDefault();
                                    if (tmpArtist != null)
                                    {
                                        musicFileViewModel.Artist   = tmpArtist.ArtistName.Trim();
                                        musicFileViewModel.ArtistId = tmpArtist.Id;
                                    }
                                }

                                using (var modelContext = new MusicPlayEntities3())
                                {
                                    Simile.MusicBand tmpBand = modelContext.MusicBands.Where(r => r.BandName.ToUpper() == tmpAlbArtists.ToUpper()).FirstOrDefault();
                                    if (tmpBand != null)
                                    {
                                        musicFileViewModel.Band   = tmpBand.BandName.Trim();
                                        musicFileViewModel.BandId = tmpBand.Id;
                                    }
                                }
                            }
                        }


                        //-----------------------------



                        //////////////////



                        if (musicFileViewModel.BandId == 0)
                        {
                            var tmpBandName = musicFile.Directory.Name.Trim();

                            using (var modelContext = new MusicPlayEntities3())
                            {
                                Simile.MusicBand tmpBand = modelContext.MusicBands.Where(r => r.BandName.ToUpper() == tmpBandName.ToUpper()).FirstOrDefault();
                                if (tmpBand != null)
                                {
                                    musicFileViewModel.Band   = tmpBand.BandName.Trim();
                                    musicFileViewModel.BandId = tmpBand.Id;
                                }
                            }
                        }

                        if (musicFileViewModel.ArtistId == 0)
                        {
                            var tmpArtistName = musicFile.Directory.Name.Trim();
                            using (var modelContext = new MusicPlayEntities3())
                            {
                                Simile.MusicArtist tmpArtist = modelContext.MusicArtists.Where(r => r.ArtistName.ToUpper() == tmpArtistName.ToUpper()).FirstOrDefault();
                                if (tmpArtist != null)
                                {
                                    musicFileViewModel.Artist   = tmpArtist.ArtistName.Trim();
                                    musicFileViewModel.ArtistId = tmpArtist.Id;
                                }
                            }
                        }

                        ////////////////////

                        if (!string.IsNullOrEmpty(tagMusicFile.Tag.Comment))
                        {
                            var splitComments = tagMusicFile.Tag.Comment.Split(';');

                            foreach (var val in splitComments)
                            {
                                var childSplit = val.ToString().Split('=');
                                if (childSplit.Length == 2)
                                {
                                    if (childSplit[0].Trim() == "Artist")
                                    {
                                        artistName = childSplit[1].Trim();
                                    }

                                    if (childSplit[0].Trim() == "Band")
                                    {
                                        bandName = childSplit[1].Trim();
                                    }
                                }
                            }
                        }

                        if (musicFileViewModel.BandId == 0 && !string.IsNullOrEmpty(bandName))
                        {
                            using (var modelContext = new MusicPlayEntities3())
                            {
                                Simile.MusicBand tmpBand = modelContext.MusicBands.Where(r => r.BandName.ToUpper() == bandName.ToUpper()).FirstOrDefault();
                                musicFileViewModel.Band   = tmpBand.BandName.Trim();
                                musicFileViewModel.BandId = tmpBand.Id;
                            }
                        }

                        if (musicFileViewModel.ArtistId == 0 && !string.IsNullOrEmpty(artistName))
                        {
                            using (var modelContext = new MusicPlayEntities3())
                            {
                                Simile.MusicArtist tmpArtist = modelContext.MusicArtists.Where(r => r.ArtistName.ToUpper() == artistName.ToUpper()).FirstOrDefault();
                                musicFileViewModel.Artist   = tmpArtist.ArtistName.Trim();
                                musicFileViewModel.ArtistId = tmpArtist.Id;
                            }
                        }



                        listMusicFileViewModel.Add(musicFileViewModel);
                    }
                    catch (Exception errMsg)
                    {
                        errR.Error = errMsg.Message;
                        errorRpts.Add(errR);
                        MessageBox.Show(errMsg.Message);
                    }
                } // end of for loop
            }     //end of dir for loop

            dgvMusicFiles.DataSource = listMusicFileViewModel;
        }
Example #11
0
        public void Process()
        {
            List <DirectoryInfo> lstDirectory = new DirectoryProcess().GetDirectories();
            DirectoryProcess     dirProcess   = new DirectoryProcess();

            foreach (DirectoryInfo dir in lstDirectory)
            {
                FileInfo[] flist = dir.GetFiles(GlobalUserConfig.SearchPattern); // "*.MP3");

                foreach (FileInfo finfo in flist)
                {
                    try
                    {
                        TagLib.File tagFile = TagLib.File.Create(finfo.FullName);
                        if (tagFile.Tag != null && !string.IsNullOrEmpty(tagFile.Tag.Title) &&
                            !string.IsNullOrEmpty(tagFile.Tag.Title.Trim()) && !tagFile.Tag.Title.Equals(finfo.Name))
                        {
                            bool bOk = !tagFile.Tag.Title.ToUpper().Contains("TRACK");                 // ? true : false;//.Contains("track"));

                            bOk = bOk == true && !tagFile.Tag.Title.ToUpper().Contains("AUDIO TRACK"); //  ? true : false;//.Contains("track"));

                            if (bOk)
                            {
                                String newName = "";  string album = "";  string[] artist;
                                album = tagFile.Tag.Album;  artist = tagFile.Tag.AlbumArtists.ToArray();  newName = tagFile.Tag.Title.Trim();
                                string[] contriArtist;    contriArtist = tagFile.Tag.Artists.ToArray();
                                try //AudioTrack 15
                                {
                                    //if (IsFileNameAlbumInAlbum(finfo) == true)
                                    //{
                                    //    System.IO.File.Move(@"E:\Songs\Sibby\New order - The best of\" + finfo.Name, @"E:\Songs\Sibby\New order - The best of\" + newName + ".mp3");
                                    //}
                                    //else
                                    {
                                        newName = TitleToFileNameRemovingAlbumName(tagFile).ToString();
                                        if (!string.IsNullOrEmpty(newName))
                                        {
                                            System.IO.File.Move(@"E:\Songs\1Refactored Songs\SIBBY\80s Compilation CDs\80s Compilation CD 1\New folder\" + finfo.Name,
                                                                @"E:\Songs\1Refactored Songs\SIBBY\80s Compilation CDs\80s Compilation CD 1\New folder\" + newName + ".mp3");

                                            //tagFile.Tag.Title = newName;
                                            //tagFile.Save();
                                        }
                                    }
                                }
                                catch (Exception errmsg)
                                {
                                    if (errmsg.Message.Trim() == "Cannot create a file when that file already exists.")
                                    {
                                        //  System.IO.File.Move(@"E:\Songs\Sibby\The_Righteous_Brothers-Unchained_Melody-(Retail)-1990-HHI\" + finfo.Name, @"E:\Songs\ProcessDelete\" + newName + ".mp3");//"ProcessDelete","");
                                    }
                                    string errMesg = errmsg.Message;
                                }
                            }
                        }
                    }
                    catch (CorruptFileException errmsg)
                    {
                        throw errmsg;
                    }
                }
            }
        }