summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2021-08-28 09:52:45 +0200
committerByteHamster <info@bytehamster.com>2021-08-28 10:59:26 +0200
commitca64739f363e585758b6ada6cc4e6c9d43191724 (patch)
tree3b5b6634792a3997d9302053e628ec8cda205ff5 /model
parentddae5e2278fe6b6e950576cdc460ec7ffe761d5d (diff)
downloadantennapod-ca64739f363e585758b6ada6cc4e6c9d43191724.zip
Moved media file parser to its own module
Diffstat (limited to 'model')
-rw-r--r--model/src/main/java/de/danoeh/antennapod/model/feed/EmbeddedChapterImage.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/EmbeddedChapterImage.java b/model/src/main/java/de/danoeh/antennapod/model/feed/EmbeddedChapterImage.java
new file mode 100644
index 000000000..793d39433
--- /dev/null
+++ b/model/src/main/java/de/danoeh/antennapod/model/feed/EmbeddedChapterImage.java
@@ -0,0 +1,73 @@
+package de.danoeh.antennapod.model.feed;
+
+import android.text.TextUtils;
+import de.danoeh.antennapod.model.playback.Playable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class EmbeddedChapterImage {
+ private static final Pattern EMBEDDED_IMAGE_MATCHER = Pattern.compile("embedded-image://(\\d+)/(\\d+)");
+
+ private final int position;
+ private final int length;
+ private final String imageUrl;
+ private final Playable media;
+
+ public EmbeddedChapterImage(Playable media, String imageUrl) {
+ this.media = media;
+ this.imageUrl = imageUrl;
+ Matcher m = EMBEDDED_IMAGE_MATCHER.matcher(imageUrl);
+ if (m.find()) {
+ this.position = Integer.parseInt(m.group(1));
+ this.length = Integer.parseInt(m.group(2));
+ } else {
+ throw new IllegalArgumentException("Not an embedded chapter");
+ }
+ }
+
+ public static String makeUrl(int position, int length) {
+ return "embedded-image://" + position + "/" + length;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public Playable getMedia() {
+ return media;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ EmbeddedChapterImage that = (EmbeddedChapterImage) o;
+ return TextUtils.equals(imageUrl, that.imageUrl);
+ }
+
+ @Override
+ public int hashCode() {
+ return imageUrl.hashCode();
+ }
+
+ private static boolean isEmbeddedChapterImage(String imageUrl) {
+ return EMBEDDED_IMAGE_MATCHER.matcher(imageUrl).matches();
+ }
+
+ public static Object getModelFor(Playable media, int chapter) {
+ String imageUrl = media.getChapters().get(chapter).getImageUrl();
+ if (isEmbeddedChapterImage(imageUrl)) {
+ return new EmbeddedChapterImage(media, imageUrl);
+ } else {
+ return imageUrl;
+ }
+ }
+}