Merge pull request #5666 from ByteHamster/chapter-merging

Improvements to chapter merging
This commit is contained in:
ByteHamster 2022-01-22 23:38:12 +01:00 committed by GitHub
commit 02241126c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -37,7 +37,7 @@ public class ChapterMerger {
if (Math.abs(chapterTarget.getStart() - chapterOther.getStart()) > 1000) { if (Math.abs(chapterTarget.getStart() - chapterOther.getStart()) > 1000) {
Log.e(TAG, "Chapter lists are too different. Cancelling merge."); Log.e(TAG, "Chapter lists are too different. Cancelling merge.");
return chapters1; return score(chapters1) > score(chapters2) ? chapters1 : chapters2;
} }
if (TextUtils.isEmpty(chapterTarget.getImageUrl())) { if (TextUtils.isEmpty(chapterTarget.getImageUrl())) {
@ -53,4 +53,18 @@ public class ChapterMerger {
return chapters2; 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;
}
} }

View File

@ -82,7 +82,7 @@ public class ChapterReader extends ID3Reader {
break; break;
case FRAME_ID_PICTURE: case FRAME_ID_PICTURE:
byte encoding = readByte(); byte encoding = readByte();
String mime = readEncodedString(encoding, frameHeader.getSize()); String mime = readIsoStringNullTerminated(frameHeader.getSize());
byte type = readByte(); byte type = readByte();
String description = readEncodedString(encoding, frameHeader.getSize()); String description = readEncodedString(encoding, frameHeader.getSize());
Log.d(TAG, "Found apic: " + mime + "," + description); Log.d(TAG, "Found apic: " + mime + "," + description);