Search in sources :

Example 1 with ChapterStartTimeComparator

use of de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator in project AntennaPod by AntennaPod.

the class ChapterUtils method readID3ChaptersFromPlayableStreamUrl.

/**
     * Uses the download URL of a media object of a feeditem to read its ID3
     * chapters.
     */
public static void readID3ChaptersFromPlayableStreamUrl(Playable p) {
    if (p != null && p.getStreamUrl() != null) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle());
        InputStream in = null;
        try {
            URL url = new URL(p.getStreamUrl());
            ChapterReader reader = new ChapterReader();
            in = url.openStream();
            reader.readInputStream(in);
            List<Chapter> chapters = reader.getChapters();
            if (chapters != null) {
                Collections.sort(chapters, new ChapterStartTimeComparator());
                processChapters(chapters, p);
                if (chaptersValid(chapters)) {
                    p.setChapters(chapters);
                    Log.i(TAG, "Chapters loaded");
                } else {
                    Log.e(TAG, "Chapter data was invalid");
                }
            } else {
                Log.i(TAG, "ChapterReader could not find any ID3 chapters");
            }
        } catch (IOException | ID3ReaderException e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    } else {
        Log.e(TAG, "Unable to read ID3 chapters: media or download URL was null");
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) ChapterReader(de.danoeh.antennapod.core.util.id3reader.ChapterReader) VorbisCommentChapterReader(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader) Chapter(de.danoeh.antennapod.core.feed.Chapter) IOException(java.io.IOException) URL(java.net.URL) ID3ReaderException(de.danoeh.antennapod.core.util.id3reader.ID3ReaderException)

Example 2 with ChapterStartTimeComparator

use of de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator in project AntennaPod by AntennaPod.

the class ChapterUtils method readOggChaptersFromInputStream.

private static void readOggChaptersFromInputStream(Playable p, InputStream input) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "Trying to read chapters from item with title " + p.getEpisodeTitle());
    try {
        VorbisCommentChapterReader reader = new VorbisCommentChapterReader();
        reader.readInputStream(input);
        List<Chapter> chapters = reader.getChapters();
        if (chapters != null) {
            Collections.sort(chapters, new ChapterStartTimeComparator());
            processChapters(chapters, p);
            if (chaptersValid(chapters)) {
                p.setChapters(chapters);
                Log.i(TAG, "Chapters loaded");
            } else {
                Log.e(TAG, "Chapter data was invalid");
            }
        } else {
            Log.i(TAG, "ChapterReader could not find any Ogg vorbis chapters");
        }
    } catch (VorbisCommentReaderException e) {
        e.printStackTrace();
    }
}
Also used : ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) Chapter(de.danoeh.antennapod.core.feed.Chapter) VorbisCommentReaderException(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException) VorbisCommentChapterReader(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)

Example 3 with ChapterStartTimeComparator

use of de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator in project AntennaPod by AntennaPod.

the class ChapterUtils method readID3ChaptersFromPlayableFileUrl.

/**
     * Uses the file URL of a media object of a feeditem to read its ID3
     * chapters.
     */
public static void readID3ChaptersFromPlayableFileUrl(Playable p) {
    if (p != null && p.localFileAvailable() && p.getLocalMediaUrl() != null) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle());
        File source = new File(p.getLocalMediaUrl());
        if (source.exists()) {
            ChapterReader reader = new ChapterReader();
            InputStream in = null;
            try {
                in = new BufferedInputStream(new FileInputStream(source));
                reader.readInputStream(in);
                List<Chapter> chapters = reader.getChapters();
                if (chapters != null) {
                    Collections.sort(chapters, new ChapterStartTimeComparator());
                    processChapters(chapters, p);
                    if (chaptersValid(chapters)) {
                        p.setChapters(chapters);
                        Log.i(TAG, "Chapters loaded");
                    } else {
                        Log.e(TAG, "Chapter data was invalid");
                    }
                } else {
                    Log.i(TAG, "ChapterReader could not find any ID3 chapters");
                }
            } catch (IOException | ID3ReaderException e) {
                e.printStackTrace();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        } else {
            Log.e(TAG, "Unable to read id3 chapters: Source doesn't exist");
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) ChapterReader(de.danoeh.antennapod.core.util.id3reader.ChapterReader) VorbisCommentChapterReader(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader) Chapter(de.danoeh.antennapod.core.feed.Chapter) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) ID3ReaderException(de.danoeh.antennapod.core.util.id3reader.ID3ReaderException)

Aggregations

Chapter (de.danoeh.antennapod.core.feed.Chapter)3 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)3 VorbisCommentChapterReader (de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)3 ChapterReader (de.danoeh.antennapod.core.util.id3reader.ChapterReader)2 ID3ReaderException (de.danoeh.antennapod.core.util.id3reader.ID3ReaderException)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 VorbisCommentReaderException (de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException)1 File (java.io.File)1 URL (java.net.URL)1