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);
}
}
}
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;
}
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());
}
}
}
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());
}
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();
}
Aggregations