예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            _meta.Tag.Performers = new String[1] {
                txtArtist.Text
            };
            _meta.Tag.Title = txtTitle.Text;
            _meta.Save();
            string newFile = _folder + "\\" + txtFileName.Text + ".mp3";

            if (!File.Exists(_meta.Name))
            {
                MessageBox.Show("There is no file: \n" + _meta.Name);
                return;
            }

            //if (File.Exists(newFile)) File.Delete(newFile);
            File.Move(_meta.Name, newFile);
            loadFile(++_counter);
        }
예제 #2
0
        public static void SetAlbumArt(Uri link, TagLib.File file)
        {
            byte[] imageBytes;
            using (WebClient client = new WebClient())
            {
                imageBytes = client.DownloadData(link);
            }

            TagLib.Id3v2.AttachedPictureFrame cover = new TagLib.Id3v2.AttachedPictureFrame
            {
                Type         = TagLib.PictureType.FrontCover,
                Description  = "Cover",
                MimeType     = System.Net.Mime.MediaTypeNames.Image.Jpeg,
                Data         = imageBytes,
                TextEncoding = TagLib.StringType.UTF16
            };
            file.Tag.Pictures = new TagLib.IPicture[] { cover };
            file.Save();
        }
예제 #3
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            if (this.SelectedFile == null)
            {
                MessageBox.Show("You have not selected a valid file in your library.", "Something requires your attention.");

                return;
            }

            TagLib.File tagLibFile = TagLib.File.Create(this.SelectedFile.Location);

            tagLibFile.Tag.Title   = this.TextName.Text;
            tagLibFile.Tag.Album   = this.TextAlbum.Text;
            tagLibFile.Tag.Artists = new string[] { this.TextArtist.Text };

            tagLibFile.Save();

            this.ButtonRefresh.PerformClick();
        }
예제 #4
0
        //Saves the information of the song.
        private void btnSave_Click(object sender, EventArgs e)
        {
            lblStatus.Text = "";
            int             selectedRowIndex = dgvMusic.SelectedCells[0].RowIndex;
            DataGridViewRow selectedRow      = dgvMusic.Rows[selectedRowIndex];

            string title = txtTitle.Text;

            string[] artists = txtArtist.Text.Split(',');
            string[] genres  = txtGenre.Text.Split(',');
            string   album   = txtAlbum.Text;
            int      year;

            if (!int.TryParse(txtYear.Text, out year))
            {
                lblStatus.Text = "Invalid year.";
                txtYear.Focus();
                return;
            }
            string filePath = selectedRow.Cells["FilePath"].Value.ToString();

            //Changes the file information
            try {
                TagLib.File file = TagLib.File.Create(filePath);
                file.Tag.Title     = title;
                file.Tag.Composers = artists;
                file.Tag.Genres    = genres;
                file.Tag.Album     = album;
                file.Tag.Year      = (uint)year;

                file.Save();
            } catch
            {
                lblStatus.Text = "Error editing file.";
                return;
            }

            //Updates information in database.
            dbUtils.Edit(title, artists, year, album, genres, filePath);
            lblStatus.Text = dbUtils.LastStatus;

            displayData();
        }
예제 #5
0
        protected override void Metadata()
        {
            ResetOutBuffer();
            using TagLib.File file = TagLib.File.Create(new MemoryFileAbstraction($"buffer.{MediaType.MimeToExt(MusicMime)}", OutBuffer));
            TagLib.Tag tag = MusicMime switch
            {
                "audio/flac" => file.Tag,
                "audio/mpeg" => file.GetTag(TagLib.TagTypes.Id3v2),
                _ => throw new FileLoadException($"Failed to get file type while processing \"{InPath}\"."),
            };

            if (CoverMime != null)
            {
                tag.Pictures = new TagLib.IPicture[1] {
                    new TagLib.Picture(new TagLib.ByteVector(CoverBuffer.ToArray(), (int)CoverBuffer.Length))
                    {
                        MimeType = CoverMime,
                        Type     = TagLib.PictureType.FrontCover
                    }
                };
            }

            if (StdMetadata.Title != null)
            {
                tag.Title = StdMetadata.Title;
            }
            if (StdMetadata.Artists != null)
            {
                tag.Performers = StdMetadata.Artists;
            }
            if (StdMetadata.Album != null)
            {
                tag.Album = StdMetadata.Album;
            }
            if (StdMetadata.AlbumArtist != null && tag.AlbumArtists.Length == 0)
            {
                tag.AlbumArtists = new string[] { StdMetadata.AlbumArtist }
            }
            ;

            file.Save();
        }
