Search in sources :

Example 1 with ChapterReader

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

the class ChapterReaderTest method testReadChapterWithTitle.

@Test
public void testReadChapterWithTitle() throws IOException, ID3ReaderException {
    byte[] title = { ID3Reader.ENCODING_ISO, // Title
    'H', // Title
    'e', // Title
    'l', // Title
    'l', // Title
    'o', // Null-terminated
    0 };
    byte[] chapterData = Id3ReaderTest.concat(CHAPTER_WITHOUT_SUBFRAME, Id3ReaderTest.generateFrameHeader(ChapterReader.FRAME_ID_TITLE, title.length), title);
    FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_CHAPTER, chapterData.length, (short) 0);
    CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(chapterData));
    ChapterReader reader = new ChapterReader(inputStream);
    Chapter chapter = reader.readChapter(header);
    assertEquals(CHAPTER_WITHOUT_SUBFRAME_START_TIME, chapter.getStart());
    assertEquals("Hello", chapter.getTitle());
}
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 2 with ChapterReader

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

the class ChapterUtils method readId3ChaptersFrom.

@NonNull
private static List<Chapter> readId3ChaptersFrom(CountingInputStream in) throws IOException, ID3ReaderException {
    ChapterReader reader = new ChapterReader(in);
    reader.readInputStream();
    List<Chapter> chapters = reader.getChapters();
    Collections.sort(chapters, new ChapterStartTimeComparator());
    enumerateEmptyChapterTitles(chapters);
    if (!chaptersValid(chapters)) {
        Log.e(TAG, "Chapter data was invalid");
        return Collections.emptyList();
    }
    return chapters;
}
Also used : ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) ChapterReader(de.danoeh.antennapod.parser.media.id3.ChapterReader) VorbisCommentChapterReader(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapterReader) Chapter(de.danoeh.antennapod.model.feed.Chapter) NonNull(androidx.annotation.NonNull)

Example 3 with ChapterReader

use of de.danoeh.antennapod.parser.media.id3.ChapterReader 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 4 with ChapterReader

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

the class ChapterReaderTest method testReadChapterWithoutSubframes.

@Test
public void testReadChapterWithoutSubframes() throws IOException, ID3ReaderException {
    FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_CHAPTER, CHAPTER_WITHOUT_SUBFRAME.length, (short) 0);
    CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(CHAPTER_WITHOUT_SUBFRAME));
    Chapter chapter = new ChapterReader(inputStream).readChapter(header);
    assertEquals(CHAPTER_WITHOUT_SUBFRAME_START_TIME, chapter.getStart());
}
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)

Aggregations

Chapter (de.danoeh.antennapod.model.feed.Chapter)4 FrameHeader (de.danoeh.antennapod.parser.media.id3.model.FrameHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CountingInputStream (org.apache.commons.io.input.CountingInputStream)3 Test (org.junit.Test)3 NonNull (androidx.annotation.NonNull)1 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)1 ChapterReader (de.danoeh.antennapod.parser.media.id3.ChapterReader)1 VorbisCommentChapterReader (de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapterReader)1