use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.
the class AtomGenerator method writeFeed.
@Override
public void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException {
if (feed == null)
throw new IllegalArgumentException("feed = null");
if (outputStream == null)
throw new IllegalArgumentException("outputStream = null");
if (encoding == null)
throw new IllegalArgumentException("encoding = null");
XmlSerializer xml = Xml.newSerializer();
xml.setOutput(outputStream, encoding);
xml.startDocument(encoding, null);
xml.startTag(null, "feed");
xml.attribute(null, "xmlns", NS_ATOM);
// Write Feed data
if (feed.getIdentifyingValue() != null) {
xml.startTag(null, "id");
xml.text(feed.getIdentifyingValue());
xml.endTag(null, "id");
}
if (feed.getTitle() != null) {
xml.startTag(null, "title");
xml.text(feed.getTitle());
xml.endTag(null, "title");
}
if (feed.getLink() != null) {
xml.startTag(null, "link");
xml.attribute(null, "rel", "alternate");
xml.attribute(null, "href", feed.getLink());
xml.endTag(null, "link");
}
if (feed.getDescription() != null) {
xml.startTag(null, "subtitle");
xml.text(feed.getDescription());
xml.endTag(null, "subtitle");
}
if (feed.getPaymentLink() != null) {
GeneratorUtil.addPaymentLink(xml, feed.getPaymentLink(), false);
}
// Write FeedItem data
if (feed.getItems() != null) {
for (FeedItem item : feed.getItems()) {
xml.startTag(null, "entry");
if (item.getIdentifyingValue() != null) {
xml.startTag(null, "id");
xml.text(item.getIdentifyingValue());
xml.endTag(null, "id");
}
if (item.getTitle() != null) {
xml.startTag(null, "title");
xml.text(item.getTitle());
xml.endTag(null, "title");
}
if (item.getLink() != null) {
xml.startTag(null, "link");
xml.attribute(null, "rel", "alternate");
xml.attribute(null, "href", item.getLink());
xml.endTag(null, "link");
}
if (item.getPubDate() != null) {
xml.startTag(null, "published");
if ((flags & FEATURE_USE_RFC3339LOCAL) != 0) {
xml.text(DateUtils.formatRFC3339Local(item.getPubDate()));
} else {
xml.text(DateUtils.formatRFC3339UTC(item.getPubDate()));
}
xml.endTag(null, "published");
}
if (item.getDescription() != null) {
xml.startTag(null, "content");
xml.text(item.getDescription());
xml.endTag(null, "content");
}
if (item.getMedia() != null) {
FeedMedia media = item.getMedia();
xml.startTag(null, "link");
xml.attribute(null, "rel", "enclosure");
xml.attribute(null, "href", media.getDownload_url());
xml.attribute(null, "type", media.getMime_type());
xml.attribute(null, "length", String.valueOf(media.getSize()));
xml.endTag(null, "link");
}
if (item.getPaymentLink() != null) {
GeneratorUtil.addPaymentLink(xml, item.getPaymentLink(), false);
}
xml.endTag(null, "entry");
}
}
xml.endTag(null, "feed");
xml.endDocument();
}
use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.
the class UITestUtils method addHostedFeedData.
/**
* Adds feeds, images and episodes to the webserver for testing purposes.
*/
public void addHostedFeedData() throws IOException {
if (feedDataHosted)
throw new IllegalStateException("addHostedFeedData was called twice on the same instance");
for (int i = 0; i < NUM_FEEDS; i++) {
File bitmapFile = newBitmapFile("image" + i);
FeedImage image = new FeedImage(0, "image " + i, null, hostFile(bitmapFile), false);
Feed feed = new Feed(0, null, "Title " + i, "http://example.com/" + i, "Description of feed " + i, "http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, image, null, "http://example.com/feed/src/" + i, false);
image.setOwner(feed);
// create items
List<FeedItem> items = new ArrayList<FeedItem>();
for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) {
FeedItem item = new FeedItem(j, "Feed " + (i + 1) + ": Item " + (j + 1), "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), FeedItem.UNPLAYED, feed);
items.add(item);
File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0, 0));
}
feed.setItems(items);
feed.setDownload_url(hostFeed(feed));
hostedFeeds.add(feed);
}
feedDataHosted = true;
}
use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.
the class UITestUtils method addLocalFeedData.
/**
* Adds feeds, images and episodes to the local database. This method will also call addHostedFeedData if it has not
* been called yet.
*
* Adds one item of each feed to the queue and to the playback history.
*
* This method should NOT be called if the testing class wants to download the hosted feed data.
*
* @param downloadEpisodes true if episodes should also be marked as downloaded.
*/
public void addLocalFeedData(boolean downloadEpisodes) throws Exception {
if (localFeedDataAdded) {
Log.w(TAG, "addLocalFeedData was called twice on the same instance");
// might be a flaky test, this is actually not that severe
return;
}
if (!feedDataHosted) {
addHostedFeedData();
}
List<FeedItem> queue = new ArrayList<>();
for (Feed feed : hostedFeeds) {
feed.setDownloaded(true);
if (feed.getImage() != null) {
FeedImage image = feed.getImage();
int fileId = Integer.parseInt(StringUtils.substringAfter(image.getDownload_url(), "files/"));
image.setFile_url(server.accessFile(fileId).getAbsolutePath());
image.setDownloaded(true);
}
if (downloadEpisodes) {
for (FeedItem item : feed.getItems()) {
if (item.hasMedia()) {
FeedMedia media = item.getMedia();
int fileId = Integer.parseInt(StringUtils.substringAfter(media.getDownload_url(), "files/"));
media.setFile_url(server.accessFile(fileId).getAbsolutePath());
media.setDownloaded(true);
}
}
}
queue.add(feed.getItems().get(0));
feed.getItems().get(1).getMedia().setPlaybackCompletionDate(new Date());
}
localFeedDataAdded = true;
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()]));
adapter.setQueue(queue);
adapter.close();
EventDistributor.getInstance().sendFeedUpdateBroadcast();
EventBus.getDefault().post(QueueEvent.setQueue(queue));
}
use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.
the class UITestUtilsTest method addLocalFeedDataCheck.
private void addLocalFeedDataCheck(boolean downloadEpisodes) throws Exception {
uiTestUtils.addLocalFeedData(downloadEpisodes);
assertNotNull(uiTestUtils.hostedFeeds);
assertFalse(uiTestUtils.hostedFeeds.isEmpty());
for (Feed feed : uiTestUtils.hostedFeeds) {
assertTrue(feed.getId() != 0);
if (feed.getImage() != null) {
assertTrue(feed.getImage().getId() != 0);
}
for (FeedItem item : feed.getItems()) {
assertTrue(item.getId() != 0);
if (item.hasMedia()) {
assertTrue(item.getMedia().getId() != 0);
if (downloadEpisodes) {
assertTrue(item.getMedia().isDownloaded());
assertNotNull(item.getMedia().getFile_url());
File file = new File(item.getMedia().getFile_url());
assertTrue(file.exists());
}
}
}
}
}
use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.
the class UITestUtilsTest method testAddHostedFeeds.
public void testAddHostedFeeds() throws Exception {
uiTestUtils.addHostedFeedData();
final List<Feed> feeds = uiTestUtils.hostedFeeds;
assertNotNull(feeds);
assertFalse(feeds.isEmpty());
for (Feed feed : feeds) {
testUrlReachable(feed.getDownload_url());
if (feed.getImage() != null) {
testUrlReachable(feed.getImage().getDownload_url());
}
for (FeedItem item : feed.getItems()) {
if (item.hasMedia()) {
testUrlReachable(item.getMedia().getDownload_url());
}
}
}
}
Aggregations