use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class DBTestUtils method saveFeedlist.
/**
* Use this method when tests involve chapters.
*/
public static List<Feed> saveFeedlist(int numFeeds, int numItems, boolean withMedia, boolean withChapters, int numChapters) {
if (numFeeds <= 0) {
throw new IllegalArgumentException("numFeeds<=0");
}
if (numItems < 0) {
throw new IllegalArgumentException("numItems<0");
}
List<Feed> feeds = new ArrayList<>();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
for (int i = 0; i < numFeeds; i++) {
Feed f = new Feed(0, null, "feed " + i, null, "link" + i, "descr", null, null, null, null, "id" + i, null, null, "url" + i, false, new FlattrStatus(), false, null, null, false);
f.setItems(new ArrayList<>());
for (int j = 0; j < numItems; j++) {
FeedItem item = new FeedItem(0, "item " + j, "id" + j, "link" + j, new Date(), FeedItem.PLAYED, f, withChapters);
if (withMedia) {
FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3");
item.setMedia(media);
}
if (withChapters) {
List<Chapter> chapters = new ArrayList<>();
item.setChapters(chapters);
for (int k = 0; k < numChapters; k++) {
chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k, item, "http://example.com"));
}
}
f.getItems().add(item);
}
Collections.sort(f.getItems(), new FeedItemPubdateComparator());
adapter.setCompleteFeed(f);
Assert.assertTrue(f.getId() != 0);
for (FeedItem item : f.getItems()) {
Assert.assertTrue(item.getId() != 0);
}
feeds.add(f);
}
adapter.close();
return feeds;
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class FeedHandlerTest method feedValid.
private void feedValid(Feed feed, Feed parsedFeed, String feedType) {
assertEquals(feed.getTitle(), parsedFeed.getTitle());
if (feedType.equals(Feed.TYPE_ATOM1)) {
assertEquals(feed.getFeedIdentifier(), parsedFeed.getFeedIdentifier());
} else {
assertEquals(feed.getLanguage(), parsedFeed.getLanguage());
}
assertEquals(feed.getLink(), parsedFeed.getLink());
assertEquals(feed.getDescription(), parsedFeed.getDescription());
assertEquals(feed.getPaymentLink(), parsedFeed.getPaymentLink());
if (feed.getImage() != null) {
FeedImage image = feed.getImage();
FeedImage parsedImage = parsedFeed.getImage();
assertNotNull(parsedImage);
assertEquals(image.getTitle(), parsedImage.getTitle());
assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
}
if (feed.getItems() != null) {
assertNotNull(parsedFeed.getItems());
assertEquals(feed.getItems().size(), parsedFeed.getItems().size());
for (int i = 0; i < feed.getItems().size(); i++) {
FeedItem item = feed.getItems().get(i);
FeedItem parsedItem = parsedFeed.getItems().get(i);
if (item.getItemIdentifier() != null)
assertEquals(item.getItemIdentifier(), parsedItem.getItemIdentifier());
assertEquals(item.getTitle(), parsedItem.getTitle());
assertEquals(item.getDescription(), parsedItem.getDescription());
assertEquals(item.getContentEncoded(), parsedItem.getContentEncoded());
assertEquals(item.getLink(), parsedItem.getLink());
assertEquals(item.getPubDate().getTime(), parsedItem.getPubDate().getTime());
assertEquals(item.getPaymentLink(), parsedItem.getPaymentLink());
if (item.hasMedia()) {
assertTrue(parsedItem.hasMedia());
FeedMedia media = item.getMedia();
FeedMedia parsedMedia = parsedItem.getMedia();
assertEquals(media.getDownload_url(), parsedMedia.getDownload_url());
assertEquals(media.getSize(), parsedMedia.getSize());
assertEquals(media.getMime_type(), parsedMedia.getMime_type());
}
if (item.hasItemImage()) {
assertTrue(parsedItem.hasItemImage());
FeedImage image = item.getImage();
FeedImage parsedImage = parsedItem.getImage();
assertEquals(image.getTitle(), parsedImage.getTitle());
assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
}
if (item.getChapters() != null) {
assertNotNull(parsedItem.getChapters());
assertEquals(item.getChapters().size(), parsedItem.getChapters().size());
List<Chapter> chapters = item.getChapters();
List<Chapter> parsedChapters = parsedItem.getChapters();
for (int j = 0; j < chapters.size(); j++) {
Chapter chapter = chapters.get(j);
Chapter parsedChapter = parsedChapters.get(j);
assertEquals(chapter.getTitle(), parsedChapter.getTitle());
assertEquals(chapter.getLink(), parsedChapter.getLink());
}
}
}
}
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class VorbisCommentChapterReader method onContentVectorValue.
@Override
public void onContentVectorValue(String key, String value) throws VorbisCommentReaderException {
if (BuildConfig.DEBUG)
Log.d(TAG, "Key: " + key + ", value: " + value);
String attribute = VorbisCommentChapter.getAttributeTypeFromKey(key);
int id = VorbisCommentChapter.getIDFromKey(key);
Chapter chapter = getChapterById(id);
if (attribute == null) {
if (getChapterById(id) == null) {
// new chapter
long start = VorbisCommentChapter.getStartTimeFromValue(value);
chapter = new VorbisCommentChapter(id);
chapter.setStart(start);
chapters.add(chapter);
} else {
throw new VorbisCommentReaderException("Found chapter with duplicate ID (" + key + ", " + value + ")");
}
} else if (attribute.equals(CHAPTER_ATTRIBUTE_TITLE)) {
if (chapter != null) {
chapter.setTitle(value);
}
} else if (attribute.equals(CHAPTER_ATTRIBUTE_LINK)) {
if (chapter != null) {
chapter.setLink(value);
}
}
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class ChapterUtils method getCurrentChapter.
/**
* Calls getCurrentChapter with current position.
*/
public static Chapter getCurrentChapter(Playable media) {
if (media.getChapters() != null) {
List<Chapter> chapters = media.getChapters();
Chapter current = null;
if (chapters != null) {
current = chapters.get(0);
for (Chapter sc : chapters) {
if (sc.getStart() > media.getPosition()) {
break;
} else {
current = sc;
}
}
}
return current;
} else {
return null;
}
}
use of de.danoeh.antennapod.core.feed.Chapter in project AntennaPod by AntennaPod.
the class ChapterUtils method readID3ChaptersFromPlayableFileUrl.
/**
* Uses the file URL of a media object of a feeditem to read its ID3
* chapters.
*/
public static void readID3ChaptersFromPlayableFileUrl(Playable p) {
if (p != null && p.localFileAvailable() && p.getLocalMediaUrl() != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle());
File source = new File(p.getLocalMediaUrl());
if (source.exists()) {
ChapterReader reader = new ChapterReader();
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(source));
reader.readInputStream(in);
List<Chapter> chapters = reader.getChapters();
if (chapters != null) {
Collections.sort(chapters, new ChapterStartTimeComparator());
processChapters(chapters, p);
if (chaptersValid(chapters)) {
p.setChapters(chapters);
Log.i(TAG, "Chapters loaded");
} else {
Log.e(TAG, "Chapter data was invalid");
}
} else {
Log.i(TAG, "ChapterReader could not find any ID3 chapters");
}
} catch (IOException | ID3ReaderException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} else {
Log.e(TAG, "Unable to read id3 chapters: Source doesn't exist");
}
}
}
Aggregations