Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tika.parser.mp3;

import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -163,6 +164,36 @@ public interface ID3Tags {
/* 125 */ "Dance Hall",
/* sentinel */ ""};

/**
* List of predefined picture types for embedded pictures, indexed
* by the type byte of the ID3v2 APIC / PIC frames. The FLAC picture
* block, as also embedded in Vorbis comments, reuses the same list.
* <p>
* See <a href="https://id3.org/id3v2.4.0-frames">http://id3.org/id3v2.4.0-frames</a>
*/
String[] PICTURE_TYPES = new String[]{
/* 0 */ "Other",
/* 1 */ "32x32 pixels 'file icon' (PNG only)",
/* 2 */ "Other file icon",
/* 3 */ "Cover (front)",
/* 4 */ "Cover (back)",
/* 5 */ "Leaflet page",
/* 6 */ "Media (e.g. label side of CD)",
/* 7 */ "Lead artist/lead performer/soloist",
/* 8 */ "Artist/performer",
/* 9 */ "Conductor",
/* 10 */ "Band/Orchestra",
/* 11 */ "Composer",
/* 12 */ "Lyricist/text writer",
/* 13 */ "Recording Location",
/* 14 */ "During recording",
/* 15 */ "During performance",
/* 16 */ "Movie/video screen capture",
/* 17 */ "A bright coloured fish",
/* 18 */ "Illustration",
/* 19 */ "Band/artist logotype",
/* 20 */ "Publisher/Studio logotype"};

/**
* Does the file contain this kind of tags?
*/
Expand Down Expand Up @@ -198,6 +229,15 @@ public interface ID3Tags {
*/
List<ID3Comment> getComments();

/**
* Retrieves the embedded pictures (e.g. cover art), if any.
* Only ID3v2 tags can carry pictures, so this defaults to
* an empty list.
*/
default List<ID3Picture> getPictures() {
return Collections.emptyList();
}

String getGenre();

String getYear();
Expand Down Expand Up @@ -258,4 +298,50 @@ public String getText() {
return text;
}
}

/**
* Represents an embedded picture in ID3 v2, such as cover art,
* as carried by the APIC (v2.3/v2.4) and PIC (v2.2) frames
*/
class ID3Picture {
private final String mimeType;
private final String description;
private final int pictureType;
private final byte[] data;

public ID3Picture(String mimeType, String description, int pictureType, byte[] data) {
this.mimeType = mimeType;
this.description = description;
this.pictureType = pictureType;
this.data = data;
}

/**
* Gets the declared mime type, if present
*/
public String getMimeType() {
return mimeType;
}

/**
* Gets the description, if present
*/
public String getDescription() {
return description;
}

/**
* Gets the picture type byte, which indexes {@link #PICTURE_TYPES}
*/
public int getPictureType() {
return pictureType;
}

/**
* Gets the raw picture data
*/
public byte[] getData() {
return data;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ID3v22Handler implements ID3Tags {
private String albumArtist;
private String disc;
private List<ID3Comment> comments = new ArrayList<>();
private List<ID3Picture> pictures = new ArrayList<>();

public ID3v22Handler(ID3v2Frame frame) throws IOException, SAXException, TikaException {
RawTagIterator tags = new RawV22TagIterator(frame);
Expand Down Expand Up @@ -78,6 +79,13 @@ public ID3v22Handler(ID3v2Frame frame) throws IOException, SAXException, TikaExc
}
break;
}
case "PIC": {
ID3Picture picture = ID3v2Frame.getV22Picture(tag.data, 0, tag.data.length);
if (picture != null) {
pictures.add(picture);
}
break;
}
case "TRK":
trackNumber = getTagString(tag.data, 0, tag.data.length);
break;
Expand Down Expand Up @@ -149,6 +157,10 @@ public List<ID3Comment> getComments() {
return comments;
}

public List<ID3Picture> getPictures() {
return pictures;
}

public String getGenre() {
return genre;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ID3v23Handler implements ID3Tags {
private String disc;
private String compilation;
private List<ID3Comment> comments = new ArrayList<>();
private List<ID3Picture> pictures = new ArrayList<>();

public ID3v23Handler(ID3v2Frame frame) throws IOException, SAXException, TikaException {
RawTagIterator tags = new RawV23TagIterator(frame);
Expand Down Expand Up @@ -79,6 +80,13 @@ public ID3v23Handler(ID3v2Frame frame) throws IOException, SAXException, TikaExc
}
break;
}
case "APIC": {
ID3Picture picture = ID3v2Frame.getPicture(tag.data, 0, tag.data.length);
if (picture != null) {
pictures.add(picture);
}
break;
}
case "TRCK":
trackNumber = getTagString(tag.data, 0, tag.data.length);
break;
Expand Down Expand Up @@ -135,6 +143,10 @@ public List<ID3Comment> getComments() {
return comments;
}

public List<ID3Picture> getPictures() {
return pictures;
}

public String getGenre() {
return genre;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ID3v24Handler implements ID3Tags {
private String disc;
private String compilation;
private List<ID3Comment> comments = new ArrayList<>();
private List<ID3Picture> pictures = new ArrayList<>();

public ID3v24Handler(ID3v2Frame frame) throws IOException, SAXException, TikaException {
RawTagIterator tags = new RawV24TagIterator(frame);
Expand Down Expand Up @@ -85,6 +86,13 @@ public ID3v24Handler(ID3v2Frame frame) throws IOException, SAXException, TikaExc
}
break;
}
case "APIC": {
ID3Picture picture = ID3v2Frame.getPicture(tag.data, 0, tag.data.length);
if (picture != null) {
pictures.add(picture);
}
break;
}
case "TRCK":
trackNumber = getTagString(tag.data, 0, tag.data.length);
break;
Expand Down Expand Up @@ -141,6 +149,10 @@ public List<ID3Comment> getComments() {
return comments;
}

public List<ID3Picture> getPictures() {
return pictures;
}

public String getGenre() {
return genre;
}
Expand All @@ -163,7 +175,8 @@ public String getCompilation() {

private class RawV24TagIterator extends RawTagIterator {
private RawV24TagIterator(ID3v2Frame frame) {
frame.super(4, 4, 1, 2);
//v2.4 frame sizes are synchsafe integers
frame.super(4, 4, 1, 2, true);
}
}
}
Loading
Loading