Search in sources :

Example 1 with FeedImage

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

the class DBWriterTest method testDeleteFeedWithQueueItems.

public void testDeleteFeedWithQueueItems() throws ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    // create Feed image
    File imgFile = new File(destFolder, "image");
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);
    List<File> itemFiles = new ArrayList<File>();
    // create items with downloaded media files
    for (int i = 0; i < 10; i++) {
        FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
        feed.getItems().add(item);
        File enc = new File(destFolder, "file " + i);
        itemFiles.add(enc);
        FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", false, null, 0, 0);
        item.setMedia(media);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
    }
    List<FeedItem> queue = new ArrayList<FeedItem>();
    queue.addAll(feed.getItems());
    adapter.open();
    adapter.setQueue(queue);
    Cursor queueCursor = adapter.getQueueIDCursor();
    assertTrue(queueCursor.getCount() == queue.size());
    queueCursor.close();
    adapter.close();
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    for (FeedItem item : feed.getItems()) {
        c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
        assertTrue(c.getCount() == 0);
        c.close();
        c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
        assertTrue(c.getCount() == 0);
        c.close();
    }
    c = adapter.getQueueCursor();
    assertTrue(c.getCount() == 0);
    c.close();
    adapter.close();
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Date(java.util.Date) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 2 with FeedImage

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

the class DBWriterTest method testDeleteFeedNoItems.

public void testDeleteFeedNoItems() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(null);
    // create Feed image
    File imgFile = new File(destFolder, "image");
    assertTrue(imgFile.createNewFile());
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    // check if files still exist
    assertFalse(imgFile.exists());
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) Cursor(android.database.Cursor) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 3 with FeedImage

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

the class DBWriterTest method testDeleteFeedNoDownloadedFiles.

public void testDeleteFeedNoDownloadedFiles() throws ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<FeedItem>());
    // create Feed image
    File imgFile = new File(destFolder, "image");
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);
    List<File> itemFiles = new ArrayList<File>();
    // create items with downloaded media files
    for (int i = 0; i < 10; i++) {
        FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
        feed.getItems().add(item);
        File enc = new File(destFolder, "file " + i);
        itemFiles.add(enc);
        FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", false, null, 0, 0);
        item.setMedia(media);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
    }
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    for (FeedItem item : feed.getItems()) {
        c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
        assertTrue(c.getCount() == 0);
        c.close();
        c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
        assertTrue(c.getCount() == 0);
        c.close();
    }
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 4 with FeedImage

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

the class DBWriterTest method testDeleteFeedNoFeedMedia.

public void testDeleteFeedNoFeedMedia() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    // create Feed image
    File imgFile = new File(destFolder, "image");
    assertTrue(imgFile.createNewFile());
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);
    // create items
    for (int i = 0; i < 10; i++) {
        FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
        feed.getItems().add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
    }
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    // check if files still exist
    assertFalse(imgFile.exists());
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    for (FeedItem item : feed.getItems()) {
        c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
        assertTrue(c.getCount() == 0);
        c.close();
    }
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 5 with FeedImage

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

the class CastUtils method convertFromFeedMedia.

/**
     * Converts {@link FeedMedia} objects into a format suitable for sending to a Cast Device.
     * Before using this method, one should make sure {@link #isCastable(Playable)} returns
     * {@code true}.
     *
     * Unless media.{@link FeedMedia#loadMetadata() loadMetadata()} has already been called,
     * 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 convertFromFeedMedia(FeedMedia media) {
    if (media == null) {
        return null;
    }
    MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
    try {
        media.loadMetadata();
    } catch (Playable.PlayableException e) {
        Log.e(TAG, "Unable to load FeedMedia metadata", e);
    }
    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);
        }
        FeedImage image = feedItem.getImage();
        if (image != null && !TextUtils.isEmpty(image.getDownload_url())) {
            metadata.addImage(new WebImage(Uri.parse(image.getDownload_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(KEY_FEED_URL, feed.getDownload_url());
            }
            if (!TextUtils.isEmpty(feed.getLink())) {
                metadata.putString(KEY_FEED_WEBSITE, feed.getLink());
            }
        }
        if (!TextUtils.isEmpty(feedItem.getItemIdentifier())) {
            metadata.putString(KEY_EPISODE_IDENTIFIER, feedItem.getItemIdentifier());
        } else {
            metadata.putString(KEY_EPISODE_IDENTIFIER, media.getStreamUrl());
        }
        if (!TextUtils.isEmpty(feedItem.getLink())) {
            metadata.putString(KEY_EPISODE_LINK, feedItem.getLink());
        }
    }
    String notes = null;
    try {
        notes = media.loadShownotes().call();
    } catch (Exception e) {
        Log.e(TAG, "Unable to load FeedMedia notes", e);
    }
    if (notes != null) {
        if (notes.length() > EPISODE_NOTES_MAX_LENGTH) {
            notes = notes.substring(0, EPISODE_NOTES_MAX_LENGTH);
        }
        metadata.putString(KEY_EPISODE_NOTES, notes);
    }
    // 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(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(KEY_FORMAT_VERSION, FORMAT_VERSION_VALUE);
    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 : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) MediaInfo(com.google.android.gms.cast.MediaInfo) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) Calendar(java.util.Calendar) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) Feed(de.danoeh.antennapod.core.feed.Feed)

Aggregations

FeedImage (de.danoeh.antennapod.core.feed.FeedImage)16 Feed (de.danoeh.antennapod.core.feed.Feed)10 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)10 Cursor (android.database.Cursor)7 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)7 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)6 File (java.io.File)6 Date (java.util.Date)6 ArrayList (java.util.ArrayList)3 Chapter (de.danoeh.antennapod.core.feed.Chapter)2 ArrayMap (android.support.v4.util.ArrayMap)1 MediaInfo (com.google.android.gms.cast.MediaInfo)1 MediaMetadata (com.google.android.gms.cast.MediaMetadata)1 WebImage (com.google.android.gms.common.images.WebImage)1 FeedPreferences (de.danoeh.antennapod.core.feed.FeedPreferences)1 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)1 SyndElement (de.danoeh.antennapod.core.syndication.namespace.SyndElement)1 AtomText (de.danoeh.antennapod.core.syndication.namespace.atom.AtomText)1 Playable (de.danoeh.antennapod.core.util.playback.Playable)1 Calendar (java.util.Calendar)1