public void SetPictures(string[] picturepath, bool update = false) { if (_mp3file == null) { _mp3file = TagLib.File.Create(_filename); } if (picturepath.Length != 0) { if (_mp3file.Tag.Pictures == null || _mp3file.Tag.Pictures.Length == 0 || update) { int pn = new Random(DateTime.Now.Millisecond).Next(0, picturepath.Length); // var pictures = new TagLib.Picture[1]; 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(picturepath[pn]); // save picture to file _mp3file.Tag.Pictures = new TagLib.IPicture[1] { pic }; } } }
// This method sets album cover art for mp3 files https://stackoverflow.com/a/50438153/ public void SetAlbumArt(string url, TagLib.File file, string path_, string filename) { string path = string.Format(@"{0}\{1}.jpg", path_, filename); byte[] imageBytes = null; try { using (WebClient client = new WebClient()) { imageBytes = client.DownloadData(url); } } catch (Exception ex) { MessageBox.Show(ex.Message); } 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 }; }
/// <summary> /// Get the album cover as Taglib instance. /// </summary> /// <returns>The album cover as Taglib instance.</returns> public TagLib.Id3v2.AttachedPictureFrame getAlbumImage() { TagLib.Picture picture = new TagLib.Picture(new TagLib.ByteVector(_imageBytes.ToArray())); TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(picture); albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; albumCoverPictFrame.TextEncoding = TagLib.StringType.Latin1; return(albumCoverPictFrame); }
public static string WriteInfos(int a) { try { TagLib.File f = TagLib.File.Create(mp3.pfad[a]); f.Tag.Title = title[a]; f.Tag.Performers[0] = artist[a]; f.Tag.Album = album[a]; f.Tag.AlbumArtists[0] = albumartist[a]; if (track[a] == -1) { } else { f.Tag.Track = Convert.ToUInt16(track[a]); } if (year[a] == -1) { } else { f.Tag.Year = Convert.ToUInt16(year[a]); } f.Tag.Genres[0] = genre[a]; f.Tag.Comment = comment[a]; if (Settings.Default.CommentChangeEnabled) { f.Tag.Comment = Settings.Default.Comment; } //albumcover TagLib.IPicture[] pictures = new IPicture[albumcover[a].Count()]; TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame(); for (int i = 1; i < albumcover[a].Count(); i++) { mp3.albumcoverpfad[a][i] = Path.GetTempPath() + i + System.DateTime.Now.GetHashCode() + ".jpg"; mp3.albumcover[a][i].Save(mp3.albumcoverpfad[a][i]); pic.TextEncoding = TagLib.StringType.Latin1; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Type = TagLib.PictureType.FrontCover; pic.Data = TagLib.ByteVector.FromPath(mp3.albumcoverpfad[a][i]); pictures[i] = pic; } f.Tag.Pictures = pictures; f.Save(); if (mp3.dateiname[a] != mp3.newdateiname[a] && mp3.newdateiname != null) { Dateien.RenameFile(mp3.newdateiname[a], a); } f = null; return("OK"); } catch { return("WriteInfos(): Datei schreibgeschützt"); } }
private static TagLib.Id3v2.AttachedPictureFrame getCoverImage(string path) { 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(path); return pic; }
public static async void SetTagsSharp(TagsPackage tagsPck, StorageFile file, int nRetries = 5) //Using TagLibSharp { try { var fileStream = await file.OpenStreamForWriteAsync(); var tagFile = TagLib.File.Create(new StreamFileAbstraction(file.Name, fileStream, fileStream)); tagFile.Tag.Title = tagsPck.title; tagFile.Tag.Performers = new[] {tagsPck.artist}; tagFile.Tag.Album = tagsPck.album; if (tagsPck.ThumbSource != null) { TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame { TextEncoding = StringType.Latin1, Type = PictureType.FrontCover }; var uri = new Uri(tagsPck.ThumbSource); if (!uri.IsFile) { var rass = RandomAccessStreamReference.CreateFromUri(uri); IRandomAccessStream stream = await rass.OpenReadAsync(); pic.Data = ByteVector.FromStream(stream.AsStream()); pic.MimeType = "image/jpeg"; stream.Dispose(); } else { StorageFile thumb = await StorageFile.GetFileFromPathAsync(tagsPck.ThumbSource); var thumbStream = await thumb.OpenStreamForReadAsync(); pic.Data = ByteVector.FromFile(new StreamFileAbstraction("Cover", thumbStream, thumbStream)); pic.MimeType = thumb.Name.Contains(".png") ? "image/png" : "image/jpeg"; thumbStream.Dispose(); } tagFile.Tag.Pictures = new IPicture[1] {pic}; } tagFile.Save(); fileStream.Dispose(); } catch (Exception exc) { Debug.WriteLine("TagsProcessing : " + exc.Message); await Task.Delay(TimeSpan.FromSeconds(5)); if (nRetries >= 0) SetTagsSharp(tagsPck, file, nRetries - 1); } }
public bool AddArtwork(string fp) { if (System.IO.File.Exists(fp)) { TagLib.Picture picture = new Picture(fp); 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 IPicture[1]; pictFrames[0] = (IPicture)albumCoverPictFrame; this.Tags.Pictures = pictFrames; DebugHelper.WriteLine(this.FileName + " --> embedded artwork"); return(IsModified = true); } return(false); }
public void AddArtwork(Image img) { MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] myBytes = ms.ToArray(); ByteVector byteVector = new ByteVector(myBytes, myBytes.Length); TagLib.Picture picture = new Picture(byteVector); TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(picture); albumCoverPictFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; this.Tags.Pictures = new IPicture[1] { (IPicture)albumCoverPictFrame }; DebugHelper.WriteLine(this.FileName + " --> embedded artwork"); IsModified = true; }
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(); }
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; }
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); }
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(); } }
public async Task <SongData> GetAlbumArt(int songId) { var filename = _dbContext.Songs.FirstOrDefault(song => song.Id == songId)?.Filename; if (filename == null) { return(null); } var file = TagLib.File.Create(filename); if (file.Tag.Pictures.Length < 1) { var albumSongLink = _dbContext.AlbumSongLinks.Include(_ => _.Album).FirstOrDefault(_ => _.SongId == songId); if (albumSongLink == null) { return(null); } var(dbArtData, dbArtMimeType) = await _vgmdbLookupHandler.GetAlbumArt(albumSongLink.Album.VgmdbLink); if (dbArtData == null || dbArtMimeType == null) { return(null); } var picture = new TagLib.Picture(new TagLib.ByteVector(dbArtData)); var pictureFrame = new TagLib.Id3v2.AttachedPictureFrame(picture) { Type = TagLib.PictureType.FrontCover }; TagLib.IPicture[] frames = { pictureFrame }; file.Tag.Pictures = frames; file.Save(); } var art = file.Tag.Pictures[0]; var songData = new SongData(art.MimeType, art.Data.Data); return(songData); }
private IPicture GeneratePicture() { if (CoverUrl == null || CoverUrl.Equals(string.Empty)) { return(null); } byte[] imageBytes; using (WebClient client = new WebClient()) { imageBytes = client.DownloadData(CoverUrl); } TagLib.Id3v2.AttachedPictureFrame cover = new TagLib.Id3v2.AttachedPictureFrame { Type = PictureType.FrontCover, Description = "Cover", MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg, Data = imageBytes, TextEncoding = StringType.UTF16 }; return(cover); }
public void SetAlbumArt(BitmapImage bi, TagLib.File file) { byte[] imageBytes; try { imageBytes = ImageToByte(bi); 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.Tag.Performers = new string[] { playerInfo.Artist ?? string.Empty }; file.Tag.Title = playerInfo.Title; file.Tag.Album = playerInfo.Album; } catch { } }
private async Task applyAll() { progressBar1.Step = 1; //method to apply changes to all songs //since we are not stupid, we will only apply Artist, Genre and Album Art progressBar1.Maximum = audioFiles.Count; foreach (var item in audioFiles) { TagLib.File f = TagLib.File.Create(item.FileName); f.Tag.Album = album.Text; for (int i = 0; i < f.Tag.Artists.Length; i++) { f.Tag.Artists[i] = artist.Text; } for (int i = 0; i < f.Tag.Genres.Length; i++) { //set every genre to the genre. f.Tag.Genres[i] = genre.Text; } MemoryStream ms = new MemoryStream(); albumArt.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] myBytes = ms.ToArray(); ByteVector byteVector = new ByteVector(myBytes, myBytes.Length); TagLib.Picture picture = new Picture(byteVector); TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(picture); albumCoverPictFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; IPicture converted = (IPicture)albumCoverPictFrame; for (int i = 0; i < f.Tag.Pictures.Length; i++) { f.Tag.Pictures[i] = converted; } f.Save(); progressBar1.PerformStep(); } }
public void SetTags(string band, int year, string album, string title, string composer, string[] picturepath) { if (_mp3file == null) { _mp3file = TagLib.File.Create(_filename); } _mp3file.Tag.Artists = new string[] { band }; _mp3file.Tag.Performers = new string[] { band }; _mp3file.Tag.AlbumArtists = new string[] { band }; _mp3file.Tag.Composers = new string[] { composer }; _mp3file.Tag.Year = (uint)year; _mp3file.Tag.Album = album; _mp3file.Tag.Title = title; if (picturepath.Length != 0) { int pn = new Random(DateTime.Now.Millisecond).Next(0, picturepath.Length); if (pn > 0) { int i = 0; } // var pictures = new TagLib.Picture[1]; 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(picturepath[pn]); // save picture to file _mp3file.Tag.Pictures = new TagLib.IPicture[1] { pic }; } }
public bool AddArtwork(string fp) { if (System.IO.File.Exists(fp)) { TagLib.Picture picture = new Picture(fp); 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 IPicture[1]; pictFrames[0] = (IPicture)albumCoverPictFrame; this.Tags.Pictures = pictFrames; DebugHelper.WriteLine(this.FileName + " --> embedded artwork"); return IsModified = true; } return false; }
private void customButton1_Click(object sender, EventArgs e) { Form1 Form1Instance = (Form1)Application.OpenForms["Form1"]; //Ανιχνεύω την παρουσία του Form1 if (_FilePaths == null || _FilePaths.Length == 0) //Αν έχει φορτωθεί μόνο ένα τραγούδι { TagLib.File Song = TagLib.File.Create(Filepath); //Δημιουργία αντικειμένου TagLib.File από την διαδρομή αρχείου του τραγουδιού //Ανάθεση των ετικετών του τραγουδιού μέσω των πεδίων εισόδου του παραθύρου Song.Tag.Title = titletextbox.Text; Song.Tag.Album = albumtextbox.Text; Song.Tag.Year = Convert.ToUInt32(yeartextbox.Text); Song.Tag.Track = Convert.ToUInt32(tracktextbox.Text); Song.Tag.Comment = commenttextbox.Text; Song.Tag.Genres = MultipleValuesProcessor(genretextbox.Text.Split(',').ToArray()); Song.Tag.Performers = MultipleValuesProcessor(artisttextbox.Text.Split(',').ToArray()); //Αν έχει επιλεχθεί τοπικά εικόνα για το άλμπουμ, τότε την αναθέτω στο τραγούδι if (AlbumArtPath != null) { 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(AlbumArtPath); Song.Tag.Pictures = new TagLib.IPicture[1] { pic }; } //Αν έχει ληφθεί online η εικόνα, τότε την αναθέτω στο τραγούδι if (DownloaderAlbumArtPath != null) { TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame(); pic.TextEncoding = StringType.Latin1; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Type = PictureType.FrontCover; pic.Data = ByteVector.FromPath(DownloaderAlbumArtPath); Song.Tag.Pictures = new IPicture[1] { pic }; } Song.Save(); AddRecentSong(Form1Instance, Song, Filepath); } else { //Αν έχουν επιλεχθεί πολλά τραγούδια, τότε ακολουθώ την ίδια διαδικασία που ακολουθώ για ένα τραγούδι, για κάθε τραγούδι for (int i = 0; i < _FilePaths.Length; i++) { TagLib.File song = TagLib.File.Create(_FilePaths[i]); if (titletextbox.Text != "<Διατήρηση τιμής>") { song.Tag.Title = titletextbox.Text; } if (artisttextbox.Text != "<Διατήρηση τιμής>") { song.Tag.Performers = MultipleValuesProcessor(artisttextbox.Text.Split(',').ToArray()); } if (albumtextbox.Text != "<Διατήρηση τιμής>") { song.Tag.Album = albumtextbox.Text; } if (yeartextbox.Text != "<Διατήρηση τιμής>") { song.Tag.Year = Convert.ToUInt32(yeartextbox.Text); } if (tracktextbox.Text != "<Διατήρηση τιμής>") { song.Tag.Track = Convert.ToUInt32(tracktextbox.Text); } if (genretextbox.Text != "<Διατήρηση τιμής>") { song.Tag.Genres = MultipleValuesProcessor(genretextbox.Text.Split(',').ToArray()); } if (commenttextbox.Text != "<Διατήρηση τιμής>") { song.Tag.Comment = commenttextbox.Text; } if (AlbumArtPath != null) { 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(AlbumArtPath); song.Tag.Pictures = new TagLib.IPicture[1] { pic }; } if (DownloaderAlbumArtPath != null) { 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(DownloaderAlbumArtPath); song.Tag.Pictures = new TagLib.IPicture[1] { pic }; } song.Save(); AddRecentSong(Form1Instance, song, _FilePaths[i]); } } }
private void openButton_Click(object sender, EventArgs e) { CommonOpenFileDialog dialog = new CommonOpenFileDialog() { InitialDirectory = "D:\\Download\\" }; if (fileRadio.Checked == true) { dialog.Multiselect = true; } else { dialog.IsFolderPicker = true; } string[] files; string[] artists = { "" }; bool good = false; TagLib.File targetFile; TagLib.Id3v2.AttachedPictureFrame pic; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { good = true; } if (dialog.IsFolderPicker == true) { files = Directory.GetFiles(dialog.FileName); } else { files = dialog.FileNames.ToArray(); } if (good == true) { if (dispRadio.Checked == true) { for (int i = 0; i < files.Length; i += 2) { outText.AppendText(files[i].Split('-').Last().Split('.')[0].Trim(' ')); outText.AppendText(Environment.NewLine); } outText.AppendText("Done"); outText.AppendText(Environment.NewLine); } else { if (folderRadio.Checked == true) { for (int i = 0; i < files.Length - 1; i++) { if (files[i].Split('\\').Last().Split('_')[0] == files[i + 1].Split('\\').Last().Split('_')[0] && files[i].Split('.').Last() == "mp3" || files[i].Split('.').Last() == "wav") { pic = new TagLib.Id3v2.AttachedPictureFrame() { TextEncoding = TagLib.StringType.Latin1, MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg, Type = TagLib.PictureType.FrontCover, Data = TagLib.ByteVector.FromPath(files[i + 1]) }; targetFile = TagLib.File.Create(files[i]); targetFile.Tag.Pictures = new TagLib.IPicture[1] { pic }; targetFile.Tag.Album = files[i].Split('\\').Last().Split('_')[0]; artists[0] = files[i].Split('-').Last().Split('.')[0].Trim(' '); targetFile.Tag.AlbumArtists = artists; targetFile.Save(); } } } else { if (artGood == true) { for (int i = 0; i < files.Length; i++) { pic = new TagLib.Id3v2.AttachedPictureFrame() { TextEncoding = TagLib.StringType.Latin1, MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg, Type = TagLib.PictureType.FrontCover, Data = TagLib.ByteVector.FromPath(art) }; targetFile = TagLib.File.Create(files[i]); targetFile.Tag.Pictures = new TagLib.IPicture[1] { pic }; targetFile.Save(); } } else { outText.AppendText("Need art"); outText.AppendText(Environment.NewLine); } } outText.AppendText("Done"); outText.AppendText(Environment.NewLine); } } else { outText.AppendText("Not good"); outText.AppendText(Environment.NewLine); } }
private void UpdateTags() { try { TagLib.File file = TagLib.File.Create(filePath); if (coverImageBytes != null) { TagLib.Picture picture = new TagLib.Picture(new ByteArrayFileAbstraction("test", coverImageBytes)); TagLib.Id3v2.AttachedPictureFrame coverPictureFrame = new TagLib.Id3v2.AttachedPictureFrame(picture); coverPictureFrame.MimeType = MediaTypeNames.Image.Jpeg; coverPictureFrame.Type = TagLib.PictureType.FrontCover; file.Tag.Pictures = new TagLib.IPicture[] { coverPictureFrame }; } else { file.Tag.Pictures = new TagLib.IPicture[0]; } file.Tag.Performers = new string[] { Artist }; file.Tag.Title = Title; file.Tag.AlbumArtists = new string[] { AlbumArtist }; file.Tag.Album = Album; if (Genre != null) file.Tag.Genres = new string[] { Genre }; file.Tag.Year = uint.Parse(Year); file.Save(); file.Dispose(); } catch (Exception ex) { SendErrorMessage(ex.Message); } }
public async Task DownloadTrack(MusixSongResult Track, string OutputDirectory, AudioEffectStack Effects = null, CancellationToken cancellationToken = default) { int Steps; int Step = 0; if (Effects == null) { Steps = 9; } else { Steps = 9 + Effects.EffectCount; } TryCallback(Step, Steps, "Starting Download", Track); if (cancellationToken.IsCancellationRequested) { return; } bool HasEffects = Effects != null; if (HasEffects) { Console.WriteLine("Has Effects"); if (string.IsNullOrEmpty(Effects.AudioCachePath)) { Effects.AudioCachePath = AudioCache; } } // Step 1 Step++; TryCallback(Step, Steps, "Preparing Download", Track); Console.WriteLine("Start Download"); if (!Track.HasVideo) { Console.WriteLine("No Vid"); } if (!Track.HasVideo) { return; } string SourceAudio = Path.Combine(AudioCache, $"audio_source_{DateTime.Now.Ticks}"); string AlbumCover = Path.Combine(ImageCachePath, $"cover_{DateTime.Now.Ticks}.jpg"); string OutputFile = Path.Combine(OutputDirectory, FileHelpers.ScrubFileName($"{Track.SpotifyTrack.Artists[0].Name} - {Track.SpotifyTrack.Name.Replace("?", "").Trim(' ')}.mp3")); string MidConversionFile = Path.Combine(AudioCache, FileHelpers.ScrubFileName($"MidConversion_{DateTime.Now.Ticks}.mp3")); // Step 2 Step++; TryCallback(Step, Steps, "Aquiring streams", Track); StreamManifest StreamData = await YouTube.Videos.Streams.GetManifestAsync(Track.YoutubeVideo.Id); if (cancellationToken.IsCancellationRequested) { return; } // Step 3 Step++; TryCallback(Step, Steps, "Sorting Streams", Track); List <AudioOnlyStreamInfo> AudioStreams = StreamData.GetAudioOnlyStreams().ToList(); AudioStreams.OrderBy(dat => dat.Bitrate); if (AudioStreams.Count() == 0) { Console.WriteLine("No Streams"); } if (AudioStreams.Count() == 0) { return; } IAudioStreamInfo SelectedStream = AudioStreams[0]; // Step 4 Step++; TryCallback(Step, Steps, "Starting downloads", Track); if (cancellationToken.IsCancellationRequested) { return; } //Task AudioDownloadTask = new Task(async () => await YouTube.Videos.Streams.DownloadAsync(SelectedStream, SourceAudio)); var req = WebRequest.CreateHttp(SelectedStream.Url); req.Method = "GET"; using (var resp = req.GetResponse()) using (var network = resp.GetResponseStream()) using (var fs = new FileStream(SourceAudio, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { Console.WriteLine("Downloading"); await network.CopyToAsync(fs); Console.WriteLine("flushing"); await fs.FlushAsync(); Console.WriteLine("done"); } WebClient WebCl = new WebClient(); Step++; TryCallback(Step, Steps, "Starting", Track); SpotifyImage Cover = Track.SpotifyTrack.Album.Images[0]; var CoverDownloadTask = new Task(() => { Console.WriteLine("Downloading Cover"); WebCl.DownloadFile(new Uri(Cover.Url), AlbumCover); } ); CoverDownloadTask.Start(); Step++; TryCallback(Step, Steps, "Waiting for downloads", Track); if (cancellationToken.IsCancellationRequested) { return; } //if (!AudioDownloadTask.IsCompleted) //{ // Console.WriteLine("Waiting on artwork..."); // CoverDownloadTask.Wait(); //} if (cancellationToken.IsCancellationRequested) { return; } //if (!AudioDownloadTask.IsCompleted) //{ // Console.WriteLine("Waiting on audio..."); // AudioDownloadTask.Wait(); // Console.WriteLine("Download Complete."); //} Thread.Sleep(100); if (cancellationToken.IsCancellationRequested) { return; } string ConversionFile = OutputFile; if (HasEffects) { ConversionFile = MidConversionFile; } if (File.Exists(OutputFile)) { File.Delete(OutputFile); } if (File.Exists(ConversionFile)) { File.Delete(ConversionFile); } Step++; TryCallback(Step, Steps, "Transcoding audio to mp3", Track); // Step 8 Console.WriteLine("Starting Conversion..."); await ConversionsProvider.Convert(SourceAudio, ConversionFile); Console.WriteLine("Conversion Complete."); // Step 9 if (cancellationToken.IsCancellationRequested) { return; } if (HasEffects) { Step++; int InternalStep = Step; TryCallback(Step, Steps, "Applying audio effects", Track); Effects.ApplyEffects(ConversionFile, OutputFile, (step, stepmax, status, download) => { step++; TryCallback(Step, Steps, status, Track); }, cancellationToken); } if (cancellationToken.IsCancellationRequested) { return; } Step++; TryCallback(Step, Steps, "Applying ID3 metadata tags", Track); // Step 10 TagLib.Id3v2.Tag.DefaultVersion = 3; TagLib.Id3v2.Tag.ForceDefaultVersion = true; TagLibFile TLF = TagLibFile.Create(OutputFile); TagLibPicture Pic = new TagLibPicture(AlbumCover); TagLib.Id3v2.AttachedPictureFrame Frame = new TagLib.Id3v2.AttachedPictureFrame(Pic) { MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg }; Pic.Type = TagLib.PictureType.FrontCover; TagLib.IPicture[] Pics = { Pic }; TLF.Tag.Pictures = Pics; TLF.Tag.Title = Track.SpotifyTrack.Name.Split('-')[0].Trim(' '); TLF.Tag.Album = Track.SpotifyTrack.Album.Name; TLF.Tag.AlbumArtists = Track.SpotifyTrack.Album.Artists.CastEnumerable(x => x.Name).ToArray(); TLF.Tag.Disc = (uint)Track.SpotifyTrack.DiscNumber; TLF.Tag.AlbumSort = Track.SpotifyTrack.Album.AlbumType; DateTime?DT = GetDate(Track.SpotifyTrack.Album.ReleaseDate); if (DT.HasValue) { TLF.Tag.Year = (uint)DT.Value.Year; } if (cancellationToken.IsCancellationRequested) { return; } TLF.Save(); // Clean Up // Step 11 Step++; TryCallback(Step, Steps, "Cleaning up", Track); WebCl.Dispose(); TLF.Dispose(); Console.WriteLine("Done."); OnMusixDownloadComplete?.Invoke(Track); }
private void DownloadFileCompleted(DownloadProgress downloadProgress, object s, AsyncCompletedEventArgs e) { (s as WebClient).DownloadFileCompleted -= (sender, ee) => DownloadFileCompleted(downloadProgress, sender, ee); (s as WebClient).DownloadProgressChanged -= (_, ee) => DownloadProgressChanged(downloadProgress, ee.BytesReceived, ee.TotalBytesToReceive); if (e.Cancelled) { downloadProgress.Report(new DownloadInfo { IsCompleted = true, RecievedBytes = downloadProgress.Info.RecievedBytes, TotalBytes = downloadProgress.Info.TotalBytes, Speed = 0, Result = "取消" }); return; } if (e.Error != null) { downloadProgress.Report(new DownloadInfo { IsCompleted = true, RecievedBytes = downloadProgress.Info.RecievedBytes, TotalBytes = downloadProgress.Info.TotalBytes, Speed = 0, Result = $"错误:{e.Error.Message}" }); return; } if (downloadProgress.Type == 0) /*是音乐就给音乐添加信息*/ { Task.Run(async() => { if (!File.Exists(downloadProgress.FilePath)) { return; } var coverAndDetail = await _NeteaseCloudMusicService.GetCoverAndDetailAsync(downloadProgress.No); try { TagLib.File file = TagLib.File.Create(downloadProgress.FilePath); TagLib.Id3v2.AttachedPictureFrame cover = new TagLib.Id3v2.AttachedPictureFrame { Type = TagLib.PictureType.FrontCover, Description = "Cover", MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg, Data = coverAndDetail.cover.ToBytes(), TextEncoding = TagLib.StringType.UTF16 }; file.Tag.Pictures = new TagLib.IPicture[] { cover }; file.Tag.Performers = coverAndDetail.detail.songs[0].artists.Select(t => t.name).ToArray(); file.Tag.Title = coverAndDetail.detail.songs[0].name; file.Tag.Album = coverAndDetail.detail.songs[0].album.name; file.Save(); } catch { } }); } downloadProgress.Report(new DownloadInfo { IsCompleted = true, RecievedBytes = downloadProgress.Info.RecievedBytes, TotalBytes = downloadProgress.Info.TotalBytes, Speed = 0, Result = "完成" }); }
public void doMe(object num) { LastFMWorker last = (LastFMWorker)num; last.busy = true; int count = last.id; int arcount = last.orignial_index; try { XmlDocument xdoc; XmlNode node; double confidence; string artist; string title; string mbid; LastFmLib.API20.Types.TrackInformation tr; string cd = ""; ListViewItem item1; updateTdisplay(count, 4); string xmlsreing = HBPUID.GenUID.LastFM.Run(last.filename, 0).Trim(); updateTdisplay(count, 2); xdoc = new XmlDocument(); xdoc.LoadXml(xmlsreing); node = xdoc.SelectSingleNode("//lfm/tracks/track"); confidence = 0; double.TryParse(xdoc.SelectSingleNode("//lfm/tracks/track/@rank").InnerText, out confidence); confidence = confidence * 100; artist = node.SelectSingleNode("//track/artist/name").InnerText; title = node.SelectSingleNode("//track/name").InnerText; mbid = node.SelectSingleNode("//track/mbid").InnerText; string largim = null ; try { largim = xdoc.SelectNodes("//lfm/tracks/track/image").Item(3).InnerXml; } catch (Exception imagex) { } if (largim != null) { TagLib.File tfile; string localFilename = @"c:\temp.jpg"; using (WebClient client = new WebClient()) { client.DownloadFile(largim, localFilename); } tfile = TagLib.File.Create(last.filename); TagLib.Picture picture = new TagLib.Picture(localFilename); 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 IPicture[1]; pictFrames[0] = (IPicture)albumCoverPictFrame; tfile.Tag.Pictures = pictFrames; if (mbid != null) { tfile.Tag.MusicBrainzTrackId = mbid; } tfile.Save(); } item1 = new ListViewItem(confidence.ToString()); if (mbid.Length > 2) { tr = client.Track.GetInfo(new Guid(mbid)); } else { tr = client.Track.GetInfo(new LastFmLib.API20.Types.Track(artist, title)); //client.Track. } string tt1 = HttpGetTrackInfo("", artist, title, "868b33aa44239a11ebd04e58e7e484ff"); dynamic json = JValue.Parse(tt1); TagLib.File mp3file; mp3file = TagLib.File.Create(last.filename); try { if (json.track != null) { if (json.track.name != null) { mp3file.Tag.Title = (string)json.track.name; } if (json.track.mbid != null) { mp3file.Tag.MusicBrainzTrackId = (string)json.track.mbid; } if (json.track.url != null) { mp3file.Tag.Lyrics = (string)json.track.url; } if (json.track.album != null) { if (json.track.album.title != null) { mp3file.Tag.Album = (string)json.track.album.title; } if (json.track.album.mbid != null) { mp3file.Tag.MusicBrainzReleaseId = (string)json.track.album.mbid; } if (json.track.album.@attr != null) { if ([email protected] != null) { mp3file.Tag.Track = (uint)json.track.album.attr.position; } } } if (json.track.artist != null) { if (json.track.artist.name != null) { mp3file.Tag.AlbumArtists[0] = (string)json.track.artist.name; } if (json.track.artist.mbid != null) { mp3file.Tag.MusicBrainzArtistId = (string)json.track.artist.mbid; } } if (json.track.toptags != null) { if (json.track.toptags.tag != null) { if (json.track.toptags.tag[0].name != null) { mp3file.Tag.Genres[0] = (string)json.track.toptags.tag[0].name; } } } } } catch (Exception ex11) { } mp3file.Save(); //client.Album.Search( XmlDocument xdoc2 = new XmlDocument(); xdoc2.LoadXml("<xml>" + tr.innerxml + "</xml>"); try { string albumname; string track; albumname = xdoc2.SelectSingleNode("//album/title").InnerText; track = xdoc2.SelectSingleNode("//album/@position").InnerText; if (albumname != null) { cd = albumname; } else { TagLib.File tfile; tfile = TagLib.File.Create(last.filename); if (tfile.Tag.Album != null) { cd = tfile.Tag.Album; } } if (track != null) { } } catch (Exception ex) { //Album retrieval failed , lets load the old album back shall we TagLib.File tfile; tfile = TagLib.File.Create(last.filename); if (tfile.Tag.Album != null) { cd = tfile.Tag.Album; } } item1.SubItems.Add(title); item1.SubItems.Add(cd); item1.SubItems.Add(artist); this.mainC1.listView1.Invoke(new MethodInvoker(delegate { this.mainC1.listView1.Items[arcount].BackColor = Color.LightGray; this.progressBar1.Value += 1; double perc = ((this.progressBar1.Value * 100) / this.progressBar1.Maximum); this.label1.Text = perc.ToString() + " %"; string no = this.mainC1.listView1.Items[arcount].SubItems[4].Text; item1.SubItems.Add(no); item1.SubItems.Add(this.mainC1.listView1.Items[arcount].SubItems[0].Text); })); AddListBoxItem(item1); last.status = false; last.busy = false; doEndLast(last.id); } catch (Exception e1) { TagLib.File mp3file; mp3file = TagLib.File.Create(last.filename); Regex rgx = new Regex("[^a-zA-Z0-9'&(). -]"); bool gotart = false; bool gottrack = false; dynamic json = ""; try { string tt1 = HttpGetTrackInfo("", rgx.Replace(mp3file.Tag.AlbumArtists[0].ToString(), ""), rgx.Replace(mp3file.Tag.Title , "") , "868b33aa44239a11ebd04e58e7e484ff"); json = JValue.Parse(tt1); if (json.track != null) { if (json.track.name != null) { gotart = true; mp3file.Tag.Title = (string)json.track.name; } if (json.track.mbid != null) { mp3file.Tag.MusicBrainzTrackId = (string)json.track.mbid; } if (json.track.url != null) { mp3file.Tag.Lyrics = (string)json.track.url; } if (json.track.album != null) { if (json.track.album.title != null) { mp3file.Tag.Album = (string)json.track.album.title; } if (json.track.album.mbid != null) { mp3file.Tag.MusicBrainzReleaseId = (string)json.track.album.mbid; } if (json.track.album.@attr != null) { if ([email protected] != null) { mp3file.Tag.Track = (uint)json.track.album.attr.position; } } } if (json.track.artist != null) { if (json.track.artist.name != null) { gottrack = true; mp3file.Tag.AlbumArtists[0] = (string)json.track.artist.name; } if (json.track.artist.mbid != null) { mp3file.Tag.MusicBrainzArtistId = (string)json.track.artist.mbid; } } if (json.track.toptags != null) { if (json.track.toptags.tag != null) { if (json.track.toptags.tag[0].name != null) { mp3file.Tag.Genres[0] = (string)json.track.toptags.tag[0].name; } } } } } catch (Exception ex11) { } if (gottrack && gotart) { ListViewItem item1 = new ListViewItem("0"); item1.SubItems.Add((string)json.track.name); item1.SubItems.Add(mp3file.Tag.Album); item1.SubItems.Add((string)json.track.artist.name); this.mainC1.listView1.Invoke(new MethodInvoker(delegate { this.mainC1.listView1.Items[arcount].BackColor = Color.LightGray; this.progressBar1.Value += 1; double perc = ((this.progressBar1.Value * 100) / this.progressBar1.Maximum); this.label1.Text = perc.ToString() + " %"; string no = this.mainC1.listView1.Items[arcount].SubItems[4].Text; item1.SubItems.Add(no); item1.SubItems.Add(this.mainC1.listView1.Items[arcount].SubItems[0].Text); })); AddListBoxItem(item1); } else { this.mainC1.listView1.Invoke(new MethodInvoker(delegate { this.progressBar1.Value += 1; this.mainC1.listView1.Items[arcount].BackColor = Color.LightPink; double perc = ((this.progressBar1.Value * 100) / this.progressBar1.Maximum); this.label1.Text = perc.ToString() + " %"; })); } try { mp3file.Save(); } catch (Exception nex1) { } updateTdisplay(count, 3); last.status = false; last.busy = false; doEndLast(last.id); } }
public bool Guardar_Pista() { TagLib.File PistaMp3 = TagLib.File.Create(ruta); PistaMp3.Tag.Clear(); PistaMp3.Tag.Performers = new string[] { Artista }; PistaMp3.Tag.AlbumArtists = new string[] { Artista }; PistaMp3.Tag.Album = Album; PistaMp3.Tag.Year = (uint) Anyo; PistaMp3.Tag.Genres = new string[] { Genero }; PistaMp3.Tag.Comment = Comentario; PistaMp3.Tag.Title = Titulo; PistaMp3.Tag.Track = (uint)Indice; string rutaAuxiliar = Path.GetTempFileName(); caratulaAlbum.Save(rutaAuxiliar, System.Drawing.Imaging.ImageFormat.Jpeg); TagLib.Picture myCover = new Picture(rutaAuxiliar); //Coloco el Picture en el FrameCorrespondiente TagLib.Id3v2.AttachedPictureFrame coverAlbumArt = new TagLib.Id3v2.AttachedPictureFrame(myCover); //Seteo el tipo Mime coverAlbumArt.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; //Seteo el tipo de imagen que estoy colocando coverAlbumArt.Type = TagLib.PictureType.FrontCover; //Agrego el frame a la coleccion de imagenes que corresponde TagLib.IPicture[] pictFrame = { coverAlbumArt }; //Vuelco la coleccion de imagenes al Tag try { PistaMp3.Tag.Pictures = pictFrame; } catch { //MessageBox.Show("Imposible Insercion de Imagen en Tag. Posible Error de Archivo -" + new FileInfo(RutaArchivo).FullName + "-"); } System.IO.File.Delete(rutaAuxiliar); try { PistaMp3.Save(); PistaMp3.Dispose(); return true; } catch { PistaMp3.Dispose(); return false; } }
/// <summary> /// Добавляет к файлу обложку /// </summary> /// <param name="mp3_path">Путь к MP3 файлу</param> /// <param name="cover_path">Путь к обложке</param> private void assignCover(string mp3_path, string cover_path) { try { // Формируем картинку в кадр Id3v2 TagLib.Picture pic = new TagLib.Picture(cover_path); TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(pic); albumCoverPictFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; TagLib.IPicture[] ipic = { albumCoverPictFrame }; // Открываем файл TagLib.File file = TagLib.File.Create(mp3_path); file.Tag.Pictures = ipic; file.Save(); } catch (Exception e) { Error("Ошибка сохранения файла."); } }
private void anyadir_Caratula(object sender, EventArgs e) { if (vistalista.SelectedItems.Count == 1) { var fileContent = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { vistalista.Clear(); columns(); openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); openFileDialog.Filter = "All files (*.*)|*.*|PNG files (*.*)|*.png*|JPG files (*.jpg)|*.jpg"; openFileDialog.FilterIndex = 3; //Number Filter of Names and Extensions openFileDialog.RestoreDirectory = true; openFileDialog.Multiselect = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { string[] filePath = openFileDialog.FileNames; int pathLimit = filePath.Length - 1; int pathCount = 0; foreach (string fileName in openFileDialog.SafeFileNames) { if (pathLimit == -1) { //Get the path of specified file string filePathOne = openFileDialog.FileName; //Read the contents of the file into a stream var fileStream = openFileDialog.OpenFile(); string[] ext = fileName.Split('.'); TagLib.File tgFile = TagLib.File.Create(filePath[pathCount]); //Add Cover CD (To PictureBox1) Image bitmap = Image.FromFile(filePathOne); pictureBox1.Image = bitmap; //And to the file Etiqueta et = new Etiqueta(); MemoryStream albmStream = new MemoryStream(tgFile.Tag.Pictures[0].Data.Data); if ((ext[ext.Length - 1] == "jpg") || (ext[ext.Length - 1] == "JPG")) { bitmap.Save(albmStream, ImageFormat.Jpeg); } et.SetImg(albmStream); TagLib.Picture picture = new TagLib.Picture(new TagLib.ByteVector(albmStream.ToArray())); TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(picture); albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; TagLib.IPicture[] pictFrames = { albumCoverPictFrame }; tags.Pictures = pictFrames; InfoMP(fileName, filePathOne); } else { if (pathCount <= pathLimit) { var fileStream = openFileDialog.OpenFile(); InfoMP(fileName, filePath[pathCount]); pathCount++; string[] ext = fileName.Split('.'); TagLib.File tgFile = TagLib.File.Create(filePath[pathCount]); //Add Cover CD (To PictureBox1) Image bitmap = Image.FromFile(filePath[pathCount]); pictureBox1.Image = bitmap; //And to the file Etiqueta et = new Etiqueta(); MemoryStream albmStream = new MemoryStream(tgFile.Tag.Pictures[0].Data.Data); if ((ext[ext.Length - 1] == "jpg") || (ext[ext.Length - 1] == "JPG")) { bitmap.Save(albmStream, ImageFormat.Jpeg); } et.SetImg(albmStream); TagLib.Picture picture = new TagLib.Picture(new TagLib.ByteVector(albmStream.ToArray())); TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(picture); albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; TagLib.IPicture[] pictFrames = { albumCoverPictFrame }; tags.Pictures = pictFrames; } } } } } } }
public static string WriteInfos(int a) { try { TagLib.File f = TagLib.File.Create(mp3.pfad[a]); f.Tag.Title = title[a]; f.Tag.Performers[0] = artist[a]; f.Tag.Album = album[a]; f.Tag.AlbumArtists[0] = albumartist[a]; if (track[a] == -1) { } else { f.Tag.Track = Convert.ToUInt16(track[a]); } if (year[a] == -1) { } else { f.Tag.Year = Convert.ToUInt16(year[a]); } f.Tag.Genres[0] = genre[a]; f.Tag.Comment = comment[a]; if (Settings.Default.CommentChangeEnabled) { f.Tag.Comment = Settings.Default.Comment; } //albumcover TagLib.IPicture[] pictures = new IPicture[albumcover[a].Count()]; TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame(); for (int i = 1; i < albumcover[a].Count(); i++) { mp3.albumcoverpfad[a][i] = Path.GetTempPath() + i + System.DateTime.Now.GetHashCode() + ".jpg"; mp3.albumcover[a][i].Save(mp3.albumcoverpfad[a][i]); pic.TextEncoding = TagLib.StringType.Latin1; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Type = TagLib.PictureType.FrontCover; pic.Data = TagLib.ByteVector.FromPath(mp3.albumcoverpfad[a][i]); pictures[i] = pic; } f.Tag.Pictures = pictures; f.Save(); if (mp3.dateiname[a] != mp3.newdateiname[a] && mp3.newdateiname != null) { Dateien.RenameFile(mp3.newdateiname[a],a); } f = null; return "OK"; } catch { return "WriteInfos(): Datei schreibgeschützt"; } }
/// <summary> /// Gestion de changement d'image d'album /// </summary> private void pictureBox1_DragDrop(object sender, DragEventArgs e) { string[] Imageloc = (String[])e.Data.GetData(DataFormats.FileDrop); TagLib.Id3v2.AttachedPictureFrame image = new TagLib.Id3v2.AttachedPictureFrame(); image.Data = TagLib.ByteVector.FromPath(Imageloc[0]); id.Tag.Pictures = new TagLib.IPicture[1]{image} ; id.Save(); pictureBox1.ImageLocation = Imageloc[0]; Form1.changement = true; }
/// <summary> /// Modification d'image d'un Album /// </summary> private void panel2_DragDrop(object sender, DragEventArgs e) { int i; for (i = 0; i < dataGridView2.Rows.Count; i++)//Remplace l'AlbumArt de toutes les pistes de l'album { System.IO.FileInfo PisteEditer = new System.IO.FileInfo(dataGridView2.Rows[i].Cells[6].Value.ToString());//Verifie que le fichier n'est pas en ReadOnly if (PisteEditer.IsReadOnly) { MessageBox.Show("Fichier en ReadOnly, aucune edition possible"); } else { TagLib.File id = TagLib.File.Create(dataGridView2.Rows[i].Cells[6].Value.ToString()); string[] Imageloc = (String[])e.Data.GetData(DataFormats.FileDrop); TagLib.Id3v2.AttachedPictureFrame image = new TagLib.Id3v2.AttachedPictureFrame(); image.Data = TagLib.ByteVector.FromPath(Imageloc[0]); id.Tag.Pictures = new TagLib.IPicture[1] { image }; id.Save(); pictureBox3.ImageLocation = Imageloc[0]; Form1.changement = true; } } }