示例#1
0
        public void SaveAudio(string toLocation)
        {
            var ext    = System.IO.Path.GetExtension(_rawdata[(int)OSUfile.AudioFilename]);
            var toName = System.IO.Path.Combine(toLocation, GetSafeFilename(Title + ext));

            if (File.Exists(toName))
            {
                toName = System.IO.Path.Combine(toLocation, GetSafeFilename(Title + "[" + Version + "]" + ext));
            }
            File.Copy(Audio, toName, true);
            try
            {
                var file = new Mp3File(toName)
                {
                    TagHandler =
                    {
                        Artist = Artist,
                        Title  = Title
                    }
                };
                file.Update();
            }
            catch (Exception)
            {
                File.Copy(Audio, toName, true);
            }
        }
示例#2
0
        public void EditTag(string filename)
        {
            Mp3File mp3File = null;

            try
            {
                // create mp3 file wrapper; open it and read the tags
                mp3File = new Mp3File(filename);
            }
            catch (Exception e)
            {
                ExceptionMessageBox.Show(_form, e, "Error Reading Tag");
                return;
            }

            // create dialog and give it the ID3v2 block for editing
            // this is a bit sneaky; it uses the edit dialog straight out of TagScanner.exe as if it was a dll.
            TagEditor.ID3AdapterEdit id3Edit = new TagEditor.ID3AdapterEdit(mp3File);

            if (id3Edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using (new CursorKeeper(Cursors.WaitCursor))
                    {
                        mp3File.Update();
                    }
                }
                catch (Exception e)
                {
                    ExceptionMessageBox.Show(_form, e, "Error Writing Tag");
                }
            }
        }
        /// <summary>
        /// copy the newdata to the original.
        /// </summary>
        /// <param name="newData"></param>
        /// <param name="orig"></param>
        /// <returns>always true</returns>
        public static bool makeChangesAndContinue(TagHandlerUpdate newData, Mp3File orig)
        {
            newData.copy(orig.TagHandler);

            var retrycount = 0;
            var maxretry   = 10;

retry:
            try
            {
                orig.Update();
            }
            catch (Exception ecp)
            {
                retrycount++;
                if (retrycount >= maxretry)
                {
                    MessageBox.Show("Changes could not be made-" + ecp.ToString());
                    return(true);
                }
                System.Threading.Thread.Sleep(100);
                goto retry;
            }

            return(true);
        }
示例#4
0
        /// <summary>
        /// Updates the song's information through its properties
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="song"></param>
        public static void UpdateSongInformation(string filePath, Song song)
        {
            Mp3File file = new Mp3File(filePath);

            file.TagHandler.Album  = song.Album;
            file.TagHandler.Artist = song.Artist;
            file.TagHandler.Title  = song.Title;
            file.Update();
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            Mp3File.TagHandler.Picture = ptbNew.Image;
            Mp3File.Update();
            dgvList.SelectedRows[0].Cells[2].Value = ptbNew.Image;
            string path    = dgvList.SelectedRows[0].Cells[1].Value.ToString();
            string pathbak = System.IO.Path.GetDirectoryName(path) + "\\" + System.IO.Path.GetFileNameWithoutExtension(path) + ".bak";

            if (File.Exists(pathbak))
            {
                File.Delete(pathbak);
            }
        }
示例#6
0
        public void SetAudioTags(string outputFile, string title, string album, string artist)
        {
            Mp3File mp3 = new Mp3File(outputFile);

            mp3.TagHandler.Title  = title;
            mp3.TagHandler.Album  = album;
            mp3.TagHandler.Artist = artist;
            mp3.Update();

            DeleteBackupFile(outputFile);

            TagModified?.Invoke(this, new EventArgs());
        }
 private void btnUpdateAll_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < this.dgvList.Rows.Count; i++)
     {
         Mp3File = new Mp3File(dgvList.Rows[i].Cells["路径"].Value.ToString());
         Mp3File.TagHandler.Picture = ptbNew.Image;
         Mp3File.Update();
         dgvList.Rows[i].Cells[2].Value = ptbNew.Image;
         string path    = dgvList.Rows[i].Cells[1].Value.ToString();
         string pathbak = System.IO.Path.GetDirectoryName(path) + "\\" + System.IO.Path.GetFileNameWithoutExtension(path) + ".bak";
         if (File.Exists(pathbak))
         {
             File.Delete(pathbak);
         }
     }
 }
示例#8
0
 private static void func0(string path)
 {
     string[] files = Directory.GetFiles(path);
     foreach (string f in files)
     {
         Console.WriteLine(f);
         Mp3File    mp3    = new Mp3File(f);
         TagHandler thd    = mp3.TagHandler;
         string     artist = Pinyin.GetPinyin(thd.Artist);
         thd.Artist = CapFirstLetter(artist).Trim();
         string title = Pinyin.GetPinyin(thd.Title);
         thd.Title      = CapFirstLetter(title).Trim();
         mp3.TagHandler = thd;
         mp3.Update();
     }
     Console.WriteLine("Finish");
 }
