コード例 #1
0
        public MP3Tag getTag()
        {
            MP3Tag tag = new MP3Tag();

            stream.Seek(stream.Length - 128, SeekOrigin.Begin);
            stream.Read(tagData, 0, SIZE);
            stream.Close();

            byte b1 = tagData[0];
            byte b2 = tagData[1];
            byte b3 = tagData[2];

            if ((char)b1 != 'T' || (char)b2 != 'A' || (char)b3 != 'G')
            {
                throw new Exception("Not an MP3 Format File");
            }

            for (int i = 3; i < 33; i++)
            {
                if (tagData[i] != 0)
                {
                    tag.Title += (char)tagData[i];
                }
            }
            for (int i = 33; i < 63; i++)
            {
                if (tagData[i] != 0)
                {
                    tag.Artist += (char)tagData[i];
                }
            }
            for (int i = 63; i < 93; i++)
            {
                if (tagData[i] != 0)
                {
                    tag.Album += (char)tagData[i];
                }
            }
            for (int i = 93; i < 97; i++)
            {
                if (tagData[i] != 0)
                {
                    tag.Year += (char)tagData[i];
                }
            }
            for (int i = 97; i < 127; i++)
            {
                if (tagData[i] != 0)
                {
                    tag.Comment += (char)tagData[i];
                }
            }
            tag.Genere = tagData[127].ToString();
            Mp3FileReader reader   = new Mp3FileReader(fileName);
            TimeSpan      duration = reader.TotalTime;

            tag.Duration = duration.ToString();
            reader.Close();
            return(tag);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: SarahOuf/MP3-Sorter
        private void button1_Click(object sender, EventArgs e) //button artist
        {
            string    textbox;                                 //textbox with name
            string    type = comboBoxSort.Text.ToString();     //combobox with type of name
            mp3sorter m    = new mp3sorter();                  //m is object from from mp3sorter class

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                mp3s = m.getList();                                          //sorts the music files normally, takes the musicfile and get the tags of it and then puts it and the filename in the mp3s list

                mp3s = mp3s.OrderBy(o => o.tags.Artist.ToString()).ToList(); // o be3mal excess ll hagat eli gowa el mp3s"filename , tags"
                m.writeComment(mp3s);                                        //writecomment fn takes the mp3s list and loops through it to writes the order of the songs in the comment section
                List <MP3Tag> tag = new List <MP3Tag>();
                foreach (mp3files file in mp3s)                              //only tags to show in datagridview
                {
                    tag.Add(file.tags);
                }
                dataGridView1.DataSource = tag;
            }

            else if (!string.IsNullOrEmpty(textBox1.Text))
            {
                textbox = textBox1.Text.ToString();
                mp3s    = m.getSpecificSort(textbox, type); //getSpecificSort checks the textbox and the type sent to it to know what the collection of files to be used(album , year , genre) and puts the final list in mp3s
                // el list el etsft bs msh sorted
                List <string> artist = new List <string>();
                foreach (mp3files file in mp3s)
                {
                    MP3Tag tag = file.tags;
                    artist.Add(tag.Artist);
                }
                bool cond = m.checkCondition(artist);
                if (cond == true)
                {
                    MessageBox.Show("all the songs are by the same artist the sort will be by title");
                    mp3s = mp3s.OrderBy(o => o.tags.Title.ToString()).ToList();
                }
                else if (cond == false)
                {
                    mp3s = mp3s.OrderBy(o => o.tags.Artist.ToString()).ToList();
                }
                m.writeComment(mp3s);
                List <MP3Tag> tag1 = new List <MP3Tag>();
                foreach (mp3files file in mp3s)
                {
                    tag1.Add(file.tags);
                }
                dataGridView1.DataSource = tag1;
            }
            List <string> filename = new List <string>();   //writes the order of the song in the comment section in the file

            foreach (mp3files file in mp3s)
            {
                filename.Add(file.filename);
            }
            m.writeCommentinFile(filename);
            m.copyFiles(filename);
        }
コード例 #3
0
 public List <mp3files> getList()
 {
     foreach (string musicFile in musicFiles)    //musicFiles: array of the files in the folder
     {                                           //mp3files: class that has the filename and tags of each song
         MP3Reader m = new MP3Reader(musicFile); //mp3s: list of type mp3sfiles of the songs in folder
         MP3Tag    c = m.getTag();
         mp3s.Add(new mp3files(musicFile, c));
     }
     return(mp3s);
 }
