Beispiel #1
0
        private void SaveMp3IdInfo()
        {
            ID3Info id3 = new ID3Info(ddtbMp3File.ItemText, true);


            try
            {
                id3.ID3v1Info.TrackNumber = BCHUtilities.IsNumeric(tbTrack3v1.Text) ? byte.Parse(tbTrack3v1.Text) : byte.Parse("1");
                id3.ID3v1Info.Title       = tbTitle3v1.Text;
                id3.ID3v1Info.Artist      = tbArtist3v1.Text;
                id3.ID3v1Info.Album       = tbAlbum3v1.Text;
                id3.ID3v1Info.Year        = tbYear3v1.Text;
                id3.ID3v1Info.Comment     = tbComment3v1.Text;
                id3.ID3v1Info.Genre       = Convert.ToByte(cbGenre3v1.GenreIndex);


                id3.ID3v2Info.SetTextFrame("TRCK", tbTrack3v2.Text);
                id3.ID3v2Info.SetTextFrame("TIT2", tbTitle3v2.Text);
                id3.ID3v2Info.SetTextFrame("TPE1", tbArtist3v2.Text);
                id3.ID3v2Info.SetTextFrame("TALB", tbAlbum3v2.Text);
                id3.ID3v2Info.SetTextFrame("TYER", tbYear3v2.Text);
                id3.ID3v2Info.SetTextFrame("WCOM", tbComment3v2.Text);
                id3.ID3v2Info.SetTextFrame("TCON", cbGenre3v2.Genre);

                id3.ID3v2Info.HaveTag = true;
                id3.ID3v1Info.HaveTag = true;

                id3.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void _currentMenu_Click(object sender, EventArgs e)
        {
            #region 界面归零
            module.MainListBox.Items.Clear();
            module.MusicPathList.Clear();
            module.MainProgressBar.Maximum = 0;
            module.MainProgressBar.Value   = 0;
            #endregion

            FolderBrowserDialog _fd = new FolderBrowserDialog();
            _fd.Description = "请选择歌曲与歌词所在的文件夹";
            _fd.ShowDialog();
            string[] files = null;

            if (_fd.SelectedPath != "")
            {
                files = Directory.GetFiles(_fd.SelectedPath, "*.mp3", SearchOption.AllDirectories);
                foreach (var item in files)
                {
                    module.MainListBox.Items.Add(new ListViewItem(new string[] { item, "" }));
                }
                // 写入
                module.MainProgressBar.Maximum = files.Length;
                int _count = 0;
                module.MainStatusStrip.Text = "开始写入LRC歌词文件...";
                foreach (var item in files)
                {
                    var _str = Path.GetDirectoryName(item) + @"\" + Path.GetFileNameWithoutExtension(item) + ".lrc";
                    if (File.Exists(_str))
                    {
                        var _fr   = new FileStream(_str, FileMode.Open);
                        var _sr   = new StreamReader(_fr);
                        var _text = _sr.ReadToEnd();
                        try
                        {
                            // 写入ID3标签
                            ID3Info info = new ID3Info(item, true);
                            info.ID3v2Info.SetTextFrame("TEXT", _text);
                            info.Save();
                            module.MainListBox.Items[_count].SubItems[1].Text = "成功";
                        }
                        catch
                        {
                            module.MainListBox.Items[_count].SubItems[1].Text = "失败";
                        }
                        _sr.Close();
                        _fr.Close();
                    }
                    else
                    {
                        module.MainListBox.Items[_count].SubItems[1].Text = "不存在LRC";
                    }

                    _count++;
                    module.MainProgressBar.Value++;
                }
                module.MainStatusStrip.Text = "歌词写入完成!";
            }
        }
Beispiel #3
0
        private void ExecCodeProj(string fileName)
        {
            ID3Info id3Info = new ID3Info(fileName, true);

            id3Info.Load();
            textBox1.Text = id3Info.ID3v2Info.GetTextFrame("TIT2") + ";" + id3Info.ID3v1Info.Title;

            id3Info.ID3v2Info.SetTextFrame("TIT2", id3Info.ID3v1Info.Title.Trim());
            id3Info.ID3v1Info.Title = id3Info.ID3v1Info.Title.Trim() + "";
            id3Info.Save();

            textBox2.Text = id3Info.ID3v2Info.GetTextFrame("TIT2") + ";" + id3Info.ID3v1Info.Title;
        }
Beispiel #4
0
        public static void RewriteMP3Tags(DownloadItem item)
        {
            string localFileName = item.Filename;

            if (File.Exists(localFileName))
            {
                try
                {
                    ID3Info id3Info   = new ID3Info(localFileName, true);
                    string  strTitle  = id3Info.ID3v2Info.GetTextFrame("TIT2");
                    string  strGenre  = id3Info.ID3v2Info.GetTextFrame("TCON");
                    string  strArtist = id3Info.ID3v2Info.GetTextFrame("TPE1");
                    string  strAlbum  = id3Info.ID3v2Info.GetTextFrame("TALB");
                    if (item.TagTitle != null && item.TagTitle != "")
                    {
                        strTitle = ParseMediaTags(item.TagTitle, item, id3Info);
                    }
                    if (item.TagGenre != null && item.TagGenre != "")
                    {
                        strGenre = ParseMediaTags(item.TagGenre, item, id3Info);
                    }
                    if (item.TagArtist != null && item.TagArtist != "")
                    {
                        strArtist = ParseMediaTags(item.TagArtist, item, id3Info);
                    }
                    if (item.TagAlbum != null && item.TagAlbum != "")
                    {
                        strAlbum = ParseMediaTags(item.TagAlbum, item, id3Info);
                    }
                    id3Info.ID3v2Info.HaveTag = true;
                    id3Info.ID3v2Info.SetMinorVersion(3);

                    id3Info.ID3v2Info.SetTextFrame("TIT2", strTitle);
                    id3Info.ID3v2Info.SetTextFrame("TCON", strGenre);
                    id3Info.ID3v2Info.SetTextFrame("TPE1", strArtist);
                    id3Info.ID3v2Info.SetTextFrame("TALB", strAlbum);
                    id3Info.Save();
                }
                catch (Exception ex)
                {
                    if (Settings.Default.LogLevel > 0)
                    {
                        log.Error(ex);
                    }
                }
            }
        }
        private void SaveMp3IdInfo(MP3FileDataType mp3, ref OperationResult op)
        {
            try
            {
                ID3Info id3 = new ID3Info(mp3.FileNamePath, true);

                string track = mp3.Track != null?mp3.Track.ToString() : "1";

                string        title     = !string.IsNullOrEmpty(mp3.SongTitleAndNumeration) ? GetMaxLen(mp3.SongTitleAndNumeration, 30) : string.Empty;
                string        artists   = !string.IsNullOrEmpty(mp3.ArtistsStrList) ? GetMaxLen(mp3.ArtistsStrList, 30) : string.Empty;
                string        album     = !string.IsNullOrEmpty(mp3.Album) ? GetMaxLen(mp3.Album, 30) : string.Empty;
                string        comments  = !string.IsNullOrEmpty(mp3.Comments) ? GetMaxLen(mp3.Comments, 28) : string.Empty;
                List <string> GenreList = BCHMP3Utilities.GetGenre();
                int           genreIndx = GenreList.Contains(mp3.Genre, StringComparer.CurrentCultureIgnoreCase)
                                    ?
                                          GenreList.FindIndex(
                    s =>
                    s.Trim().Equals(mp3.Genre.Trim(), StringComparison.CurrentCultureIgnoreCase))
                                    :
                                          GenreList.FindIndex(
                    s =>
                    s.Trim().Equals("Other", StringComparison.CurrentCultureIgnoreCase));

                id3.ID3v1Info.TrackNumber = byte.Parse(track);
                id3.ID3v1Info.Title       = title;
                id3.ID3v1Info.Artist      = artists;
                id3.ID3v1Info.Album       = album;
                id3.ID3v1Info.Comment     = comments;
                id3.ID3v1Info.Genre       = Convert.ToByte(genreIndx);


                id3.ID3v2Info.SetTextFrame("TRCK", track);
                id3.ID3v2Info.SetTextFrame("TIT2", title);
                id3.ID3v2Info.SetTextFrame("TPE1", artists);
                id3.ID3v2Info.SetTextFrame("TALB", album);
                id3.ID3v2Info.SetTextFrame("WCOM", comments);
                id3.ID3v2Info.SetTextFrame("TCON", GenreList[genreIndx]);

                id3.ID3v2Info.HaveTag = true;

                id3.Save();
            }
            catch (Exception ex)
            {
                op.AddException(ex);
            }
        }
Beispiel #6
0
        private void ConvertID3(string mp3FilePath)
        {
            ID3Info info = new ID3Info(mp3FilePath, true);

            if (info.ID3v1Info.HaveTag)
            {
                if (Regex.Match(StupiddEncoding(info.ID3v1Info.Artist), "[а-яА-Я№]").Value.Length > 0 || Regex.Match(StupiddEncoding(info.ID3v1Info.Album), "[а-яА-Я№]").Value.Length > 0 ||
                    Regex.Match(StupiddEncoding(info.ID3v1Info.Title), "[а-яА-Я№]").Value.Length > 0)
                {
                    info.ID3v1Info.Artist  = ConvName(StupiddEncoding(info.ID3v1Info.Artist));
                    info.ID3v1Info.Album   = ConvName(StupiddEncoding(info.ID3v1Info.Album));
                    info.ID3v1Info.Title   = ConvName(StupiddEncoding(info.ID3v1Info.Title));
                    info.ID3v1Info.Comment = ConvName(StupiddEncoding(info.ID3v1Info.Comment));

                    if (info.ID3v2Info.HaveTag)
                    {
                        info.ID3v2Info.ClearAll();
                        info.ID3v2Info.SetMinorVersion(3);
                        //Title
                        info.ID3v2Info.SetTextFrame("TIT2", ConvName(StupiddEncoding(info.ID3v1Info.Title)));

                        //Track
                        //info.ID3v2Info.SetTextFrame("TRCK", ConvName(StupiddEncoding(info.ID3v1Info.Title)));

                        //Disk
                        //info.ID3v2Info.SetTextFrame("TPOS","Text 3");

                        //Artist
                        //info.ID3v2Info.SetTextFrame("TPE1", ConvName(StupiddEncoding(info.ID3v1Info.Artist)));

                        //Album
                        //info.ID3v2Info.SetTextFrame("TALB", ConvName(StupiddEncoding(info.ID3v1Info.Album)));

                        //Genre
                        //info.ID3v2Info.SetTextFrame("TCON", cmb2Genre.Genre);
                        //Languege
                        //info.ID3v2Info.SetTextFrame("TLAN", cmb2Language.Language);
                    }
                    info.Save();
                }
            }
        }
Beispiel #7
0
            public void Process(IStatus status)
            {
                this.status = status;
                status.Report("Updataing tags...");

                ID3Info info = new ID3Info(this.source, true);

                info.ID3v1Info.HaveTag     = true;
                info.ID3v1Info.Title       = Helper.String.Clip(this.title, 30);
                info.ID3v1Info.Artist      = Helper.String.Clip(this.artist, 30);
                info.ID3v1Info.Album       = Helper.String.Clip(this.album, 30);
                info.ID3v1Info.Genre       = 255;
                info.ID3v1Info.Year        = DateTime.Now.Year.ToString();
                info.ID3v1Info.Comment     = string.Empty;
                info.ID3v1Info.TrackNumber = this.track;

                info.ID3v2Info.ClearAll();
                info.ID3v2Info.HaveTag = true;
                info.ID3v2Info.SetMinorVersion(3);
                info.ID3v2Info.SetTextFrame("TIT2", this.title);
                info.ID3v2Info.SetTextFrame("TPE1", this.artist);
                info.ID3v2Info.SetTextFrame("TALB", this.album);
                info.ID3v2Info.SetTextFrame("TCON", this.genre);
                info.ID3v2Info.SetTextFrame("TRCK", this.track.ToString());

                using (MemoryStream stream = Helper.Imaging.ImageToMemoryStream(this.artwork, System.Drawing.Imaging.ImageFormat.Jpeg))
                {
                    AttachedPictureFrame ATP = new AttachedPictureFrame(new FrameFlags(), "", TextEncodings.Ascii, "image/jpg", AttachedPictureFrame.PictureTypes.Cover_Front, stream);
                    info.ID3v2Info.AttachedPictureFrames.Add(ATP);

                    try
                    {
                        info.Save();
                    }
                    catch (Exception ex)
                    {
                        status.Report(String.Format("Unable to save tags. (\"{0}\")", ex.Message));
                    }
                }

                //info.Save();
            }
Beispiel #8
0
        private void ConvertID3_2(string mp3FilePath)
        {
            ID3Info info = new ID3Info(mp3FilePath, true);

            if (info.ID3v1Info.HaveTag)
            {
                if (Regex.Match(Converts(info.ID3v1Info.Artist, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue)), "[а-яА-Я№]").Value.Length > 0 ||
                    Regex.Match(Converts(info.ID3v1Info.Album, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue)), "[а-яА-Я№]").Value.Length > 0 ||
                    Regex.Match(Converts(info.ID3v1Info.Title, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue)), "[а-яА-Я№]").Value.Length > 0 ||
                    Regex.Match(Converts(info.ID3v1Info.Comment, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue)), "[а-яА-Я№]").Value.Length > 0)
                {
                    info.ID3v1Info.Artist  = Converts(info.ID3v1Info.Artist, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue));
                    info.ID3v1Info.Album   = Converts(info.ID3v1Info.Album, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue));
                    info.ID3v1Info.Title   = Converts(info.ID3v1Info.Title, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue));
                    info.ID3v1Info.Comment = Converts(info.ID3v1Info.Comment, Encoding.GetEncoding((int)comboBoxInput.SelectedValue), Encoding.GetEncoding((int)comboBoxOut.SelectedValue));



                    info.ID3v2Info.ClearAll();
                    info.ID3v2Info.SetMinorVersion(3);
                    //Title
                    info.ID3v2Info.SetTextFrame("TIT2", info.ID3v1Info.Title);
                    //Artist
                    info.ID3v2Info.SetTextFrame("TPE1", info.ID3v1Info.Artist);
                    //Album
                    info.ID3v2Info.SetTextFrame("TALB", info.ID3v1Info.Album);

                    info.ID3v1Info.Album   = "";
                    info.ID3v1Info.Artist  = "";
                    info.ID3v1Info.Comment = "";
                    info.ID3v1Info.Title   = "";


                    info.Save();
                }
            }

            /*
             * if (info.ID3v1Info.HaveTag)
             * {
             *  if (Regex.Match(Converts(info.ID3v1Info.Artist, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250)), "[а-яА-Я№]").Value.Length > 0 ||
             *      Regex.Match(Converts(info.ID3v1Info.Album, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250)), "[а-яА-Я№]").Value.Length > 0 ||
             *      Regex.Match(Converts(info.ID3v1Info.Title, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250)), "[а-яА-Я№]").Value.Length > 0 ||
             *      Regex.Match(Converts(info.ID3v1Info.Comment, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250)), "[а-яА-Я№]").Value.Length > 0)
             *  {
             *
             *      info.ID3v1Info.Artist = Converts(info.ID3v1Info.Artist, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250));
             *      info.ID3v1Info.Album = Converts(info.ID3v1Info.Album, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250));
             *      info.ID3v1Info.Title = Converts(info.ID3v1Info.Title, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250));
             *      info.ID3v1Info.Comment = Converts(info.ID3v1Info.Comment, Encoding.GetEncoding(1251), Encoding.GetEncoding(1250));
             *
             *
             *
             *
             *      info.ID3v2Info.ClearAll();
             *      info.ID3v2Info.SetMinorVersion(3);
             *      //Title
             *      info.ID3v2Info.SetTextFrame("TIT2", info.ID3v1Info.Title);
             *      //Artist
             *      info.ID3v2Info.SetTextFrame("TPE1", info.ID3v1Info.Artist);
             *      //Album
             *      info.ID3v2Info.SetTextFrame("TALB", info.ID3v1Info.Album);
             *
             *      info.ID3v1Info.Album = "";
             *      info.ID3v1Info.Artist = "";
             *      info.ID3v1Info.Comment = "";
             *      info.ID3v1Info.Title = "";
             *
             *
             *      info.Save();
             *  }
             * }
             */
        }