Search in sources :

Example 11 with FeedMedia

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

the class PlaybackService method bufferUpdate.

@Subscribe(threadMode = ThreadMode.MAIN)
@SuppressWarnings("unused")
public void bufferUpdate(BufferUpdateEvent event) {
    if (event.hasEnded()) {
        Playable playable = getPlayable();
        if (getPlayable() instanceof FeedMedia && playable.getDuration() <= 0 && mediaPlayer.getDuration() > 0) {
            // Playable is being streamed and does not have a duration specified in the feed
            playable.setDuration(mediaPlayer.getDuration());
            DBWriter.setFeedMedia((FeedMedia) playable);
            updateNotificationAndMediaSession(playable);
        }
    }
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 12 with FeedMedia

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

the class APCleanupAlgorithm method getCandidates.

@NonNull
private List<FeedItem> getCandidates() {
    List<FeedItem> candidates = new ArrayList<>();
    List<FeedItem> downloadedItems = DBReader.getDownloadedItems();
    Date mostRecentDateForDeletion = calcMostRecentDateForDeletion(new Date());
    for (FeedItem item : downloadedItems) {
        if (item.hasMedia() && item.getMedia().isDownloaded() && !item.isTagged(FeedItem.TAG_QUEUE) && item.isPlayed() && !item.isTagged(FeedItem.TAG_FAVORITE)) {
            FeedMedia media = item.getMedia();
            // to now
            if (media != null && media.getPlaybackCompletionDate() != null && media.getPlaybackCompletionDate().before(mostRecentDateForDeletion)) {
                candidates.add(item);
            }
        }
    }
    return candidates;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) NonNull(androidx.annotation.NonNull)

Example 13 with FeedMedia

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

the class DownloadService method writeFileUrl.

/**
 * Creates the destination file and writes FeedMedia File_url directly after starting download
 * to make it possible to resume download after the service was killed by the system.
 */
private void writeFileUrl(DownloadRequest request) {
    if (request.getFeedfileType() != FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
        return;
    }
    File dest = new File(request.getDestination());
    if (!dest.exists()) {
        try {
            dest.createNewFile();
        } catch (IOException e) {
            Log.e(TAG, "Unable to create file");
        }
    }
    if (dest.exists()) {
        Log.d(TAG, "Writing file url");
        FeedMedia media = DBReader.getFeedMedia(request.getFeedfileId());
        if (media == null) {
            Log.d(TAG, "No media");
            return;
        }
        media.setFile_url(request.getDestination());
        try {
            DBWriter.setFeedMedia(media).get();
        } catch (InterruptedException e) {
            Log.e(TAG, "writeFileUrl was interrupted");
        } catch (ExecutionException e) {
            Log.e(TAG, "ExecutionException in writeFileUrl: " + e.getMessage());
        }
    }
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File)

Example 14 with FeedMedia

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

the class FeedItemDuplicateGuesser method seemDuplicates.

public static boolean seemDuplicates(FeedItem item1, FeedItem item2) {
    if (sameAndNotEmpty(item1.getItemIdentifier(), item2.getItemIdentifier())) {
        return true;
    }
    FeedMedia media1 = item1.getMedia();
    FeedMedia media2 = item2.getMedia();
    if (media1 == null || media2 == null) {
        return false;
    }
    if (sameAndNotEmpty(media1.getStreamUrl(), media2.getStreamUrl())) {
        return true;
    }
    return titlesLookSimilar(item1, item2) && datesLookSimilar(item1, item2) && durationsLookSimilar(media1, media2) && TextUtils.equals(media1.getMime_type(), media2.getMime_type());
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 15 with FeedMedia

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

the class DbCleanupTests method testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia.

/**
 * Reproduces a bug where DBTasks.performAutoCleanup(android.content.Context) would use the ID
 * of the FeedItem in the call to DBWriter.deleteFeedMediaOfItem instead of the ID of the FeedMedia.
 * This would cause the wrong item to be deleted.
 */
@Test
public void testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia() throws IOException {
    // add feed with no enclosures so that item ID != media ID
    saveFeedlist(1, 10, false);
    // add candidate for performAutoCleanup
    List<Feed> feeds = saveFeedlist(1, 1, true);
    FeedMedia m = feeds.get(0).getItems().get(0).getMedia();
    // noinspection ConstantConditions
    m.setDownloaded(true);
    m.setFile_url("file");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setMedia(m);
    adapter.close();
    testPerformAutoCleanupShouldNotDeleteBecauseInQueue();
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Aggregations

FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)91 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)46 Test (org.junit.Test)28 Feed (de.danoeh.antennapod.model.feed.Feed)26 Date (java.util.Date)25 ArrayList (java.util.ArrayList)18 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)15 File (java.io.File)15 Playable (de.danoeh.antennapod.model.playback.Playable)8 View (android.view.View)6 NonNull (androidx.annotation.NonNull)6 Context (android.content.Context)5 Log (android.util.Log)5 PlaybackServiceStarter (de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter)5 Cursor (android.database.Cursor)4 Nullable (androidx.annotation.Nullable)4 R (de.danoeh.antennapod.R)4 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)4 DownloadService (de.danoeh.antennapod.core.service.download.DownloadService)4 Intent (android.content.Intent)3