From f5f1ec336fafc27392b1a6c6726f56675585d06b Mon Sep 17 00:00:00 2001 From: tesshucom Date: Wed, 10 Apr 2019 19:24:27 +0900 Subject: [PATCH 1/3] Fix to get fields when file format is ID3v2.4 --- .../service/metadata/JaudiotaggerParser.java | 68 ++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java index ff37a78d..72a48e25 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java @@ -28,6 +28,9 @@ import org.jaudiotagger.audio.AudioFileIO; import org.jaudiotagger.audio.AudioHeader; import org.jaudiotagger.tag.FieldKey; import org.jaudiotagger.tag.Tag; +import org.jaudiotagger.tag.id3.AbstractID3Tag; +import org.jaudiotagger.tag.id3.ID3v24Frames; +import org.jaudiotagger.tag.id3.ID3v24Tag; import org.jaudiotagger.tag.images.Artwork; import org.jaudiotagger.tag.reference.GenreTypes; import org.slf4j.Logger; @@ -96,8 +99,69 @@ public class JaudiotaggerParser extends MetaDataParser { String songArtist = getTagField(tag, FieldKey.ARTIST); String albumArtist = getTagField(tag, FieldKey.ALBUM_ARTIST); - metaData.setArtist(StringUtils.isBlank(songArtist) ? albumArtist : songArtist); - metaData.setAlbumArtist(StringUtils.isBlank(albumArtist) ? songArtist : albumArtist); + + if (tag instanceof AbstractID3Tag && 0 < audioFile.getTag().getFieldCount()) { + + AbstractID3Tag id3Tag = (AbstractID3Tag)tag; + if (ID3v24Tag.RELEASE == id3Tag.getRelease() + && ID3v24Tag.MAJOR_VERSION == id3Tag.getMajorVersion() + && ID3v24Tag.REVISION == id3Tag.getRevision()) { + + audioFile.getTag().getFields().forEachRemaining(f -> { + switch (f.getId()) { + case ID3v24Frames.FRAME_ID_ALBUM: + if (null == metaData.getAlbumName()) { + metaData.setAlbumName(f.toString()); + } + break; + case ID3v24Frames.FRAME_ID_TITLE: + if (null == metaData.getTitle()) { + metaData.setTitle(f.toString()); + } + break; + case ID3v24Frames.FRAME_ID_YEAR: + if (null == metaData.getYear()) { + metaData.setYear(parseYear(f.toString())); + } + break; + case ID3v24Frames.FRAME_ID_GENRE: + if (null == metaData.getGenre()) { + metaData.setGenre(mapGenre(f.toString())); + } + break; + case ID3v24Frames.FRAME_ID_SET: + if (null == metaData.getDiscNumber()) { + metaData.setDiscNumber(parseInteger(f.toString())); + } + break; + case ID3v24Frames.FRAME_ID_TRACK: + if (null == metaData.getTrackNumber()) { + metaData.setTrackNumber(parseTrackNumber(f.toString())); + } + break; + case ID3v24Frames.FRAME_ID_ARTIST: + if (null == metaData.getArtist() && null == songArtist) { + metaData.setArtist(f.toString()); + } + break; + case ID3v24Frames.FRAME_ID_ACCOMPANIMENT: + if (null == metaData.getAlbumArtist()) { + metaData.setAlbumArtist(f.toString()); + } + break; + default: + break; + } + }); + } + } + if(StringUtils.isBlank(metaData.getArtist())) { + metaData.setArtist(StringUtils.isBlank(songArtist) ? albumArtist : songArtist); + } + if(StringUtils.isBlank(metaData.getAlbumArtist())) { + metaData.setAlbumArtist(StringUtils.isBlank(albumArtist) ? songArtist : albumArtist); + } + } AudioHeader audioHeader = audioFile.getAudioHeader(); From 133cf666b707e62ad1a908cc9fa8dfe5738222f8 Mon Sep 17 00:00:00 2001 From: tesshucom Date: Thu, 11 Apr 2019 05:26:56 +0900 Subject: [PATCH 2/3] Fix processing when artist and albumArtist are null --- .../service/metadata/JaudiotaggerParser.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java index 72a48e25..a9dd398f 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java @@ -97,8 +97,8 @@ public class JaudiotaggerParser extends MetaDataParser { metaData.setTrackNumber(parseTrackNumber(getTagField(tag, FieldKey.TRACK))); metaData.setMusicBrainzReleaseId(getTagField(tag, FieldKey.MUSICBRAINZ_RELEASEID)); - String songArtist = getTagField(tag, FieldKey.ARTIST); - String albumArtist = getTagField(tag, FieldKey.ALBUM_ARTIST); + metaData.setArtist(getTagField(tag, FieldKey.ARTIST)); + metaData.setAlbumArtist(getTagField(tag, FieldKey.ALBUM_ARTIST)); if (tag instanceof AbstractID3Tag && 0 < audioFile.getTag().getFieldCount()) { @@ -140,7 +140,7 @@ public class JaudiotaggerParser extends MetaDataParser { } break; case ID3v24Frames.FRAME_ID_ARTIST: - if (null == metaData.getArtist() && null == songArtist) { + if (null == metaData.getArtist()) { metaData.setArtist(f.toString()); } break; @@ -155,11 +155,11 @@ public class JaudiotaggerParser extends MetaDataParser { }); } } - if(StringUtils.isBlank(metaData.getArtist())) { - metaData.setArtist(StringUtils.isBlank(songArtist) ? albumArtist : songArtist); + if (StringUtils.isBlank(metaData.getArtist())) { + metaData.setArtist(metaData.getAlbumArtist()); } - if(StringUtils.isBlank(metaData.getAlbumArtist())) { - metaData.setAlbumArtist(StringUtils.isBlank(albumArtist) ? songArtist : albumArtist); + if (StringUtils.isBlank(metaData.getAlbumArtist())) { + metaData.setAlbumArtist(metaData.getArtist()); } } From 1c4a70af99229091c258033f9640e4bc27815ce4 Mon Sep 17 00:00:00 2001 From: tesshucom Date: Fri, 24 May 2019 03:57:57 +0900 Subject: [PATCH 3/3] Fixed null check with StringUtils/ObjectUtils. --- .../service/metadata/JaudiotaggerParser.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java index a9dd398f..718c4621 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java @@ -37,6 +37,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; import java.io.File; import java.util.SortedSet; @@ -110,42 +111,42 @@ public class JaudiotaggerParser extends MetaDataParser { audioFile.getTag().getFields().forEachRemaining(f -> { switch (f.getId()) { case ID3v24Frames.FRAME_ID_ALBUM: - if (null == metaData.getAlbumName()) { + if (StringUtils.isBlank(metaData.getAlbumName())) { metaData.setAlbumName(f.toString()); } break; case ID3v24Frames.FRAME_ID_TITLE: - if (null == metaData.getTitle()) { + if (StringUtils.isBlank(metaData.getTitle())) { metaData.setTitle(f.toString()); } break; case ID3v24Frames.FRAME_ID_YEAR: - if (null == metaData.getYear()) { + if (ObjectUtils.isEmpty(metaData.getYear())) { metaData.setYear(parseYear(f.toString())); } break; case ID3v24Frames.FRAME_ID_GENRE: - if (null == metaData.getGenre()) { + if (StringUtils.isBlank(metaData.getGenre())) { metaData.setGenre(mapGenre(f.toString())); } break; case ID3v24Frames.FRAME_ID_SET: - if (null == metaData.getDiscNumber()) { + if (ObjectUtils.isEmpty(metaData.getDiscNumber())) { metaData.setDiscNumber(parseInteger(f.toString())); } break; case ID3v24Frames.FRAME_ID_TRACK: - if (null == metaData.getTrackNumber()) { + if (ObjectUtils.isEmpty(metaData.getTrackNumber())) { metaData.setTrackNumber(parseTrackNumber(f.toString())); } break; case ID3v24Frames.FRAME_ID_ARTIST: - if (null == metaData.getArtist()) { + if (StringUtils.isBlank(metaData.getArtist())) { metaData.setArtist(f.toString()); } break; case ID3v24Frames.FRAME_ID_ACCOMPANIMENT: - if (null == metaData.getAlbumArtist()) { + if (StringUtils.isBlank(metaData.getAlbumArtist())) { metaData.setAlbumArtist(f.toString()); } break;