Search in sources :

Example 1 with ID3Chapter

use of de.danoeh.antennapod.core.feed.ID3Chapter in project AntennaPod by AntennaPod.

the class ChapterReader method onStartFrameHeader.

@Override
public int onStartFrameHeader(FrameHeader header, InputStream input) throws IOException, ID3ReaderException {
    System.out.println(header.toString());
    switch(header.getId()) {
        case FRAME_ID_CHAPTER:
            if (currentChapter != null) {
                if (!hasId3Chapter(currentChapter)) {
                    chapters.add(currentChapter);
                    if (BuildConfig.DEBUG)
                        Log.d(TAG, "Found chapter: " + currentChapter);
                    currentChapter = null;
                }
            }
            StringBuffer elementId = new StringBuffer();
            readISOString(elementId, input, Integer.MAX_VALUE);
            char[] startTimeSource = readBytes(input, 4);
            long startTime = ((int) startTimeSource[0] << 24) | ((int) startTimeSource[1] << 16) | ((int) startTimeSource[2] << 8) | startTimeSource[3];
            currentChapter = new ID3Chapter(elementId.toString(), startTime);
            skipBytes(input, 12);
            return ID3Reader.ACTION_DONT_SKIP;
        case FRAME_ID_TITLE:
            if (currentChapter != null && currentChapter.getTitle() == null) {
                StringBuffer title = new StringBuffer();
                readString(title, input, header.getSize());
                currentChapter.setTitle(title.toString());
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "Found title: " + currentChapter.getTitle());
                return ID3Reader.ACTION_DONT_SKIP;
            }
            break;
        case FRAME_ID_LINK:
            if (currentChapter != null) {
                // skip description
                int descriptionLength = readString(null, input, header.getSize());
                StringBuffer link = new StringBuffer();
                readISOString(link, input, header.getSize() - descriptionLength);
                String decodedLink = URLDecoder.decode(link.toString(), "UTF-8");
                currentChapter.setLink(decodedLink);
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "Found link: " + currentChapter.getLink());
                return ID3Reader.ACTION_DONT_SKIP;
            }
            break;
        case "APIC":
            Log.d(TAG, header.toString());
            break;
    }
    return super.onStartFrameHeader(header, input);
}
Also used : ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter)

Example 2 with ID3Chapter

use of de.danoeh.antennapod.core.feed.ID3Chapter in project AntennaPod by AntennaPod.

the class DBReader method loadChaptersOfFeedItem.

static void loadChaptersOfFeedItem(PodDBAdapter adapter, FeedItem item) {
    Cursor chapterCursor = adapter.getSimpleChaptersOfFeedItemCursor(item);
    if (chapterCursor.moveToFirst()) {
        item.setChapters(new ArrayList<>());
        do {
            int indexType = chapterCursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
            int indexStart = chapterCursor.getColumnIndex(PodDBAdapter.KEY_START);
            int indexTitle = chapterCursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
            int indexLink = chapterCursor.getColumnIndex(PodDBAdapter.KEY_LINK);
            int chapterType = chapterCursor.getInt(indexType);
            Chapter chapter = null;
            long start = chapterCursor.getLong(indexStart);
            String title = chapterCursor.getString(indexTitle);
            String link = chapterCursor.getString(indexLink);
            switch(chapterType) {
                case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
                    chapter = new SimpleChapter(start, title, item, link);
                    break;
                case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
                    chapter = new ID3Chapter(start, title, item, link);
                    break;
                case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
                    chapter = new VorbisCommentChapter(start, title, item, link);
                    break;
            }
            if (chapter != null) {
                int indexId = chapterCursor.getColumnIndex(PodDBAdapter.KEY_ID);
                chapter.setId(chapterCursor.getLong(indexId));
                item.getChapters().add(chapter);
            }
        } while (chapterCursor.moveToNext());
    } else {
        item.setChapters(null);
    }
    chapterCursor.close();
}
Also used : SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter) ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter) Chapter(de.danoeh.antennapod.core.feed.Chapter) ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter) Cursor(android.database.Cursor) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter)

Aggregations

ID3Chapter (de.danoeh.antennapod.core.feed.ID3Chapter)2 Cursor (android.database.Cursor)1 Chapter (de.danoeh.antennapod.core.feed.Chapter)1 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)1 VorbisCommentChapter (de.danoeh.antennapod.core.feed.VorbisCommentChapter)1