Search in sources :

Example 86 with FeedItem

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

the class UITestUtils method addHostedFeedData.

/**
 * Adds feeds, images and episodes to the webserver for testing purposes.
 */
public void addHostedFeedData() throws IOException {
    if (feedDataHosted)
        throw new IllegalStateException("addHostedFeedData was called twice on the same instance");
    for (int i = 0; i < NUM_FEEDS; i++) {
        Feed feed = new Feed(0, null, "Title " + i, "http://example.com/" + i, "Description of feed " + i, "http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, null, null, "http://example.com/feed/src/" + i, false);
        // create items
        List<FeedItem> items = new ArrayList<>();
        for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) {
            FeedItem item = new FeedItem(j, "Feed " + (i + 1) + ": Item " + (j + 1), "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), FeedItem.UNPLAYED, feed);
            items.add(item);
            if (!hostTextOnlyFeeds) {
                File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
                item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0, 0));
            }
        }
        feed.setItems(items);
        feed.setDownload_url(hostFeed(feed));
        hostedFeeds.add(feed);
    }
    feedDataHosted = true;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 87 with FeedItem

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

the class DownloadServiceTest method setUpTestFeeds.

private Feed setUpTestFeeds() throws Exception {
    // To avoid complication in case of test failures, leaving behind orphaned
    // media files: add a timestamp so that each test run will have its own directory for media files.
    Feed feed = new Feed("url", null, "Test Feed title 1 " + System.currentTimeMillis());
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    FeedItem item1 = new FeedItem(0, "Item 1-1", "Item 1-1", "url", new Date(), FeedItem.NEW, feed);
    items.add(item1);
    FeedMedia media1 = new FeedMedia(0, item1, 123, 1, 1, "audio/mp3", null, "http://example.com/episode.mp3", false, null, 0, 0);
    item1.setMedia(media1);
    DBWriter.setFeedItem(item1).get();
    return feed;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 88 with FeedItem

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

the class PlaybackServiceTaskManagerTest method writeTestQueue.

private List<FeedItem> writeTestQueue(String pref) {
    final int NUM_ITEMS = 10;
    Feed f = new Feed(0, null, "title", "link", "d", null, null, null, null, "id", null, "null", "url", false);
    f.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
        f.getItems().add(new FeedItem(0, pref + i, pref + i, "link", new Date(), FeedItem.PLAYED, f));
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(f);
    adapter.setQueue(f.getItems());
    adapter.close();
    for (FeedItem item : f.getItems()) {
        assertTrue(item.getId() != 0);
    }
    return f.getItems();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 89 with FeedItem

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

the class Atom method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (ENTRY.equals(localName)) {
        state.setCurrentItem(new FeedItem());
        state.getItems().add(state.getCurrentItem());
        state.getCurrentItem().setFeed(state.getFeed());
    } else if (localName.matches(isText)) {
        String type = attributes.getValue(TEXT_TYPE);
        return new AtomText(localName, this, type);
    } else if (LINK.equals(localName)) {
        String href = attributes.getValue(LINK_HREF);
        String rel = attributes.getValue(LINK_REL);
        SyndElement parent = state.getTagstack().peek();
        if (parent.getName().matches(isFeedItem)) {
            if (rel == null || LINK_REL_ALTERNATE.equals(rel)) {
                state.getCurrentItem().setLink(href);
            } else if (LINK_REL_ENCLOSURE.equals(rel)) {
                String strSize = attributes.getValue(LINK_LENGTH);
                long size = 0;
                try {
                    if (strSize != null) {
                        size = Long.parseLong(strSize);
                    }
                } catch (NumberFormatException e) {
                    Log.d(TAG, "Length attribute could not be parsed.");
                }
                String type = attributes.getValue(LINK_TYPE);
                if (type == null) {
                    type = SyndTypeUtils.getMimeTypeFromUrl(href);
                }
                FeedItem currItem = state.getCurrentItem();
                if (SyndTypeUtils.enclosureTypeValid(type) && currItem != null && !currItem.hasMedia()) {
                    currItem.setMedia(new FeedMedia(currItem, href, size, type));
                }
            } else if (LINK_REL_PAYMENT.equals(rel)) {
                state.getCurrentItem().setPaymentLink(href);
            }
        } else if (parent.getName().matches(isFeed)) {
            if (rel == null || LINK_REL_ALTERNATE.equals(rel)) {
                String type = attributes.getValue(LINK_TYPE);
                /*
                     * Use as link if a) no type-attribute is given and
                     * feed-object has no link yet b) type of link is
                     * LINK_TYPE_HTML or LINK_TYPE_XHTML
                     */
                if (state.getFeed() != null && ((type == null && state.getFeed().getLink() == null) || (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)))) {
                    state.getFeed().setLink(href);
                } else if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
                    // treat as podlove alternate feed
                    String title = attributes.getValue(LINK_TITLE);
                    if (TextUtils.isEmpty(title)) {
                        title = href;
                    }
                    state.addAlternateFeedUrl(title, href);
                }
            } else if (LINK_REL_ARCHIVES.equals(rel) && state.getFeed() != null) {
                String type = attributes.getValue(LINK_TYPE);
                if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
                    String title = attributes.getValue(LINK_TITLE);
                    if (TextUtils.isEmpty(title)) {
                        title = href;
                    }
                    state.addAlternateFeedUrl(title, href);
                } else if (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)) {
                // A Link such as to a directory such as iTunes
                }
            } else if (LINK_REL_PAYMENT.equals(rel) && state.getFeed() != null) {
                state.getFeed().addPayment(new FeedFunding(href, ""));
            } else if (LINK_REL_NEXT.equals(rel) && state.getFeed() != null) {
                state.getFeed().setPaged(true);
                state.getFeed().setNextPageLink(href);
            }
        }
    }
    return new SyndElement(localName, this);
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) SyndElement(de.danoeh.antennapod.parser.feed.element.SyndElement) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) AtomText(de.danoeh.antennapod.parser.feed.element.AtomText) FeedFunding(de.danoeh.antennapod.model.feed.FeedFunding)

Example 90 with FeedItem

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

the class DublinCore method handleElementEnd.

@Override
public void handleElementEnd(String localName, HandlerState state) {
    if (state.getCurrentItem() != null && state.getContentBuf() != null && state.getTagstack() != null && state.getTagstack().size() >= 2) {
        FeedItem currentItem = state.getCurrentItem();
        String top = state.getTagstack().peek().getName();
        String second = state.getSecondTag().getName();
        if (DATE.equals(top) && ITEM.equals(second)) {
            String content = state.getContentBuf().toString();
            currentItem.setPubDate(DateUtils.parseOrNullIfFuture(content));
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem)

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