예제 #6
0
 private bool addcoverart(string audiopath, string picturepath)
 {
     try
     {
         TagLib.File    TagLibFile = TagLib.File.Create(audiopath);
         TagLib.Picture picture    = new TagLib.Picture(picturepath);
         TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(picture);
         albumCoverPictFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
         albumCoverPictFrame.Type     = TagLib.PictureType.FrontCover;
         TagLib.IPicture[] pictFrames = new TagLib.IPicture[1];
         pictFrames[0]           = (TagLib.IPicture)albumCoverPictFrame;
         TagLibFile.Tag.Pictures = pictFrames;
         TagLibFile.Save();
     }
     catch
     {
         return(false);
     }
     return(true);
 }
예제 #7
0
 private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     //current textbox values will overwrite the current file tags
     currentFile.Tag.Title         = titleTextBox.Text;
     currentFile.Tag.Performers[0] = artistTextBox.Text;
     currentFile.Tag.Album         = albumTextBox.Text;
     try
     {
         currentFile.Tag.Year = uint.Parse(yearTextBox.Text);
     }
     //if year not in unit get the current year from date time
     catch (FormatException)
     {
         DateTime now = DateTime.Today;
         currentFile.Tag.Year = uint.Parse(now.ToString("yyyy"));
     }
     //save and hide menu
     currentFile.Save();
     editHidden();
 }
예제 #8
0
        public bool SaveAlbumImage(string filePath, byte[] imgBytes)
        {
            try
            {
                TagFile _file = TagFile.Create(filePath);

                var _picList = new List <TagPicture>()
                {
                    new TagPicture(imgBytes)
                };
                _file.Tag.Pictures = _picList.ToArray();
                _file.Save();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            //新增外层是父目录
            var basePath = @"D:\洗音乐专用";
            var paths    = Directory.GetDirectories(basePath).ToList();

            //包含父目录
            paths.Add(basePath);
            foreach (var item in paths)
            {
                var dirPath = item;
                if (dirPath[dirPath.Length - 1] != '\\')
                {
                    dirPath += @"\";
                }
                string targetBasePath = dirPath + @"\temp\";
                FileHelper.CreateDirectory(targetBasePath);
                var files = Directory.GetFiles(dirPath);
                foreach (var file in files)
                {
                    var         path = file.Trim();
                    TagLib.File f    = TagLib.File.Create(path);

                    var name = Path.GetFileName(path);
                    //网易读取的名字
                    f.Tag.Title = name;
                    //说明的左边
                    f.Tag.Performers = new string[] { name };
                    //说明的右边
                    f.Tag.Album = name;

                    f.Tag.Pictures = null;
                    f.Save();
                    var targetPath = targetBasePath + name;
                    FileHelper.MoveFile(file, targetPath);
                }
            }

            Console.WriteLine("清洗完毕");
            Console.ReadLine();
        }
예제 #10
0
        private void button6_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                string x = row.Cells[0].Value.ToString();

                WorkingTrack wt = collection[x.ToLower()];

                if (wt != null)
                {
                    if (wt.Position != null)
                    {
                        IITFileOrCDTrack track = GetITTFileOrCDTrackFromWorkingTrack(wt);

                        string AlbumArtist = new FileInfo(wt.iTunesLocation).Directory.Parent.Name;

                        if (track.AlbumArtist != AlbumArtist)
                        {
                            track.AlbumArtist = AlbumArtist;
                        }

                        wt.iTunesAlbumArtist = AlbumArtist;
                    }

                    string newID3AlbumArtist = new FileInfo(wt.ID3Location).Directory.Parent.Name;

                    TagLib.File mp3File = TagLib.File.Create(wt.ID3Location);

                    if (mp3File.Tag.FirstAlbumArtist != newID3AlbumArtist)
                    {
                        mp3File.Tag.AlbumArtists = new string[] { newID3AlbumArtist };
                        mp3File.Save();
                    }

                    wt.ID3AlbumArtist = newID3AlbumArtist;

                    collection[x.ToLower()] = wt;
                }
            }
            MessageBox.Show("done");
        }