コード例 #4
0
        public void writeComment(List <mp3files> list)   // function el data gridview
        {
            int i = 0;

            foreach (mp3files file in list)
            {
                MP3Tag t = file.tags;
                t.Comment = i.ToString();
                i++;
            }
        }
コード例 #5
0
 public List <mp3files> getSpecificSort(string textbox, string type)
 {
     if (type == "Artist")
     {
         foreach (string musicFile in musicFiles)
         {
             MP3Reader m = new MP3Reader(musicFile);
             MP3Tag    c = m.getTag();
             if (c.Artist == textbox)
             {
                 mp3s.Add(new mp3files(musicFile, c));
             }
         }
     }
     else if (type == "Album")
     {
         foreach (string musicFile in musicFiles)
         {
             MP3Reader m = new MP3Reader(musicFile);
             MP3Tag    c = m.getTag();
             if (c.Album == textbox)
             {
                 mp3s.Add(new mp3files(musicFile, c));
             }
         }
     }
     else if (type == "Year")
     {
         foreach (string musicFile in musicFiles)
         {
             MP3Reader m = new MP3Reader(musicFile);
             MP3Tag    c = m.getTag();
             if (c.Year == textbox)
             {
                 mp3s.Add(new mp3files(musicFile, c));
             }
         }
     }
     else if (type == "Genre")
     {
         foreach (string musicFile in musicFiles)
         {
             MP3Reader m = new MP3Reader(musicFile);
             MP3Tag    c = m.getTag();
             if (c.Genere == textbox)
             {
                 mp3s.Add(new mp3files(musicFile, c));
             }
         }
     }
     else if (type == "Duration")
     {
         foreach (string musicFile in musicFiles)
         {
             MP3Reader m = new MP3Reader(musicFile);
             MP3Tag    c = m.getTag();
             if (c.Duration == textbox)
             {
                 mp3s.Add(new mp3files(musicFile, c));
             }
         }
     }
     return(mp3s);
 }
コード例 #6
0
 public mp3files(string filename, MP3Tag tags)
 {
     this.filename = filename;   // location
     this.tags     = tags;       //information
 }
コード例 #7
0
ファイル: Form1.cs プロジェクト: SarahOuf/MP3-Sorter
        private void buttonDuration_Click(object sender, EventArgs e)
        {
            string    textbox;
            string    type = comboBoxSort.Text.ToString();
            mp3sorter m    = new mp3sorter();

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                mp3s = m.getList();
                mp3s = mp3s.OrderBy(o => o.tags.Duration.ToString()).ToList();
                m.writeComment(mp3s);
                List <MP3Tag> tag = new List <MP3Tag>();
                foreach (mp3files file in mp3s)
                {
                    tag.Add(file.tags);
                }
                dataGridView1.DataSource = tag;
                List <string> filename = new List <string>();
                foreach (mp3files files in mp3s)
                {
                    filename.Add(files.filename);
                }
                m.writeCommentinFile(filename);
                m.copyFiles(filename);
            }
            else if (!string.IsNullOrEmpty(textBox1.Text))
            {
                textbox = textBox1.Text.ToString();
                mp3s    = m.getSpecificSort(textbox, type);
                List <string> duration = new List <string>();
                foreach (mp3files file in mp3s)
                {
                    MP3Tag tag = file.tags;
                    duration.Add(tag.Duration);
                }
                bool cond = m.checkCondition(duration);
                if (cond == true)
                {
                    MessageBox.Show("all the files are with the same duration the sort will be on the title");
                    mp3s = mp3s.OrderBy(o => o.tags.Title.ToString()).ToList();
                }
                else if (cond == false)
                {
                    mp3s = mp3s.OrderBy(o => o.tags.Duration.ToString()).ToList();
                }
                m.writeComment(mp3s);
                List <MP3Tag> tag1 = new List <MP3Tag>();
                foreach (mp3files file in mp3s)
                {
                    tag1.Add(file.tags);
                }
                dataGridView1.DataSource = tag1;
                List <string> filename = new List <string>();
                foreach (mp3files file in mp3s)
                {
                    filename.Add(file.filename);
                }
                m.writeCommentinFile(filename);
                m.copyFiles(filename);
            }
        }