Search in sources :

Example 6 with FeedItem

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

the class QueueFragment method onEventMainThread.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FeedItemEvent event) {
    Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
    if (queue == null) {
        return;
    } else if (recyclerAdapter == null) {
        loadItems(true);
        return;
    }
    for (int i = 0, size = event.items.size(); i < size; i++) {
        FeedItem item = event.items.get(i);
        int pos = FeedItemUtil.indexOfItemWithId(queue, item.getId());
        if (pos >= 0) {
            queue.remove(pos);
            queue.add(pos, item);
            recyclerAdapter.notifyItemChangedCompat(pos);
            refreshInfoBar();
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 7 with FeedItem

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

the class RssParserTest method testMediaContentMime.

@Test
public void testMediaContentMime() throws Exception {
    File feedFile = FeedParserTestHelper.getFeedFile("feed-rss-testMediaContentMime.xml");
    Feed feed = FeedParserTestHelper.runFeedParser(feedFile);
    assertEquals("title", feed.getTitle());
    assertEquals("http://example.com", feed.getLink());
    assertEquals("This is the description", feed.getDescription());
    assertEquals("http://example.com/payment", feed.getPaymentLinks().get(0).url);
    assertNull(feed.getImageUrl());
    assertEquals(1, feed.getItems().size());
    FeedItem feedItem = feed.getItems().get(0);
    // noinspection ConstantConditions
    assertEquals(MediaType.VIDEO, feedItem.getMedia().getMediaType());
    assertEquals("https://www.example.com/file.mp4", feedItem.getMedia().getDownload_url());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 8 with FeedItem

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

the class AtomParserTest method testAtomBasic.

@Test
public void testAtomBasic() throws Exception {
    File feedFile = FeedParserTestHelper.getFeedFile("feed-atom-testAtomBasic.xml");
    Feed feed = FeedParserTestHelper.runFeedParser(feedFile);
    assertEquals(Feed.TYPE_ATOM1, feed.getType());
    assertEquals("title", feed.getTitle());
    assertEquals("http://example.com/feed", feed.getFeedIdentifier());
    assertEquals("http://example.com", feed.getLink());
    assertEquals("This is the description", feed.getDescription());
    assertEquals("http://example.com/payment", feed.getPaymentLinks().get(0).url);
    assertEquals("http://example.com/picture", feed.getImageUrl());
    assertEquals(10, feed.getItems().size());
    for (int i = 0; i < feed.getItems().size(); i++) {
        FeedItem item = feed.getItems().get(i);
        assertEquals("http://example.com/item-" + i, item.getItemIdentifier());
        assertEquals("item-" + i, item.getTitle());
        assertNull(item.getDescription());
        assertEquals("http://example.com/items/" + i, item.getLink());
        assertEquals(new Date(i * 60000), item.getPubDate());
        assertNull(item.getPaymentLink());
        assertEquals("http://example.com/picture", item.getImageLocation());
        // media
        assertTrue(item.hasMedia());
        FeedMedia media = item.getMedia();
        // noinspection ConstantConditions
        assertEquals("http://example.com/media-" + i, media.getDownload_url());
        assertEquals(1024 * 1024, media.getSize());
        assertEquals("audio/mp3", media.getMime_type());
        // chapters
        assertNull(item.getChapters());
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 9 with FeedItem

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

the class Atom method handleElementEnd.

@Override
public void handleElementEnd(String localName, HandlerState state) {
    if (ENTRY.equals(localName)) {
        if (state.getCurrentItem() != null && state.getTempObjects().containsKey(Itunes.DURATION)) {
            FeedItem currentItem = state.getCurrentItem();
            if (currentItem.hasMedia()) {
                Integer duration = (Integer) state.getTempObjects().get(Itunes.DURATION);
                currentItem.getMedia().setDuration(duration);
            }
            state.getTempObjects().remove(Itunes.DURATION);
        }
        state.setCurrentItem(null);
    }
    if (state.getTagstack().size() >= 2) {
        AtomText textElement = null;
        String contentRaw;
        if (state.getContentBuf() != null) {
            contentRaw = state.getContentBuf().toString();
        } else {
            contentRaw = "";
        }
        String content = SyndStringUtils.trimAllWhitespace(contentRaw);
        SyndElement topElement = state.getTagstack().peek();
        String top = topElement.getName();
        SyndElement secondElement = state.getSecondTag();
        String second = secondElement.getName();
        if (top.matches(isText)) {
            textElement = (AtomText) topElement;
            textElement.setContent(content);
        }
        if (ID.equals(top)) {
            if (FEED.equals(second) && state.getFeed() != null) {
                state.getFeed().setFeedIdentifier(contentRaw);
            } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setItemIdentifier(contentRaw);
            }
        } else if (TITLE.equals(top) && textElement != null) {
            if (FEED.equals(second) && state.getFeed() != null) {
                state.getFeed().setTitle(textElement.getProcessedContent());
            } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setTitle(textElement.getProcessedContent());
            }
        } else if (SUBTITLE.equals(top) && FEED.equals(second) && textElement != null && state.getFeed() != null) {
            state.getFeed().setDescription(textElement.getProcessedContent());
        } else if (CONTENT.equals(top) && ENTRY.equals(second) && textElement != null && state.getCurrentItem() != null) {
            state.getCurrentItem().setDescriptionIfLonger(textElement.getProcessedContent());
        } else if (SUMMARY.equals(top) && ENTRY.equals(second) && textElement != null && state.getCurrentItem() != null) {
            state.getCurrentItem().setDescriptionIfLonger(textElement.getProcessedContent());
        } else if (UPDATED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null && state.getCurrentItem().getPubDate() == null) {
            state.getCurrentItem().setPubDate(DateUtils.parseOrNullIfFuture(content));
        } else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
            state.getCurrentItem().setPubDate(DateUtils.parseOrNullIfFuture(content));
        } else if (IMAGE_LOGO.equals(top) && state.getFeed() != null && state.getFeed().getImageUrl() == null) {
            state.getFeed().setImageUrl(content);
        } else if (IMAGE_ICON.equals(top) && state.getFeed() != null) {
            state.getFeed().setImageUrl(content);
        } else if (AUTHOR_NAME.equals(top) && AUTHOR.equals(second) && state.getFeed() != null && state.getCurrentItem() == null) {
            String currentName = state.getFeed().getAuthor();
            if (currentName == null) {
                state.getFeed().setAuthor(content);
            } else {
                state.getFeed().setAuthor(currentName + ", " + content);
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) SyndElement(de.danoeh.antennapod.parser.feed.element.SyndElement) AtomText(de.danoeh.antennapod.parser.feed.element.AtomText)

Example 10 with FeedItem

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

the class PlaybackSpeedUtils method getCurrentPlaybackSpeed.

/**
 * Returns the currently configured playback speed for the specified media.
 */
public static float getCurrentPlaybackSpeed(Playable media) {
    float playbackSpeed = SPEED_USE_GLOBAL;
    MediaType mediaType = null;
    if (media != null) {
        mediaType = media.getMediaType();
        playbackSpeed = PlaybackPreferences.getCurrentlyPlayingTemporaryPlaybackSpeed();
        if (playbackSpeed == SPEED_USE_GLOBAL && media instanceof FeedMedia) {
            FeedItem item = ((FeedMedia) media).getItem();
            if (item != null) {
                Feed feed = item.getFeed();
                if (feed != null && feed.getPreferences() != null) {
                    playbackSpeed = feed.getPreferences().getFeedPlaybackSpeed();
                } else {
                    Log.d(TAG, "Can not get feed specific playback speed: " + feed);
                }
            }
        }
    }
    if (playbackSpeed == SPEED_USE_GLOBAL) {
        playbackSpeed = UserPreferences.getPlaybackSpeed(mediaType);
    }
    return playbackSpeed;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) MediaType(de.danoeh.antennapod.model.playback.MediaType) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

FeedItem (de.danoeh.antennapod.model.feed.FeedItem)178 Feed (de.danoeh.antennapod.model.feed.Feed)74 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)48 Date (java.util.Date)47 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)46 File (java.io.File)26 Cursor (android.database.Cursor)20 NonNull (androidx.annotation.NonNull)15 Nullable (androidx.annotation.Nullable)11 Subscribe (org.greenrobot.eventbus.Subscribe)9 Intent (android.content.Intent)7 FeedFilter (de.danoeh.antennapod.model.feed.FeedFilter)7 View (android.view.View)6 LongList (de.danoeh.antennapod.core.util.LongList)6 SQLException (android.database.SQLException)5 Playable (de.danoeh.antennapod.model.playback.Playable)5 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)5 ExecutionException (java.util.concurrent.ExecutionException)5 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)4