Search in sources :

Example 6 with Chapter

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

the class DBTestUtils method saveFeedlist.

/**
     * Use this method when tests involve chapters.
     */
public static List<Feed> saveFeedlist(int numFeeds, int numItems, boolean withMedia, boolean withChapters, int numChapters) {
    if (numFeeds <= 0) {
        throw new IllegalArgumentException("numFeeds<=0");
    }
    if (numItems < 0) {
        throw new IllegalArgumentException("numItems<0");
    }
    List<Feed> feeds = new ArrayList<>();
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int i = 0; i < numFeeds; i++) {
        Feed f = new Feed(0, null, "feed " + i, null, "link" + i, "descr", null, null, null, null, "id" + i, null, null, "url" + i, false, new FlattrStatus(), false, null, null, false);
        f.setItems(new ArrayList<>());
        for (int j = 0; j < numItems; j++) {
            FeedItem item = new FeedItem(0, "item " + j, "id" + j, "link" + j, new Date(), FeedItem.PLAYED, f, withChapters);
            if (withMedia) {
                FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3");
                item.setMedia(media);
            }
            if (withChapters) {
                List<Chapter> chapters = new ArrayList<>();
                item.setChapters(chapters);
                for (int k = 0; k < numChapters; k++) {
                    chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k, item, "http://example.com"));
                }
            }
            f.getItems().add(item);
        }
        Collections.sort(f.getItems(), new FeedItemPubdateComparator());
        adapter.setCompleteFeed(f);
        Assert.assertTrue(f.getId() != 0);
        for (FeedItem item : f.getItems()) {
            Assert.assertTrue(item.getId() != 0);
        }
        feeds.add(f);
    }
    adapter.close();
    return feeds;
}
Also used : ArrayList(java.util.ArrayList) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) Chapter(de.danoeh.antennapod.core.feed.Chapter) Date(java.util.Date) FlattrStatus(de.danoeh.antennapod.core.util.flattr.FlattrStatus) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 7 with Chapter

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

the class FeedHandlerTest method feedValid.

private void feedValid(Feed feed, Feed parsedFeed, String feedType) {
    assertEquals(feed.getTitle(), parsedFeed.getTitle());
    if (feedType.equals(Feed.TYPE_ATOM1)) {
        assertEquals(feed.getFeedIdentifier(), parsedFeed.getFeedIdentifier());
    } else {
        assertEquals(feed.getLanguage(), parsedFeed.getLanguage());
    }
    assertEquals(feed.getLink(), parsedFeed.getLink());
    assertEquals(feed.getDescription(), parsedFeed.getDescription());
    assertEquals(feed.getPaymentLink(), parsedFeed.getPaymentLink());
    if (feed.getImage() != null) {
        FeedImage image = feed.getImage();
        FeedImage parsedImage = parsedFeed.getImage();
        assertNotNull(parsedImage);
        assertEquals(image.getTitle(), parsedImage.getTitle());
        assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
    }
    if (feed.getItems() != null) {
        assertNotNull(parsedFeed.getItems());
        assertEquals(feed.getItems().size(), parsedFeed.getItems().size());
        for (int i = 0; i < feed.getItems().size(); i++) {
            FeedItem item = feed.getItems().get(i);
            FeedItem parsedItem = parsedFeed.getItems().get(i);
            if (item.getItemIdentifier() != null)
                assertEquals(item.getItemIdentifier(), parsedItem.getItemIdentifier());
            assertEquals(item.getTitle(), parsedItem.getTitle());
            assertEquals(item.getDescription(), parsedItem.getDescription());
            assertEquals(item.getContentEncoded(), parsedItem.getContentEncoded());
            assertEquals(item.getLink(), parsedItem.getLink());
            assertEquals(item.getPubDate().getTime(), parsedItem.getPubDate().getTime());
            assertEquals(item.getPaymentLink(), parsedItem.getPaymentLink());
            if (item.hasMedia()) {
                assertTrue(parsedItem.hasMedia());
                FeedMedia media = item.getMedia();
                FeedMedia parsedMedia = parsedItem.getMedia();
                assertEquals(media.getDownload_url(), parsedMedia.getDownload_url());
                assertEquals(media.getSize(), parsedMedia.getSize());
                assertEquals(media.getMime_type(), parsedMedia.getMime_type());
            }
            if (item.hasItemImage()) {
                assertTrue(parsedItem.hasItemImage());
                FeedImage image = item.getImage();
                FeedImage parsedImage = parsedItem.getImage();
                assertEquals(image.getTitle(), parsedImage.getTitle());
                assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
            }
            if (item.getChapters() != null) {
                assertNotNull(parsedItem.getChapters());
                assertEquals(item.getChapters().size(), parsedItem.getChapters().size());
                List<Chapter> chapters = item.getChapters();
                List<Chapter> parsedChapters = parsedItem.getChapters();
                for (int j = 0; j < chapters.size(); j++) {
                    Chapter chapter = chapters.get(j);
                    Chapter parsedChapter = parsedChapters.get(j);
                    assertEquals(chapter.getTitle(), parsedChapter.getTitle());
                    assertEquals(chapter.getLink(), parsedChapter.getLink());
                }
            }
        }
    }
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Chapter(de.danoeh.antennapod.core.feed.Chapter)

Example 8 with Chapter

use of de.danoeh.antennapod.core.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.core.feed.Chapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter)

Example 9 with Chapter

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

the class ChapterUtils method getCurrentChapter.

/**
     * Calls getCurrentChapter with current position.
     */
public static Chapter getCurrentChapter(Playable media) {
    if (media.getChapters() != null) {
        List<Chapter> chapters = media.getChapters();
        Chapter current = null;
        if (chapters != null) {
            current = chapters.get(0);
            for (Chapter sc : chapters) {
                if (sc.getStart() > media.getPosition()) {
                    break;
                } else {
                    current = sc;
                }
            }
        }
        return current;
    } else {
        return null;
    }
}
Also used : Chapter(de.danoeh.antennapod.core.feed.Chapter)

Example 10 with Chapter

use of de.danoeh.antennapod.core.feed.Chapter 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)12 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)3 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)3 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)3 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)3 VorbisCommentChapterReader (de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)3 Cursor (android.database.Cursor)2 Feed (de.danoeh.antennapod.core.feed.Feed)2 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)2 VorbisCommentChapter (de.danoeh.antennapod.core.feed.VorbisCommentChapter)2 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)2 ChapterReader (de.danoeh.antennapod.core.util.id3reader.ChapterReader)2 ID3ReaderException (de.danoeh.antennapod.core.util.id3reader.ID3ReaderException)2 BufferedInputStream (java.io.BufferedInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2