예제 #11
0
        private void btnApplyTags_Click(object sender, EventArgs e)
        {
            if (this._musicFiles.Count == 0)
            {
                return;
            }

            foreach (MusicFile musicFile in this._musicFiles.Values)
            {
                try {
                    TagLib.File file = TagLib.File.Create(musicFile.FileName);
                    file.Tag.Title        = musicFile.SongName;
                    file.Tag.AlbumArtists = musicFile.Authors;
                    file.Tag.Performers   = musicFile.Featuring;
                    file.Save();
                }
                catch (Exception ex) {
                    MessageBox.Show("Error while saving " + musicFile.FileName + ".", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #12
0
        public void SetMp3Tags(string mp3Path, string artist, string title)
        {
            if (!File.Exists(mp3Path))
            {
                throw new FileNotFoundException($"Mp# was not found at the specified path {mp3Path}. Setting of MP3 tags failed.");
            }

            using (TagLib.File file = TagLib.File.Create(mp3Path))
            {
                file.RemoveTags(TagLib.TagTypes.AllTags);
                file.Save();
            }

            using (TagLib.File file = TagLib.File.Create(mp3Path))
            {
                file.Tag.Title        = title;
                file.Tag.Performers   = new[] { artist };
                file.Tag.AlbumArtists = new[] { artist };
                file.Save();
            }
        }
예제 #13
0
        private void CopyCurrentTagToAnotherFile(string TargetFileTag)
        {
            TagLib.File targetFile = TagLib.File.Create(TargetFileTag);

            // Moche mais pas de IEnumerable sur le Tag :(
            targetFile.Tag.Album                      = _file.Tag.Album;
            targetFile.Tag.AlbumArtists               = _file.Tag.AlbumArtists;
            targetFile.Tag.AlbumArtistsSort           = _file.Tag.AlbumArtistsSort;
            targetFile.Tag.AlbumSort                  = _file.Tag.AlbumSort;
            targetFile.Tag.AmazonId                   = _file.Tag.AmazonId;
            targetFile.Tag.BeatsPerMinute             = _file.Tag.BeatsPerMinute;
            targetFile.Tag.Composers                  = _file.Tag.Composers;
            targetFile.Tag.ComposersSort              = _file.Tag.ComposersSort;
            targetFile.Tag.Conductor                  = _file.Tag.Conductor;
            targetFile.Tag.Disc                       = _file.Tag.Disc;
            targetFile.Tag.DiscCount                  = _file.Tag.DiscCount;
            targetFile.Tag.Genres                     = _file.Tag.Genres;
            targetFile.Tag.Grouping                   = _file.Tag.Grouping;
            targetFile.Tag.Lyrics                     = _file.Tag.Lyrics;
            targetFile.Tag.MusicBrainzArtistId        = _file.Tag.MusicBrainzArtistId;
            targetFile.Tag.MusicBrainzDiscId          = _file.Tag.MusicBrainzDiscId;
            targetFile.Tag.MusicBrainzReleaseArtistId = _file.Tag.MusicBrainzReleaseArtistId;
            targetFile.Tag.MusicBrainzReleaseCountry  = _file.Tag.MusicBrainzReleaseCountry;
            targetFile.Tag.MusicBrainzReleaseId       = _file.Tag.MusicBrainzReleaseId;
            targetFile.Tag.MusicBrainzReleaseStatus   = _file.Tag.MusicBrainzReleaseStatus;
            targetFile.Tag.MusicBrainzReleaseType     = _file.Tag.MusicBrainzReleaseType;
            targetFile.Tag.MusicBrainzTrackId         = _file.Tag.MusicBrainzTrackId;
            targetFile.Tag.MusicIpId                  = _file.Tag.MusicIpId;
            targetFile.Tag.Performers                 = _file.Tag.Performers;
            targetFile.Tag.PerformersSort             = _file.Tag.PerformersSort;
            targetFile.Tag.Pictures                   = _file.Tag.Pictures;
            targetFile.Tag.Title                      = _file.Tag.Title;
            targetFile.Tag.TitleSort                  = _file.Tag.TitleSort;
            targetFile.Tag.Track                      = _file.Tag.Track;
            targetFile.Tag.TrackCount                 = _file.Tag.TrackCount;
            targetFile.Tag.Year                       = _file.Tag.Year;

            targetFile.Save();
            _isEncoded = true;
        }
예제 #14
0
        public static void UpdateMp3Metadata(string filePath, bool updateITunes)
        {
            OnStatusUpdate("Updating metadata: " + filePath);

            TagLib.File f = TagLib.File.Create(filePath);

            //check if album.jpg exists
            //if so, reset pictures array with it
            string albumPath = Path.GetDirectoryName(filePath) + "\\Album.jpg";

            if (File.Exists(albumPath))
            {
                //trying to do the following will not work for iTunes: TagLib.Picture cover = new TagLib.Picture(albumPath);
                //additional info here http://stackoverflow.com/questions/13667378/embed-album-art-in-mp3-using-tag-lib-c-sharp

                TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
                pic.TextEncoding = TagLib.StringType.Latin1;
                pic.MimeType     = System.Net.Mime.MediaTypeNames.Image.Jpeg;
                pic.Type         = TagLib.PictureType.FrontCover;
                pic.Data         = TagLib.ByteVector.FromPath(albumPath);

                f.Tag.Pictures = new TagLib.IPicture[1] {
                    pic
                };

                f.Save();
            }
            //

            //clear composer, comments

            //check for "various artists"

            //if update iTunes is checked, then update iTunes
            if (updateITunes)
            {
                var iTunesFile = ITunesMusicTracks.Where(t => t.Location.ToLower() == filePath.ToLower()).FirstOrDefault();
                iTunesFile.UpdateInfoFromFile();
            }
        }
예제 #15
0
        private int SetSongMetadata(string path, entry data)
        {
            try {
                TagLib.File file = TagLib.File.Create(path);

                //file.Tag.Performers = null;
                file.Tag.Performers = new[] { data.artist };

                //file.Tag.AlbumArtists = null;
                file.Tag.AlbumArtists = new[] { data.album_artist };

                file.Tag.Album = data.album;

                file.Tag.Title = data.title;

                //file.Tag.Genres = null;
                string[] genres = data.genre.Split('/');
                file.Tag.Genres = genres;

                file.Tag.Track = (uint)Convert.ToInt32(data.track_num);

                file.Tag.Year = (uint)Convert.ToInt32(data.year);

                file.Save();

                Print("changed: " + path + "\r\n");
            }
            catch (Exception ex) {
                if (ex.GetType().IsAssignableFrom(typeof(System.IO.FileNotFoundException)))
                {
                    return(2);
                }
                else
                {
                    Print("error " + ex + "\r\n");
                    return(1);
                }
            }
            return(0);
        }
예제 #16
0
        private void bg_Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            int int_counter = 0;
            int int_renamed = 0;

            try
            {
                BackgroundWorker worker = sender as BackgroundWorker;

                string        dirPath    = txt_Path.Text;
                DirectoryInfo dir_Source = new DirectoryInfo(txt_Path.Text);
                FileInfo[]    files      = dir_Source.GetFiles("*.mp3");
                foreach (FileInfo file in files)
                {
                    int_counter += 1;
                    string finalName = string.Empty;
                    if (file.Name.Contains('-'))
                    {
                        int_renamed += 1;
                        finalName    = file.Name.Remove(0, file.Name.LastIndexOf('-') + 1).Trim();
                        finalName    = Path.Combine(file.Directory.FullName, finalName);
                        worker.ReportProgress((int_counter * 10));
                        File.Move(file.FullName, finalName);
                        TagLib.File tagFile = TagLib.File.Create(finalName);
                        if (tagFile.Tag.Title.Contains("- SongsPK.info"))
                        {
                            tagFile.Tag.Title = tagFile.Tag.Title.Replace("- SongsPK.info", "");
                            tagFile.Save();
                        }
                    }
                }
                this.txt_Path.Text = "";
                e.Result           = (new RenameProgress(int_counter, int_renamed, Constants.Success, string.Empty));
            }
            catch (Exception ex)
            {
                e.Result = (new RenameProgress(int_counter, int_renamed, Constants.Failure, ex.Message));
            }
        }
예제 #17
0
        // PUT /api/music/5
        public HttpResponseMessage Put(Models.MusicModel data)
        {
            HttpResponseMessage theresponse = new HttpResponseMessage();

            string filePath = HttpContext.Current.Server.MapPath("~/Content/Music") + "\\" + data.MusicId.ToString() + ".mp3";

            if (System.IO.File.Exists(filePath))
            {
                TagLib.File file = TagLib.File.Create(filePath);
                if (!string.IsNullOrWhiteSpace(data.Title))
                {
                    file.Tag.Title = data.Title;
                }
                if (!string.IsNullOrWhiteSpace(data.Artist))
                {
                    file.Tag.Performers = data.Artist.Split(',');
                }
                if (!string.IsNullOrWhiteSpace(data.Album))
                {
                    file.Tag.Album = data.Album;
                }
                if (!string.IsNullOrWhiteSpace(data.Genres))
                {
                    file.Tag.Genres = data.Genres.Split(',');
                }
                file.Tag.Track = data.Track;
                file.Save();

                theresponse.StatusCode = System.Net.HttpStatusCode.OK;

                //Hreinsum cacheið
                HttpContext.Current.Cache.Remove("songlist");
            }
            else
            {
                theresponse.StatusCode = System.Net.HttpStatusCode.NotFound;
            }
            return(theresponse);
        }
예제 #18
0
        public void WriteTag()
        {
            File file = TagLib.File.Create(_filepath);

            if (file == null)
            {
                return;
            }

            //checking for readonly
            var fileInfo = new FileInfo(_filepath);

            if (fileInfo.IsReadOnly)
            {
                fileInfo.IsReadOnly = false;
            }

            // artist tag editor
            file.Tag.Performers = ArtistName.Split('&');

            // album tag editor
            file.Tag.Album  = AlbumTitle;
            file.Tag.Genres = new[] { Genre };
            //file.Tag.Composers = Composers;
            //file.Tag.Conductor = Conductor;
            uint year;

            if (UInt32.TryParse(Year.ToString(CultureInfo.InvariantCulture), out year))
            {
                file.Tag.Year = year;
            }

            // song
            file.Tag.Title = TrackTitle;
            file.Tag.Track = Convert.ToUInt32(TrackNumber);

            // save
            file.Save();
        }
예제 #19
0
        public void SetMusicTag(string sourcePath)
        {
            if (string.IsNullOrWhiteSpace(sourcePath))
            {
                Console.WriteLine("Cannot change tag, path was not found");
                return;
            }
            Folder folder = shell.NameSpace(sourcePath);

            if (folder == null)
            {
                //TODO: Add dialog
                Console.WriteLine("Cannot change tag, path was not found");
                return;
            }


            FolderItem[] musicFiles = folder.Items().Cast <FolderItem>().Where(item => item.Type == "MP3 File").ToArray();

            foreach (FolderItem musicFilePath in musicFiles)
            {
                Folder3 tempFolder = (Folder3)shell.NameSpace(Path.GetTempPath());
                tempFolder.NewFolder("Music ripper");
                tempFolder = (Folder3)shell.NameSpace(Path.Combine(Path.GetTempPath(), "Music ripper"));
                tempFolder.MoveHere(musicFilePath);
                WaitForAFileTransfer(tempFolder, musicFilePath.Name);
                FolderItem tempMpFile = tempFolder.Items().Cast <FolderItem>().First(item => item.Name == musicFilePath.Name);
                using (TagLib.File file = TagLib.File.Create(tempMpFile.Path))
                {
                    file.Tag.Album        = form.MusicTagName.Text;
                    file.Tag.AlbumArtists = new string[] { form.MusicTagName.Text };
                    file.Tag.Performers   = new string[] { form.MusicTagName.Text };
                    file.Save();
                }
                folder.MoveHere(tempMpFile.Path);
                WaitForAFileTransfer(folder, tempMpFile.Name);
            }
        }
예제 #20
0
        public void Execute()
        {
            string libraryPath = Properties.Settings.Default.LibraryLocation;

            string fileName = Path.Combine(libraryPath, TagDownload.TagFile.ToString());

            YouTube youtube = YouTube.Default;
            Video   video   = youtube.GetVideo(this.TagDownload.YoutubeUri);

            System.IO.File.WriteAllBytes(fileName + ".vid", video.GetBytes());

            var inputFile = new MediaFile {
                Filename = fileName + ".vid"
            };
            var outputFile = new MediaFile {
                Filename = $"{fileName}.mp3"
            };

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);

                engine.Convert(inputFile, outputFile);
            }

            File.Delete(inputFile.Filename);

            // Write dem meta shiz
            TagLib.File tagLibFile = TagLib.File.Create(outputFile.Filename);

            tagLibFile.Tag.Title   = TagDownload.TagMeta.Name;
            tagLibFile.Tag.Album   = TagDownload.TagMeta.Album;
            tagLibFile.Tag.Artists = new string[] { TagDownload.TagMeta.Artist };

            tagLibFile.Save();

            Context.MainForm.DoRefresh();
        }
예제 #21
0
        public static void ModifyMusic(Element originalElement, string newName, string[] genres)
        {
            Music foundMusic = GetMusic(originalElement);

            if (foundMusic != null)
            {
                foundMusic.Title = newName;
                foundMusic.MID   = Utility.Hash.SHA256Hash(foundMusic.Title + foundMusic.Author.Name);

                TagLib.File file = TagLib.File.Create(foundMusic.ServerPath);
                file.Tag.Title = foundMusic.Title;

                if (genres != null)
                {
                    foundMusic.Genre = genres;
                    file.Tag.Genres  = genres;
                }

                file.Save();

                MusicsInfo.EditMusicsInfo(originalElement.MID, foundMusic);
            }
        }
예제 #22
0
 /// <summary>
 /// get song information and write it into the metadata
 /// </summary>
 public async void tagging()
 {
     foreach (var file in getFilesMp3())
     {
         String fileName = Path.GetFileNameWithoutExtension(file);
         try
         {
             if (file.Contains(".mp3"))
             {
                 TagLib.File filetoTag = TagLib.File.Create(file);
                 filetoTag.Tag.Title      = fileName.Substring(fileName.IndexOf("-") + 1);
                 filetoTag.Tag.Performers = null;
                 filetoTag.Tag.Performers = new[] { fileName.Substring(0, fileName.IndexOf("-")) };
                 filetoTag.Save();
             }
         }
         catch
         {
             MetroMessageBox.Show(Form.ActiveForm, fileName.Substring(fileName.IndexOf("-") + 1) + "\r\nFile format must be like: artist - title ", "Tagging error");
         }
     }
     await Task.Delay(1);
 }
예제 #23
0
        private void storeFile(string path, string name)
        {
            string[] artiste = artists[path].Replace("; ", ";").Split(';');
            string   album   = albums[path];
            string   destFolder;

            if (album == "")
            {
                destFolder = Path.Combine(Settings.Default.Musique, String.Join("", artiste[0].Split('\\', '|', '?', '\"', '<', '>', '*', '/', ':')));
            }
            else
            {
                destFolder = Path.Combine(Settings.Default.Musique, String.Join("", artiste[0].Split('\\', '|', '?', '\"', '<', '>', '*', '/', ':')), String.Join("", album.Split('\\', '|', '?', '\"', '<', '>', '*', '/', ':')));
            }

            if (!Directory.Exists(destFolder))
            {
                Directory.CreateDirectory(destFolder);
            }

            TagLib.File f = TagLib.File.Create(path);
            f.Tag.Album      = album;
            f.Tag.Performers = new string[] { artiste[0] };
            f.Tag.Title      = name;
            f.Save();

            string destination = Path.Combine(destFolder, String.Join("", name.Split('\\', '|', '?', '\"', '<', '>', '*', '/', ':')) + Path.GetExtension(path));

            if (File.Exists(destination) && destination != path)
            {
                File.Delete(path);
            }
            else
            {
                File.Move(path, destination);
            }
        }
예제 #24
0
        ///// <summary>
        ///// intialize listview
        ///// </summary>
        ///// <param name="lv"></param>
        //public virtual void Initialize()
        //{
        //    if(lv.SelectedItems.Count > 0)
        //    {
        //        idx = 0;
        //    }

        //    //string[] fmts = new string[Properties.Settings.Default.org_formats.Count];
        //    //Properties.Settings.Default.org_formats.CopyTo( fmts, 0 );
        //    //cmbFormat.Items.AddRange( fmts );
        //    //cmbFormat.SelectedIndex = 0;
        //}

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(cmbFormat.Text))
            {
                MessageBox.Show(
                    "Please eneter a valid format and path.",
                    "Invalid",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Asterisk);
                return;
            }

            ListView.SelectedListViewItemCollection items = lv.SelectedItems;
            int len = items.Count;

            FileInfo[] infos = new FileInfo[len];

            for (int i = 0; i < len; ++i)
            {
                infos[i] = items[i].Tag as FileInfo;
            }

            //Threading.File2TagProgressThread thread = new Threading.File2TagProgressThread(
            //    infos,
            //    cmbFormat.Text );
            //thread.Start();


            foreach (FileInfo fi in infos)
            {
                TagLib.File             tag_file = TagLib.File.Create(fi.FullName);
                File2TagFormatEvaluator eval     = new File2TagFormatEvaluator(cmbFormat.Text, tag_file);
                tag_file.Save();
            }
            view.RefreshView();
            Close();
        }
