Ejemplo n.º 1
0
        private static List <SongFileInfo> PraseFileNamesIntoSongList(IEnumerable <string> musicFilePathsList)
        {
            var songList = new List <SongFileInfo>();

            foreach (var filepath in musicFilePathsList)
            {
                string filename         = string.Empty;
                string filenameUpToDash = string.Empty;
                int    dashPosition;
                int    tildePositionPlusOne;
                int    parenPositionMinusOne;
                string title;
                int    lengthOfTitle;
                string artist;

                SongFileInfo song;

                try
                {
                    filename = System.IO.Path.GetFileNameWithoutExtension(filepath);



                    dashPosition     = filename.IndexOf(" - ");
                    filenameUpToDash = filename.Substring(0, dashPosition);

                    if (filename.Contains("~~"))
                    {
                        tildePositionPlusOne = filename.IndexOf("~~") + 2;
                    }
                    else
                    {
                        tildePositionPlusOne = filename.IndexOf("~") + 1;
                    }


                    if (tildePositionPlusOne > 12)
                    {
                    }

                    //no, we don't want the parenPosition if it's after the dash:
                    parenPositionMinusOne = filenameUpToDash.IndexOf("(") - 1;
                    if (parenPositionMinusOne > -1)
                    {
                        title = filename.Substring(tildePositionPlusOne, parenPositionMinusOne - tildePositionPlusOne).Trim();
                    }
                    else
                    {
                        title = filename.Substring(tildePositionPlusOne, dashPosition - tildePositionPlusOne).Trim();
                    }

                    if (filename.Contains("with Diana Ross"))
                    {
                        //sfd
                    }

                    if (filename.Contains("Duncan"))
                    {
                        //sfd
                    }

                    lengthOfTitle = filename.Length - dashPosition;

                    // the 3 below is for this " - " which starts at the dash position
                    artist = filename.Substring(dashPosition + 3, lengthOfTitle - 3).Trim();

                    if (artist.Contains("("))
                    {
                        artist = artist.Substring(0, artist.IndexOf("(")).Trim();
                    }

                    song          = new SongFileInfo();
                    song.FilePath = filepath;
                    song.FileName = filename;
                    song.Title    = title;
                    song.Artist   = artist;

                    try
                    {
                        // https://stackoverflow.com/a/40839588/381082

                        var musicFile = TagLib.File.Create(filepath);
                        var genre     = musicFile.Tag.FirstGenre;
                        song.Genre = genre;
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    songList.Add(song);
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show("File name: " + filename + "     Error:  " + ex.ToString());
                }
            }

            return(songList);
        }
Ejemplo n.º 2
0
        private static int GetNextOccuranceOfArtistIndex(List <SongFileInfo> songListByFileName, int currentIndex, SongFileInfo song)
        {
            //https://stackoverflow.com/a/38822432/381082
            var nextArtistOccuranceIndex = songListByFileName.FindIndex(currentIndex + 1, sng => sng.Artist.ToUpper() == song.Artist.ToUpper());

            return(nextArtistOccuranceIndex + 1);
        }