Index: src/Tag.cs =================================================================== --- src/Tag.cs (revision 48282) +++ src/Tag.cs (working copy) @@ -116,28 +116,6 @@ get; } - string FirstGenre { - get; - } - string FirstTitle { - get; - } - string FirstTrack { - get; - } - string FirstYear { - get; - } - string FirstAlbum { - get; - } - string FirstArtist { - get; - } - string FirstComment { - get; - } - bool HasCommonFields { get; } @@ -146,8 +124,6 @@ get; } - void Merge(Tag tag); - void Set(TagField field); void SetAlbum(string s); @@ -200,63 +176,8 @@ { get { return Get(CommentId); } } - - public string FirstTitle - { - get { - IList l = Get(TitleId); - return (l.Count != 0) ? (l[0] as TagTextField).Content : ""; - } - } - public string FirstAlbum - { - get { - IList l = Get(AlbumId); - return (l.Count != 0) ? (l[0] as TagTextField).Content : ""; - } - } - public string FirstArtist - { - get { - IList l = Get(ArtistId); - return (l.Count != 0) ? (l[0] as TagTextField).Content : ""; - } - } - - public string FirstGenre - { - get { - IList l = Get(GenreId); - return (l.Count != 0) ? (l[0] as TagTextField).Content : ""; - } - } - - public string FirstTrack - { - get { - IList l = Get(TrackId); - return (l.Count != 0) ? (l[0] as TagTextField).Content : ""; - } - } - - public string FirstYear - { - get { - IList l = Get(YearId); - return (l.Count != 0) ? (l[0] as TagTextField).Content : ""; - } - } - - public string FirstComment - { - get { - IList l = Get(CommentId); - return (l.Count != 0) ? (l[0] as TagTextField).Content : ""; - } - } - public void SetTitle(string s) { Set (CreateTitleField (s)); @@ -458,29 +379,7 @@ } return sb.ToString().Substring(0,sb.Length-1); } - - public void Merge(Tag tag) - { - //FIXME: Improve me, for the moment, - //it overwrites this tag with other values - //FIXME: TODO: an abstract method that merges particular things for each - //format - if( Title.Count == 0) - SetTitle(tag.FirstTitle); - if( Artist.Count == 0 ) - SetArtist(tag.FirstArtist); - if( Album.Count == 0 ) - SetAlbum(tag.FirstAlbum); - if( Year.Count == 0 ) - SetYear(tag.FirstYear); - if( Comment.Count == 0 ) - SetComment(tag.FirstComment); - if( Track.Count == 0 ) - SetTrack(tag.FirstTrack); - if( Genre.Count == 0 ) - SetGenre(tag.FirstGenre); - } - + public bool SetEncoding(string enc) { if(!IsAllowedEncoding(enc)) { return false; Index: src/Mp3/Mp3FileReader.cs =================================================================== --- src/Mp3/Mp3FileReader.cs (revision 48282) +++ src/Mp3/Mp3FileReader.cs (working copy) @@ -72,17 +72,10 @@ error += "("+e.Message+")"; } - if(v1 == null && v2 == null) - return new GenericTag(); - - if(v2 == null) { - return v1; - } - else if(v1 != null) { - v2.Merge( v1 ); + if (v2 != null && v1 != null) v2.HasId3v1 = true; - } - return v2; + + return Utils.CombineTags(v2, v1); } } } Index: src/AudioFileWrapper.cs =================================================================== --- src/AudioFileWrapper.cs (revision 48282) +++ src/AudioFileWrapper.cs (working copy) @@ -104,20 +104,69 @@ return afb.EncodingInfo.Vbr; } } - + + public string[] Genres + { + get { + return Utils.FieldListToStringArray(Tag.Genre); + } + } + + public string[] Titles + { + get { + return Utils.FieldListToStringArray(Tag.Title); + } + } + + public int[] TrackNumbers + { + get { + return Utils.FieldListToIntArray(Tag.Track); + } + } + + public int[] Years + { + get { + return Utils.FieldListToIntArray(Tag.Year); + } + } + + public string[] Albums + { + get { + return Utils.FieldListToStringArray(Tag.Album); + } + } + + public string[] Artists + { + get { + return Utils.FieldListToStringArray(Tag.Artist); + } + } + + public string[] Comments + { + get { + return Utils.FieldListToStringArray(Tag.Comment); + } + } + public string Genre { get { - return afb.Tag.FirstGenre.Equals(String.Empty) - ? null : afb.Tag.FirstGenre; + return Tag.Genre.Count > 0 ? + ((TagTextField)Tag.Genre[0]).Content : null; } } public string Title { get { - return afb.Tag.FirstTitle.Equals(String.Empty) - ? null : afb.Tag.FirstTitle; + return Tag.Title.Count > 0 ? + ((TagTextField)Tag.Title[0]).Content : null; } } @@ -125,7 +174,7 @@ { get { try { - return Convert.ToInt32(afb.Tag.FirstTrack); + return Convert.ToInt32(((TagTextField)Tag.Track[0]).Content); } catch(Exception) { return 0; } @@ -136,41 +185,41 @@ { get { try { - return Convert.ToInt32(afb.Tag.FirstYear); + return Convert.ToInt32(((TagTextField)Tag.Year[0]).Content); } catch(Exception) { return 0; } } } - + public string Album { get { - return afb.Tag.FirstAlbum.Equals(String.Empty) - ? null : afb.Tag.FirstAlbum; + return Tag.Album.Count > 0 ? + ((TagTextField)Tag.Album[0]).Content : null; } } public string Artist { get { - return afb.Tag.FirstArtist.Equals(String.Empty) - ? null : afb.Tag.FirstArtist; + return Tag.Artist.Count > 0 ? + ((TagTextField)Tag.Artist[0]).Content : null; } } public string Comment { get { - return afb.Tag.FirstComment.Equals(String.Empty) - ? null : afb.Tag.FirstComment; + return Tag.Comment.Count > 0 ? + ((TagTextField)Tag.Comment[0]).Content : null; } } public Tag Tag { get { - return afb.Tag == null ? new GenericTag() : afb.Tag; + return afb.Tag; } } Index: src/Util/Utils.cs =================================================================== --- src/Util/Utils.cs (revision 48282) +++ src/Util/Utils.cs (working copy) @@ -30,6 +30,8 @@ * */ +using System; +using System.Collections; using System.Text; namespace Entagged.Audioformats.Util { @@ -65,5 +67,57 @@ return number; } + + public static string[] FieldListToStringArray(IList taglist) + { + string[] ret = new string[taglist.Count]; + int i = 0; + foreach (TagTextField field in taglist) + ret[i++] = field.Content; + return ret; + } + + public static int[] FieldListToIntArray(IList taglist) + { + int[] ret = new int[taglist.Count]; + int i = 0; + foreach (TagTextField field in taglist) + ret[i++] = Convert.ToInt32(field.Content); + return ret; + } + + public static Tag CombineTags(params Tag[] tags) + { + Tag ret = new GenericTag(); + + foreach (Tag tag in tags) { + if (tag == null) + continue; + + foreach (TagTextField artist in tag.Artist) + ret.AddArtist (artist.Content); + + foreach (TagTextField album in tag.Album) + ret.AddAlbum (album.Content); + + foreach (TagTextField title in tag.Title) + ret.AddTitle (title.Content); + + foreach (TagTextField track in tag.Track) + ret.AddTrack (track.Content); + + foreach (TagTextField year in tag.Year) + ret.AddYear (year.Content); + + foreach (TagTextField comment in tag.Comment) + ret.AddComment (comment.Content); + + foreach (TagTextField genre in tag.Genre) + ret.AddGenre (genre.Content); + } + + return ret; + } + } } Index: src/Util/AudioFileReader.cs =================================================================== --- src/Util/AudioFileReader.cs (revision 48282) +++ src/Util/AudioFileReader.cs (working copy) @@ -64,12 +64,12 @@ EncodingInfo info = GetEncodingInfo(stream); - Tag tag; + Tag tag = null; try { stream.Seek( 0, SeekOrigin.Begin ); tag = GetTag(stream); } catch (CannotReadException e) { - tag = new GenericTag(); + // Do nothing } return new AudioFile(info, tag);