예제 #25
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                var         selectedMP3 = listBox1.SelectedItem.ToString();
                TagLib.File tagFile     = TagLib.File.Create(selectedMP3);

                tagFile.Tag.Title = textBox8.Text;
                label1.Text       = "Process completed: " + DateTime.Now.ToString("h:mm:ss tt");

                tagFile.Save();
                textBox8.Text = "";
                listBox1.ClearSelected();
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
                textBox5.Text = "";
                textBox6.Text = "";
            }
            catch (NullReferenceException ex)
            {
                label9.Text = "No MP3s selected!";
            }
        }
예제 #26
0
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            if (tbTitle2.Text != "")
            {
                file.Tag.Title = tbTitle2.Text;
            }

            //  file.Tag.Performers[0] = tbArtist2.Text;

            // file.Tag.Album = tbAlbum2.Text;

            //if (tbTrack2.Text != "")
            //{
            //    try { file.Tag.Track = Convert.ToUInt32(tbTrack2.Text); }
            //    catch (Exception) { throw; }
            //}

            // set is nowhere to be found

            // Setting Performers to null because file.Tag.FirstPerformer is read-only
            //if (tbArtist2.Text != "")
            //{
            //    file.Tag.Performers = null;
            //    file.Tag.Performers = new[] { tbArtist2.Text };
            //}

            // Same for Genres
            if (cbGenre2.SelectedItem != null)
            {
                file.Tag.Genres = null;
                file.Tag.Genres = new[] { cbGenre2.SelectedItem.ToString() };
            }

            file.Save();
            MessageBox.Show("File saved successfully.");
        }
