summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2022-01-22 23:38:12 +0100
committerGitHub <noreply@github.com>2022-01-22 23:38:12 +0100
commit02241126c5f95f61a42ba64a54dc936fc0273f57 (patch)
tree9b0344ca016fe36be538399c2932d13dee9b6716
parentc09d671826a312f47ad35b8904fc7ce75bc414b4 (diff)
parent1837ce30d1616639a327271be657a9ef40a575b9 (diff)
downloadantennapod-02241126c5f95f61a42ba64a54dc936fc0273f57.zip
Merge pull request #5666 from ByteHamster/chapter-merging
Improvements to chapter merging
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/ChapterMerger.java16
-rw-r--r--parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ChapterReader.java2
2 files changed, 16 insertions, 2 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/ChapterMerger.java b/core/src/main/java/de/danoeh/antennapod/core/feed/ChapterMerger.java
index 80e669939..9bbab7251 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/ChapterMerger.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/ChapterMerger.java
@@ -37,7 +37,7 @@ public class ChapterMerger {
if (Math.abs(chapterTarget.getStart() - chapterOther.getStart()) > 1000) {
Log.e(TAG, "Chapter lists are too different. Cancelling merge.");
- return chapters1;
+ return score(chapters1) > score(chapters2) ? chapters1 : chapters2;
}
if (TextUtils.isEmpty(chapterTarget.getImageUrl())) {
@@ -53,4 +53,18 @@ public class ChapterMerger {
return chapters2;
}
}
+
+ /**
+ * Tries to give a score that can determine which list of chapters a user might want to see.
+ */
+ private static int score(List<Chapter> chapters) {
+ int score = 0;
+ for (Chapter chapter : chapters) {
+ score = score
+ + (TextUtils.isEmpty(chapter.getTitle()) ? 0 : 1)
+ + (TextUtils.isEmpty(chapter.getLink()) ? 0 : 1)
+ + (TextUtils.isEmpty(chapter.getImageUrl()) ? 0 : 1);
+ }
+ return score;
+ }
}
diff --git a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ChapterReader.java b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ChapterReader.java
index 81bfa67b6..ac79432b5 100644
--- a/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ChapterReader.java
+++ b/parser/media/src/main/java/de/danoeh/antennapod/parser/media/id3/ChapterReader.java
@@ -82,7 +82,7 @@ public class ChapterReader extends ID3Reader {
break;
case FRAME_ID_PICTURE:
byte encoding = readByte();
- String mime = readEncodedString(encoding, frameHeader.getSize());
+ String mime = readIsoStringNullTerminated(frameHeader.getSize());
byte type = readByte();
String description = readEncodedString(encoding, frameHeader.getSize());
Log.d(TAG, "Found apic: " + mime + "," + description);