Search in sources :

Example 81 with FeedItem

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

the class FeedHandlerTest method createTestFeed.

private Feed createTestFeed(int numItems, boolean withImage, boolean withFeedMedia, boolean withChapters) {
    FeedImage image = null;
    if (withImage) {
        image = new FeedImage(0, "image", null, "http://example.com/picture", false);
    }
    Feed feed = new Feed(0, null, "title", "http://example.com", "This is the description", "http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", image, file.getAbsolutePath(), "http://example.com/feed", true);
    feed.setItems(new ArrayList<FeedItem>());
    for (int i = 0; i < numItems; i++) {
        FeedItem item = new FeedItem(0, "item-" + i, "http://example.com/item-" + i, "http://example.com/items/" + i, new Date(i * 60000), FeedItem.UNPLAYED, feed);
        feed.getItems().add(item);
        if (withFeedMedia) {
            item.setMedia(new FeedMedia(0, item, 4711, 0, 1024 * 1024, "audio/mp3", null, "http://example.com/media-" + i, false, null, 0, 0));
        }
    }
    return feed;
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 82 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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 83 with FeedItem

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

the class FeedFilterTest method testComplexExcludeFilter.

public void testComplexExcludeFilter() throws Exception {
    String excludeFilter = "Hello \"Two words\"";
    FeedFilter filter = new FeedFilter("", excludeFilter);
    FeedItem item = new FeedItem();
    item.setTitle("hello world");
    FeedItem item2 = new FeedItem();
    item2.setTitle("One three words");
    FeedItem item3 = new FeedItem();
    item3.setTitle("One two words");
    assertTrue(filter.excludeOnly());
    assertTrue(!filter.includeOnly());
    assertEquals(excludeFilter, filter.getExcludeFilter());
    assertEquals("", filter.getIncludeFilter());
    assertTrue(!filter.shouldAutoDownload(item));
    assertTrue(filter.shouldAutoDownload(item2));
    assertTrue(!filter.shouldAutoDownload(item3));
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter)

Example 84 with FeedItem

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

the class FeedFilterTest method testComplexIncludeFilter.

public void testComplexIncludeFilter() throws Exception {
    String includeFilter = "Hello \n\"Two words\"";
    FeedFilter filter = new FeedFilter(includeFilter, "");
    FeedItem item = new FeedItem();
    item.setTitle("hello world");
    FeedItem item2 = new FeedItem();
    item2.setTitle("Two three words");
    FeedItem item3 = new FeedItem();
    item3.setTitle("One two words");
    assertTrue(!filter.excludeOnly());
    assertTrue(filter.includeOnly());
    assertEquals("", filter.getExcludeFilter());
    assertEquals(includeFilter, filter.getIncludeFilter());
    assertTrue(filter.shouldAutoDownload(item));
    assertTrue(!filter.shouldAutoDownload(item2));
    assertTrue(filter.shouldAutoDownload(item3));
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter)

Example 85 with FeedItem

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

the class CastUtils method getPlayable.

//TODO make unit tests for all the conversion methods
/**
     * Converts {@link MediaInfo} objects into the appropriate implementation of {@link Playable}.
     *
     * Unless <code>searchFeedMedia</code> is set to <code>false</code>, this method should not run
     * on the GUI thread.
     *
     * @param media The {@link MediaInfo} object to be converted.
     * @param searchFeedMedia If set to <code>true</code>, the database will be queried to find a
     *              {@link FeedMedia} instance that matches {@param media}.
     * @return {@link Playable} object in a format proper for casting.
     */
public static Playable getPlayable(MediaInfo media, boolean searchFeedMedia) {
    Log.d(TAG, "getPlayable called with searchFeedMedia=" + searchFeedMedia);
    if (media == null) {
        Log.d(TAG, "MediaInfo object provided is null, not converting to any Playable instance");
        return null;
    }
    MediaMetadata metadata = media.getMetadata();
    int version = metadata.getInt(KEY_FORMAT_VERSION);
    if (version <= 0 || version > MAX_VERSION_FORWARD_COMPATIBILITY) {
        Log.w(TAG, "MediaInfo object obtained from the cast device is not compatible with this" + "version of AntennaPod CastUtils, curVer=" + FORMAT_VERSION_VALUE + ", object version=" + version);
        return null;
    }
    Playable result = null;
    if (searchFeedMedia) {
        long mediaId = metadata.getInt(KEY_MEDIA_ID);
        if (mediaId > 0) {
            FeedMedia fMedia = DBReader.getFeedMedia(mediaId);
            if (fMedia != null) {
                try {
                    fMedia.loadMetadata();
                    if (matches(media, fMedia)) {
                        result = fMedia;
                        Log.d(TAG, "FeedMedia object obtained matches the MediaInfo provided. id=" + mediaId);
                    } else {
                        Log.d(TAG, "FeedMedia object obtained does NOT match the MediaInfo provided. id=" + mediaId);
                    }
                } catch (Playable.PlayableException e) {
                    Log.e(TAG, "Unable to load FeedMedia metadata to compare with MediaInfo", e);
                }
            } else {
                Log.d(TAG, "Unable to find in database a FeedMedia with id=" + mediaId);
            }
        }
        if (result == null) {
            FeedItem feedItem = DBReader.getFeedItem(metadata.getString(KEY_FEED_URL), metadata.getString(KEY_EPISODE_IDENTIFIER));
            if (feedItem != null) {
                result = feedItem.getMedia();
                Log.d(TAG, "Found episode that matches the MediaInfo provided. Using its media, if existing.");
            }
        }
    }
    if (result == null) {
        List<WebImage> imageList = metadata.getImages();
        String imageUrl = null;
        if (!imageList.isEmpty()) {
            imageUrl = imageList.get(0).getUrl().toString();
        }
        result = new RemoteMedia(media.getContentId(), metadata.getString(KEY_EPISODE_IDENTIFIER), metadata.getString(KEY_FEED_URL), metadata.getString(MediaMetadata.KEY_SUBTITLE), metadata.getString(MediaMetadata.KEY_TITLE), metadata.getString(KEY_EPISODE_LINK), metadata.getString(MediaMetadata.KEY_ARTIST), imageUrl, metadata.getString(KEY_FEED_WEBSITE), media.getContentType(), metadata.getDate(MediaMetadata.KEY_RELEASE_DATE).getTime());
        String notes = metadata.getString(KEY_EPISODE_NOTES);
        if (!TextUtils.isEmpty(notes)) {
            ((RemoteMedia) result).setNotes(notes);
        }
        Log.d(TAG, "Converted MediaInfo into RemoteMedia");
    }
    if (result.getDuration() == 0 && media.getStreamDuration() > 0) {
        result.setDuration((int) media.getStreamDuration());
    }
    return result;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4