예제 #27
0
 //save the newly updated tag data.
 private void saveMetaData()
 {
     //making sure year input is valid
     match = Regex.Match(meReleaseYear.Text, regex);
     if (match.Success)
     {
         //make textbox red and display error in the box
         meReleaseYear.Background = Brushes.Red;
         meReleaseYear.Text       = faultyYearStr;
         //end the function
         return;
     }
     else
     {
         meReleaseYear.Background = Brushes.White;
     }
     //update the tags with user input data.
     file.Tag.Title = meSong.Text;
     file.Tag.Album = meAlbum.Text;
     try
     {
         file.Tag.Year = Convert.ToUInt32(meReleaseYear.Text);
     }catch (Exception e)
     {
         throw e;
     }
     file.Tag.AlbumArtists = new[] { meArtist.Text };
     try
     {
         file.Save();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #28
0
        protected override void Metadata()
        {
            ResetOutBuffer();
            using TagLib.File file = TagLib.File.Create(new MemoryFileAbstraction($"buffer.{MediaType.MimeToExt(MusicMime)}", OutBuffer));
            TagLib.Tag tag = MusicMime switch
            {
                "audio/flac" => file.Tag,
                "audio/mpeg" => file.GetTag(TagLib.TagTypes.Id3v2),
                "audio/mpeg4" => file.Tag,
                "audio/ogg" => file.Tag,
                _ => throw new FileLoadException($"Failed to get file type while processing \"{InPath}\"."),
            };

            if (tag.Pictures.Length > 0)
            {
                tag.Pictures[0].Type = TagLib.PictureType.FrontCover;
            }

            if (ForceRename)
            {
                if (tag.Title != null && tag.AlbumArtists.Length > 0)
                {
                    OutName = $"{tag.AlbumArtists[0]} - {tag.Title}";
                }
                else if (tag.Title != null && tag.Performers.Length > 0)
                {
                    OutName = $"{tag.Performers[0]} - {tag.Title}";
                }
                else
                {
                    Logger.Error("Failed to find name for {Path}", InPath);
                }
            }

            file.Save();
        }
예제 #29
0
        public void Save()
        {
            try
            {
                TagLib.File file = TagLib.File.Create(Location);

                file.Tag.Title      = Title;
                file.Tag.Performers = new string[1] {
                    Artist
                };
                file.Tag.Album  = Album;
                file.Tag.Genres = new string[1] {
                    Genre
                };
                file.Tag.Year = Year;

                file.Save();
                file.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #30
0
        /// <summary>
        /// saves mp3 tag information to file
        /// </summary>
        /// <param name="taglibFile"></param>
        public void SaveMp3Tag(TagLib.File taglibFile)
        {
            if (taglibFile != null)
            {
                //string fName = file.FileName;
                //AudioFileReader prev = file;
                if (file != null)
                {
                    float curVol = file.Volume;
                    wavePlayer.Stop();
                    //wavePlayer.Dispose();
                    //file.Close();
                    //file.Dispose();

                    string prevFile = this.file.FileName;

                    this.file.Close();
                    this.file.Dispose();
                    this.file = null;

                    try
                    {
                        taglibFile.Save();
                    }
                    catch (UnauthorizedAccessException)
                    { }
                    catch (Exception)
                    { }

                    this.file = new AudioFileReader(prevFile);
                    wavePlayer.Init(file);
                    SetVolume(curVol);
                    //wavePlayer.Play();
                }
            }
        }