| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.jaudiotagger.audio.asf.util; |
| 20 | |
|
| 21 | |
import org.jaudiotagger.audio.asf.data.AsfHeader; |
| 22 | |
import org.jaudiotagger.audio.asf.data.ContentDescription; |
| 23 | |
import org.jaudiotagger.audio.asf.data.ContentDescriptor; |
| 24 | |
import org.jaudiotagger.audio.asf.data.ExtendedContentDescription; |
| 25 | |
import org.jaudiotagger.audio.asf.tag.*; |
| 26 | |
import org.jaudiotagger.tag.Tag; |
| 27 | |
import org.jaudiotagger.tag.reference.GenreTypes; |
| 28 | |
|
| 29 | |
import java.util.Iterator; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 5 | public class TagConverter |
| 40 | |
{ |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public static void assignCommonTagValues(Tag tag, ExtendedContentDescription description) |
| 57 | |
{ |
| 58 | 13 | ContentDescriptor tmp = null; |
| 59 | 13 | if (!Utils.isBlank(tag.getFirstAlbum())) |
| 60 | |
{ |
| 61 | 8 | tmp = new ContentDescriptor(AsfFieldKey.ALBUM.getFieldName(), ContentDescriptor.TYPE_STRING); |
| 62 | 8 | tmp.setStringValue(tag.getFirstAlbum()); |
| 63 | 8 | description.addOrReplace(tmp); |
| 64 | |
} |
| 65 | |
else |
| 66 | |
{ |
| 67 | 5 | description.remove(AsfFieldKey.ALBUM.getFieldName()); |
| 68 | |
} |
| 69 | 13 | if (!Utils.isBlank(tag.getFirstTrack())) |
| 70 | |
{ |
| 71 | 8 | tmp = new ContentDescriptor(AsfFieldKey.TRACK.getFieldName(), ContentDescriptor.TYPE_STRING); |
| 72 | 8 | tmp.setStringValue(tag.getFirstTrack()); |
| 73 | 8 | description.addOrReplace(tmp); |
| 74 | |
} |
| 75 | |
else |
| 76 | |
{ |
| 77 | 5 | description.remove(AsfFieldKey.TRACK.getFieldName()); |
| 78 | |
} |
| 79 | 13 | if (!Utils.isBlank(tag.getFirstYear())) |
| 80 | |
{ |
| 81 | 8 | tmp = new ContentDescriptor(AsfFieldKey.YEAR.getFieldName(), ContentDescriptor.TYPE_STRING); |
| 82 | 8 | tmp.setStringValue(tag.getFirstYear()); |
| 83 | 8 | description.addOrReplace(tmp); |
| 84 | |
} |
| 85 | |
else |
| 86 | |
{ |
| 87 | 5 | description.remove(AsfFieldKey.YEAR.getFieldName()); |
| 88 | |
} |
| 89 | 13 | if (!Utils.isBlank(tag.getFirstGenre())) |
| 90 | |
{ |
| 91 | 8 | tmp = new ContentDescriptor(AsfFieldKey.GENRE.getFieldName(), ContentDescriptor.TYPE_STRING); |
| 92 | 8 | tmp.setStringValue(tag.getFirstGenre()); |
| 93 | 8 | description.addOrReplace(tmp); |
| 94 | 8 | Integer genreNum = GenreTypes.getInstanceOf().getIdForName(tag.getFirstGenre()); |
| 95 | 8 | if (genreNum != null) |
| 96 | |
{ |
| 97 | 0 | tmp = new ContentDescriptor(AsfFieldKey.GENRE_ID.getFieldName(), ContentDescriptor.TYPE_STRING); |
| 98 | 0 | tmp.setStringValue("(" + genreNum + ")"); |
| 99 | 0 | description.addOrReplace(tmp); |
| 100 | |
} |
| 101 | |
else |
| 102 | |
{ |
| 103 | 8 | description.remove(AsfFieldKey.GENRE_ID.getFieldName()); |
| 104 | |
} |
| 105 | 8 | } |
| 106 | |
else |
| 107 | |
{ |
| 108 | 5 | description.remove(AsfFieldKey.GENRE.getFieldName()); |
| 109 | 5 | description.remove(AsfFieldKey.GENRE_ID.getFieldName()); |
| 110 | |
} |
| 111 | 13 | } |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
public static void assignOptionalTagValues(AsfTag tag, ExtendedContentDescription descriptor) |
| 121 | |
{ |
| 122 | 13 | assert tag.isCopyingFields(); |
| 123 | 13 | Iterator<AsfTagField> it = tag.getAsfFields(); |
| 124 | 378 | while (it.hasNext()) |
| 125 | |
{ |
| 126 | 365 | ContentDescriptor contentDesc = it.next().getDescriptor(); |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | 365 | if (!descriptor.containsDescriptor(contentDesc.getName())) |
| 132 | |
{ |
| 133 | 333 | descriptor.addOrReplace(contentDesc); |
| 134 | |
} |
| 135 | 365 | } |
| 136 | 13 | } |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public static ContentDescription createContentDescription(AsfTag tag) |
| 153 | |
{ |
| 154 | 17 | ContentDescription result = new ContentDescription(); |
| 155 | 17 | result.setAuthor(tag.getFirstArtist()); |
| 156 | 17 | result.setTitle(tag.getFirstTitle()); |
| 157 | 17 | result.setComment(tag.getFirstComment()); |
| 158 | 17 | result.setCopyRight(tag.getFirstCopyright()); |
| 159 | 17 | result.setRating(tag.getFirstRating()); |
| 160 | 17 | return result; |
| 161 | |
} |
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
public static AsfTag createTagOf(AsfHeader source) |
| 172 | |
{ |
| 173 | 44 | AsfTag result = new AsfTag(true); |
| 174 | 44 | final ContentDescription contentDescription = source.findContentDescription(); |
| 175 | 44 | final ExtendedContentDescription extDesc = source.findExtendedContentDescription(); |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | 44 | if (source.findContentDescription() != null) |
| 182 | |
{ |
| 183 | 35 | result.setArtist(contentDescription.getAuthor()); |
| 184 | 35 | result.setComment(contentDescription.getComment()); |
| 185 | 35 | result.setTitle(contentDescription.getTitle()); |
| 186 | 35 | result.setCopyright(contentDescription.getCopyRight()); |
| 187 | 35 | result.setRating(contentDescription.getRating()); |
| 188 | |
} |
| 189 | |
|
| 190 | |
|
| 191 | 44 | if (extDesc != null) |
| 192 | |
{ |
| 193 | |
|
| 194 | 30 | Iterator<ContentDescriptor> it = extDesc.getDescriptors().iterator(); |
| 195 | 885 | while (it.hasNext()) |
| 196 | |
{ |
| 197 | 855 | ContentDescriptor current = it.next(); |
| 198 | 855 | if (!AsfTag.storesDescriptor(current)) |
| 199 | |
{ |
| 200 | 816 | if (current.getType() == ContentDescriptor.TYPE_BINARY) |
| 201 | |
{ |
| 202 | 16 | if(current.getName().equals(AsfFieldKey.COVER_ART.getFieldName())) |
| 203 | |
{ |
| 204 | 16 | result.add(new AsfTagCoverField(current)); |
| 205 | |
} |
| 206 | |
else |
| 207 | |
{ |
| 208 | 0 | result.add(new AsfTagField(current)); |
| 209 | |
} |
| 210 | |
} |
| 211 | |
else |
| 212 | |
{ |
| 213 | 800 | result.add(new AsfTagTextField(current)); |
| 214 | |
} |
| 215 | |
} |
| 216 | 855 | } |
| 217 | |
} |
| 218 | 44 | return result; |
| 219 | |
} |
| 220 | |
|
| 221 | |
} |