Search in sources :

Example 1 with ID3Chapter

use of de.danoeh.antennapod.parser.media.id3.ID3Chapter in project AntennaPod by AntennaPod.

the class ChapterCursorMapper method convert.

/**
 * Create a {@link Chapter} instance from a database row (cursor).
 */
@NonNull
public static Chapter convert(@NonNull Cursor cursor) {
    int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
    int indexTitle = cursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
    int indexStart = cursor.getColumnIndex(PodDBAdapter.KEY_START);
    int indexLink = cursor.getColumnIndex(PodDBAdapter.KEY_LINK);
    int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE_URL);
    int indexChapterType = cursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
    long id = cursor.getLong(indexId);
    String title = cursor.getString(indexTitle);
    long start = cursor.getLong(indexStart);
    String link = cursor.getString(indexLink);
    String imageUrl = cursor.getString(indexImage);
    int chapterType = cursor.getInt(indexChapterType);
    Chapter chapter;
    switch(chapterType) {
        case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
            chapter = new SimpleChapter(start, title, link, imageUrl);
            break;
        case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
            chapter = new ID3Chapter(start, title, link, imageUrl);
            break;
        case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
            chapter = new VorbisCommentChapter(start, title, link, imageUrl);
            break;
        default:
            throw new IllegalArgumentException("Unknown chapter type");
    }
    chapter.setId(id);
    return chapter;
}
Also used : SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) VorbisCommentChapter(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter) ID3Chapter(de.danoeh.antennapod.parser.media.id3.ID3Chapter) ID3Chapter(de.danoeh.antennapod.parser.media.id3.ID3Chapter) SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter) NonNull(androidx.annotation.NonNull)

Example 2 with ID3Chapter

use of de.danoeh.antennapod.parser.media.id3.ID3Chapter in project AntennaPod by AntennaPod.

the class ChapterReaderTest method testReadTitleWithGarbage.

@Test
public void testReadTitleWithGarbage() throws IOException, ID3ReaderException {
    byte[] titleSubframeContent = { ID3Reader.ENCODING_ISO, // Title
    'A', // Null-terminated
    0, // Garbage, should be ignored
    42, // Garbage, should be ignored
    42, // Garbage, should be ignored
    42, // Garbage, should be ignored
    42 };
    FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_TITLE, titleSubframeContent.length, (short) 0);
    CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(titleSubframeContent));
    ChapterReader reader = new ChapterReader(inputStream);
    Chapter chapter = new ID3Chapter("", 0);
    reader.readChapterSubFrame(header, chapter);
    assertEquals("A", chapter.getTitle());
    // Should skip the garbage and point to the next frame
    assertEquals(titleSubframeContent.length, reader.getPosition());
}
Also used : FrameHeader(de.danoeh.antennapod.parser.media.id3.model.FrameHeader) ByteArrayInputStream(java.io.ByteArrayInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) Chapter(de.danoeh.antennapod.model.feed.Chapter) Test(org.junit.Test)

Example 3 with ID3Chapter

use of de.danoeh.antennapod.parser.media.id3.ID3Chapter in project AntennaPod by AntennaPod.

the class ChapterReader method readChapter.

public Chapter readChapter(@NonNull FrameHeader frameHeader) throws IOException, ID3ReaderException {
    int chapterStartedPosition = getPosition();
    String elementId = readIsoStringNullTerminated(100);
    long startTime = readInt();
    // Ignore end time, start offset, end offset
    skipBytes(12);
    ID3Chapter chapter = new ID3Chapter(elementId, startTime);
    // Read sub-frames
    while (getPosition() < chapterStartedPosition + frameHeader.getSize()) {
        FrameHeader subFrameHeader = readFrameHeader();
        readChapterSubFrame(subFrameHeader, chapter);
    }
    return chapter;
}
Also used : FrameHeader(de.danoeh.antennapod.parser.media.id3.model.FrameHeader)

Aggregations

Chapter (de.danoeh.antennapod.model.feed.Chapter)2 FrameHeader (de.danoeh.antennapod.parser.media.id3.model.FrameHeader)2 NonNull (androidx.annotation.NonNull)1 SimpleChapter (de.danoeh.antennapod.parser.feed.element.SimpleChapter)1 ID3Chapter (de.danoeh.antennapod.parser.media.id3.ID3Chapter)1 VorbisCommentChapter (de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1 Test (org.junit.Test)1