Search in sources :

Example 1 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class ChapterReaderTest method testRealFileHindenburgJournalistPro.

@Test
public void testRealFileHindenburgJournalistPro() throws IOException, ID3ReaderException {
    CountingInputStream inputStream = new CountingInputStream(getClass().getClassLoader().getResource("hindenburg-journalist-pro.mp3").openStream());
    ChapterReader reader = new ChapterReader(inputStream);
    reader.readInputStream();
    List<Chapter> chapters = reader.getChapters();
    assertEquals(2, chapters.size());
    assertEquals(0, chapters.get(0).getStart());
    assertEquals(5006, chapters.get(1).getStart());
    assertEquals("Chapter Marker 1", chapters.get(0).getTitle());
    assertEquals("Chapter Marker 2", chapters.get(1).getTitle());
    assertEquals("https://example.com/chapter1url", chapters.get(0).getLink());
    assertEquals("https://example.com/chapter2url", chapters.get(1).getLink());
    assertEquals(EmbeddedChapterImage.makeUrl(5330, 4015), chapters.get(0).getImageUrl());
    assertEquals(EmbeddedChapterImage.makeUrl(9498, 4364), chapters.get(1).getImageUrl());
}
Also used : CountingInputStream(org.apache.commons.io.input.CountingInputStream) Chapter(de.danoeh.antennapod.model.feed.Chapter) Test(org.junit.Test)

Example 2 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class VorbisCommentChapterReader method onContentVectorValue.

@Override
public void onContentVectorValue(String key, String value) throws VorbisCommentReaderException {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "Key: " + key + ", value: " + value);
    }
    String attribute = VorbisCommentChapter.getAttributeTypeFromKey(key);
    int id = VorbisCommentChapter.getIDFromKey(key);
    Chapter chapter = getChapterById(id);
    if (attribute == null) {
        if (getChapterById(id) == null) {
            // new chapter
            long start = VorbisCommentChapter.getStartTimeFromValue(value);
            chapter = new VorbisCommentChapter(id);
            chapter.setStart(start);
            chapters.add(chapter);
        } else {
            throw new VorbisCommentReaderException("Found chapter with duplicate ID (" + key + ", " + value + ")");
        }
    } else if (attribute.equals(CHAPTER_ATTRIBUTE_TITLE)) {
        if (chapter != null) {
            chapter.setTitle(value);
        }
    } else if (attribute.equals(CHAPTER_ATTRIBUTE_LINK)) {
        if (chapter != null) {
            chapter.setLink(value);
        }
    }
}
Also used : Chapter(de.danoeh.antennapod.model.feed.Chapter)

Example 3 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter 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 4 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class DBReader method loadChaptersOfFeedItem.

private static List<Chapter> loadChaptersOfFeedItem(PodDBAdapter adapter, FeedItem item) {
    try (Cursor cursor = adapter.getSimpleChaptersOfFeedItemCursor(item)) {
        int chaptersCount = cursor.getCount();
        if (chaptersCount == 0) {
            item.setChapters(null);
            return null;
        }
        ArrayList<Chapter> chapters = new ArrayList<>();
        while (cursor.moveToNext()) {
            chapters.add(ChapterCursorMapper.convert(cursor));
        }
        return chapters;
    }
}
Also used : Chapter(de.danoeh.antennapod.model.feed.Chapter) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 5 with Chapter

use of de.danoeh.antennapod.model.feed.Chapter in project AntennaPod by AntennaPod.

the class ChaptersListAdapter method setMedia.

public void setMedia(Playable media) {
    this.media = media;
    hasImages = false;
    if (media.getChapters() != null) {
        for (Chapter chapter : media.getChapters()) {
            if (!TextUtils.isEmpty(chapter.getImageUrl())) {
                hasImages = true;
            }
        }
    }
    notifyDataSetChanged();
}
Also used : Chapter(de.danoeh.antennapod.model.feed.Chapter)

Aggregations

Chapter (de.danoeh.antennapod.model.feed.Chapter)20 CountingInputStream (org.apache.commons.io.input.CountingInputStream)7 Test (org.junit.Test)7 NonNull (androidx.annotation.NonNull)4 FrameHeader (de.danoeh.antennapod.parser.media.id3.model.FrameHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)2 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)2 SimpleChapter (de.danoeh.antennapod.parser.feed.element.SimpleChapter)2 VorbisCommentChapterReader (de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapterReader)2 Dialog (android.app.Dialog)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ProgressBar (android.widget.ProgressBar)1 RelativeLayout (android.widget.RelativeLayout)1