private void SetHighlights() { //lock (loadDurationLockObj) //{ // if (duration == nonloadedDuration) duration = GetDuration(); //} //Highlights = collections.GetHighlightCollection(this); try { TextFrame frame; ID3File id3File = new ID3File(FullPath); Highlights = TryFindHighlightsFrame(id3File?.ID3v2Tag?.Frames, out frame) ? DeserializeHighlights(frame.Text) : new HighlightCollection(); Highlights.CollectionChanged += Highlights_CollectionChanged; foreach (Highlight highlight in Highlights) { highlight.BeginChanged += Highlight_BeginChanged; highlight.EndChanged += Highlight_EndChanged; } } catch { Highlights = new HighlightCollection(); } }
/// <summary> /// Copies values from a specified <see cref="ID3File" /> to a new instance of <see cref="StorableTaggedFile" /> /// </summary> /// <param name="file"></param> /// <returns></returns> public static StorableTaggedFile Copy(ID3File file) { var alb = file.Album.Trim(); alb = string.IsNullOrEmpty(alb) ? Unknown : alb; var art = file.Artist.Trim(); art = string.IsNullOrEmpty(art) ? Unknown : art; var gen = file.Genre.Trim(); gen = string.IsNullOrEmpty(gen) ? Unknown : gen; var tit = file.Title.Trim(); tit = string.IsNullOrEmpty(tit) ? file.Filename : tit; var artistId = GenerateLowerCaseId(art, ArtistNamespace); var albumId = GenerateLowerCaseId(alb, AlbumNamespace); var genreId = GenerateLowerCaseId(gen, GenreNamespace); var titleId = GenerateLowerCaseId(tit, TitleNamespace); var yearId = GenerateLowerCaseId(file.Year.ToString(CultureInfo.InvariantCulture), YearNamespace); var filename = file.Filename; return(new StorableTaggedFile { Id = GenerateLowerCaseId(filename, FilenameNamespace), Comment = file.Comment, Filename = filename, TrackNo = file.TrackNo, Duration = file.Duration, StorageType = StorageTypes.SystemFile, Album = new Album { Name = alb, Id = albumId, }, Artist = new Artist { Name = art, Id = artistId, }, Genre = new Genre { Name = gen, Id = genreId, }, Title = new Title { Name = tit, Id = titleId, }, Year = new Year { Value = file.Year, Id = yearId, }, }); }
public void LoadID3(string file) { ID3File iD3File = new ID3File(file); iD3File.Save(Source); Reload(); FileName.FileName = Path.GetFileNameWithoutExtension(file); }
public void SaveHighlights() { try { TextFrame frame; ID3File id3File = new ID3File(FullPath); if (id3File.ID3v2Tag == null) { id3File.ID3v2Tag = new ID3v2Tag(); } if (!TryFindHighlightsFrame(id3File.ID3v2Tag.Frames, out frame)) { frame = FrameFactory.GetFrame(FrameFactory.UserDefinedTextFrameId) as TextFrame; id3File.ID3v2Tag.Frames.Add(frame); } if (Highlights.Count > 0) { frame.Text = SerializeHighlights(Highlights); } else { id3File.ID3v2Tag.Frames.Remove(frame); } id3File.Save(FullPath); HasChanges = false; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
public void Reload() { parent = new ID3File(source); if (parent.ID3v1Tag == null) { parent.ID3v1Tag = new ID3v1Tag(); } if (parent.ID3v2Tag == null) { parent.ID3v2Tag = new ID3v2Tag(); } V1Tag = new EditID3v1Tag(parent.ID3v1Tag); V2Tag = new EditID3v2Tag(parent.ID3v2Tag); Title = new PropertySynchronizer(V1Tag, V2Tag, nameof(V1Tag.Title), FrameFactory.TitleFrameId); Artist = new PropertySynchronizer(V1Tag, V2Tag, nameof(V1Tag.Artist), FrameFactory.LeadArtistFrameId, FrameFactory.BandFrameId); Album = new PropertySynchronizer(V1Tag, V2Tag, nameof(V1Tag.Album), FrameFactory.AlbumFrameId); TrackNumber = new PropertySynchronizer(V1Tag, V2Tag, nameof(V1Tag.TrackNumber), FrameFactory.TrackNumberFrameId); Year = new PropertySynchronizer(V1Tag, V2Tag, nameof(V1Tag.Year), FrameFactory.YearFrameId); FileName = new FileNameSynchronizer(this); }