Search in sources :

Example 11 with FeedItem

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

the class ImageResourceUtils method getFallbackImageLocation.

@Nullable
public static String getFallbackImageLocation(@NonNull Playable playable) {
    if (playable instanceof FeedMedia) {
        FeedMedia media = (FeedMedia) playable;
        FeedItem item = media.getItem();
        if (item != null && item.getFeed() != null) {
            return item.getFeed().getImageUrl();
        } else {
            return null;
        }
    } else {
        return playable.getImageLocation();
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Nullable(androidx.annotation.Nullable)

Example 12 with FeedItem

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

the class FavoritesWriter method getFeedMap.

/**
 * Group favorite episodes by feed, sorting them by publishing date in descending order.
 *
 * @param favoritesList {@code List} of all favorite episodes.
 * @return A {@code Map} favorite episodes, keyed by feed ID.
 */
private Map<Long, List<FeedItem>> getFeedMap(List<FeedItem> favoritesList) {
    Map<Long, List<FeedItem>> feedMap = new TreeMap<>();
    for (FeedItem item : favoritesList) {
        List<FeedItem> feedEpisodes = feedMap.get(item.getFeedId());
        if (feedEpisodes == null) {
            feedEpisodes = new ArrayList<>();
            feedMap.put(item.getFeedId(), feedEpisodes);
        }
        feedEpisodes.add(item);
    }
    return feedMap;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap)

Example 13 with FeedItem

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

the class MediaInfoCreator method from.

/**
 * Converts {@link FeedMedia} objects into a format suitable for sending to a Cast Device.
 * Before using this method, one should make sure isCastable(Playable) returns
 * {@code true}. This method should not run on the main thread.
 *
 * @param media The {@link FeedMedia} object to be converted.
 * @return {@link MediaInfo} object in a format proper for casting.
 */
public static MediaInfo from(FeedMedia media) {
    if (media == null) {
        return null;
    }
    MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
    if (media.getItem() == null) {
        throw new IllegalStateException("item is null");
    // media.setItem(DBReader.getFeedItem(media.getItemId()));
    }
    FeedItem feedItem = media.getItem();
    if (feedItem != null) {
        metadata.putString(MediaMetadata.KEY_TITLE, media.getEpisodeTitle());
        String subtitle = media.getFeedTitle();
        if (subtitle != null) {
            metadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle);
        }
        // Manual because cast does not support embedded images
        String url = feedItem.getImageUrl() == null ? feedItem.getFeed().getImageUrl() : feedItem.getImageUrl();
        if (!TextUtils.isEmpty(url)) {
            metadata.addImage(new WebImage(Uri.parse(url)));
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(media.getItem().getPubDate());
        metadata.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar);
        Feed feed = feedItem.getFeed();
        if (feed != null) {
            if (!TextUtils.isEmpty(feed.getAuthor())) {
                metadata.putString(MediaMetadata.KEY_ARTIST, feed.getAuthor());
            }
            if (!TextUtils.isEmpty(feed.getDownload_url())) {
                metadata.putString(CastUtils.KEY_FEED_URL, feed.getDownload_url());
            }
            if (!TextUtils.isEmpty(feed.getLink())) {
                metadata.putString(CastUtils.KEY_FEED_WEBSITE, feed.getLink());
            }
        }
        if (!TextUtils.isEmpty(feedItem.getItemIdentifier())) {
            metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, feedItem.getItemIdentifier());
        } else {
            metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, media.getStreamUrl());
        }
        if (!TextUtils.isEmpty(feedItem.getLink())) {
            metadata.putString(CastUtils.KEY_EPISODE_LINK, feedItem.getLink());
        }
    }
    // This field only identifies the id on the device that has the original version.
    // Idea is to perhaps, on a first approach, check if the version on the local DB with the
    // same id matches the remote object, and if not then search for episode and feed identifiers.
    // This at least should make media recognition for a single device much quicker.
    metadata.putInt(CastUtils.KEY_MEDIA_ID, ((Long) media.getIdentifier()).intValue());
    // A way to identify different casting media formats in case we change it in the future and
    // senders with different versions share a casting device.
    metadata.putInt(CastUtils.KEY_FORMAT_VERSION, CastUtils.FORMAT_VERSION_VALUE);
    metadata.putString(CastUtils.KEY_STREAM_URL, media.getStreamUrl());
    MediaInfo.Builder builder = new MediaInfo.Builder(media.getStreamUrl()).setContentType(media.getMime_type()).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(metadata);
    if (media.getDuration() > 0) {
        builder.setStreamDuration(media.getDuration());
    }
    return builder.build();
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Calendar(java.util.Calendar) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 14 with FeedItem

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

the class PlaybackService method loadChildrenSynchronous.

private List<MediaBrowserCompat.MediaItem> loadChildrenSynchronous(@NonNull String parentId) throws InterruptedException {
    List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
    if (parentId.equals(getResources().getString(R.string.app_name))) {
        mediaItems.add(createBrowsableMediaItem(R.string.queue_label, R.drawable.ic_playlist_black, DBReader.getQueue().size()));
        mediaItems.add(createBrowsableMediaItem(R.string.downloads_label, R.drawable.ic_download_black, DBReader.getDownloadedItems().size()));
        List<Feed> feeds = DBReader.getFeedList();
        for (Feed feed : feeds) {
            mediaItems.add(createBrowsableMediaItemForFeed(feed));
        }
        return mediaItems;
    }
    List<FeedItem> feedItems;
    if (parentId.equals(getResources().getString(R.string.queue_label))) {
        feedItems = DBReader.getQueue();
    } else if (parentId.equals(getResources().getString(R.string.downloads_label))) {
        feedItems = DBReader.getDownloadedItems();
    } else if (parentId.startsWith("FeedId:")) {
        long feedId = Long.parseLong(parentId.split(":")[1]);
        feedItems = DBReader.getFeedItemList(DBReader.getFeed(feedId));
    } else {
        Log.e(TAG, "Parent ID not found: " + parentId);
        return null;
    }
    int count = 0;
    for (FeedItem feedItem : feedItems) {
        if (feedItem.getMedia() != null && feedItem.getMedia().getMediaItem() != null) {
            mediaItems.add(feedItem.getMedia().getMediaItem());
            if (++count >= MAX_ANDROID_AUTO_EPISODES_PER_FEED) {
                break;
            }
        }
    }
    return mediaItems;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 15 with FeedItem

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

the class DBReader method loadTagsOfFeedItemList.

private static void loadTagsOfFeedItemList(List<FeedItem> items) {
    LongList favoriteIds = getFavoriteIDList();
    LongList queueIds = getQueueIDList();
    for (FeedItem item : items) {
        if (favoriteIds.contains(item.getId())) {
            item.addTag(FeedItem.TAG_FAVORITE);
        }
        if (queueIds.contains(item.getId())) {
            item.addTag(FeedItem.TAG_QUEUE);
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) LongList(de.danoeh.antennapod.core.util.LongList)

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