示例#9
0
        private static void func1(string path)
        {
            string[] files = Directory.GetFiles(path);
            foreach (string f in files)
            {
                string tmp = f.Substring(path.Length, f.Length - path.Length);
                Console.WriteLine(tmp);
                string[] fn = tmp.Split('-');
                //tmp = ToDBC(tmp);

                // 添加后缀
                //File.Move(f, f + ".mp3");

                // 去除空格
                //string filename = fn[0].Trim() + " - " + fn[1].Trim();

                // 替换_到&
                //string fn = tmp.Replace("_", "&");

                // 去除括号
                //string[] fn = tmp.Split('(');
                //if (fn.Length > 1)
                //{
                //    string filename = fn[0].Trim();
                //    File.Move(f, path + filename);
                //}

                //更新mp3信息
                Mp3File    mp3 = new Mp3File(f);
                TagHandler thd = mp3.TagHandler;
                //thd.Title = CapFirstLetter(Pinyin.GetPinyin(fn[1].Substring(0, fn[1].Length - 4).Trim()));
                //thd.Artist = CapFirstLetter(Pinyin.GetPinyin(fn[0].Trim()));
                thd.Title      = fn[1].Substring(0, fn[1].Length - 4).Trim();
                thd.Artist     = fn[0].Trim();
                thd.Year       = "";
                thd.Album      = "";
                thd.Disc       = "";
                thd.Track      = "";
                thd.Genre      = "";
                mp3.TagHandler = thd;
                mp3.Update();
            }
            Console.WriteLine("Finish");
        }
示例#10
0
        public void saveTags()
        {
            if (imageUpdated)
            {
                System.Drawing.Image image = Tag_Image.Tag as System.Drawing.Image;
                //Bitmap b = Tag_Image.Tag as Bitmap;
                file.TagHandler.Picture = image;
            }

            if (tagsUpdated)
            {
                file.TagHandler.Album  = Tag_Album.Text;
                file.TagHandler.Artist = Tag_Artist.Text;
                file.TagHandler.Song   = Tag_Song.Text;
            }
            try
            {
                file.Update();
                //delete any bak files
                string   bakName = System.IO.Path.ChangeExtension(file.FileName, "bak");
                FileInfo bakfile = new FileInfo(bakName);
                if (bakfile.Exists)
                {
                    if (chk_Backup.IsChecked == true)
                    {
                        string location = backupDirectory.FullName + @"\" + System.IO.Path.GetFileName(file.FileName);
                        bakfile.MoveTo(location);
                    }
                    else
                    {
                        bakfile.Delete();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#11
0
        public void saveTags()
        {
            if (file == null)
            {
                lbl_status.Text = "No file is currently selected!";
                return;
            }

            if (imageUpdated)
            {
                System.Drawing.Image image = Tag_Image.Tag as System.Drawing.Image;
                //Bitmap b = Tag_Image.Tag as Bitmap;

                file.TagHandler.Picture = image;
            }

            if (tagsUpdated)
            {
                file.TagHandler.Album  = Tag_Album.Text;
                file.TagHandler.Artist = Tag_Artist.Text;
                file.TagHandler.Song   = Tag_Song.Text;
            }

            //check our paths exist and files don't before we start.
            string   bakName        = System.IO.Path.ChangeExtension(file.FileName, "bak");
            FileInfo bakfile        = new FileInfo(bakName);
            string   backupLocation = backupDirectory.FullName + @"\" + System.IO.Path.GetFileName(file.FileName);

            if (backupDirectory.Exists == false)
            {
                lbl_status.Text = "Backup Directory does not exist!";
                return;
            }
            //if it's null, it was never set, therefore we dont move the file. If its !exists, it was set, but isnt a valid folder.
            if (destinationDirectory != null && destinationDirectory.Exists == false)
            {
                lbl_status.Text = "Destination Directory does not exist!";
                return;
            }


            //save the file. Creates a .bak in the source dir
            file.Update();

            //move / delete any bak files
            if (bakfile.Exists)
            {
                if (chk_Backup.IsChecked == true)
                {
                    bakfile.MoveTo(backupLocation);
                }
                else
                {
                    bakfile.Delete();
                }
            }


            //move file to output folder (if selected)
            //if it's null, it was never set, therefore we dont move the file. If its !exists, it was set, but isnt a valid folder.
            if (destinationDirectory != null)
            {
                FileInfo fi = new FileInfo(file.FileName);
                file = null;
                fi.MoveTo(destinationDirectory.FullName + "\\" + fi.Name);
            }
        }
示例#12
0
 public void Save()
 {
     _mp3.Update();
 }