Speed up chapter parsing
This commit is contained in:
parent
25dd4902ba
commit
9624d8ce9e
|
@ -9,6 +9,7 @@ import android.util.Log;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
|
@ -218,7 +219,8 @@ public class LocalFeedUpdater {
|
|||
mediaMetadataRetriever.close();
|
||||
|
||||
try (InputStream inputStream = context.getContentResolver().openInputStream(file.getUri())) {
|
||||
Id3MetadataReader reader = new Id3MetadataReader(new CountingInputStream(inputStream));
|
||||
Id3MetadataReader reader = new Id3MetadataReader(
|
||||
new CountingInputStream(new BufferedInputStream(inputStream)));
|
||||
reader.readInputStream();
|
||||
item.setDescriptionIfLonger(reader.getComment());
|
||||
} catch (IOException | ID3ReaderException e) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import okhttp3.Request;
|
|||
import okhttp3.Response;
|
||||
import org.apache.commons.io.input.CountingInputStream;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -120,17 +121,17 @@ public class ChapterUtils {
|
|||
if (!source.exists()) {
|
||||
throw new IOException("Local file does not exist");
|
||||
}
|
||||
return new CountingInputStream(new FileInputStream(source));
|
||||
return new CountingInputStream(new BufferedInputStream(new FileInputStream(source)));
|
||||
} else if (playable.getStreamUrl().startsWith(ContentResolver.SCHEME_CONTENT)) {
|
||||
Uri uri = Uri.parse(playable.getStreamUrl());
|
||||
return new CountingInputStream(context.getContentResolver().openInputStream(uri));
|
||||
return new CountingInputStream(new BufferedInputStream(context.getContentResolver().openInputStream(uri)));
|
||||
} else {
|
||||
Request request = new Request.Builder().url(playable.getStreamUrl()).build();
|
||||
Response response = AntennapodHttpClient.getHttpClient().newCall(request).execute();
|
||||
if (response.body() == null) {
|
||||
throw new IOException("Body is null");
|
||||
}
|
||||
return new CountingInputStream(response.body().byteStream());
|
||||
return new CountingInputStream(new BufferedInputStream(response.body().byteStream()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +172,7 @@ public class ChapterUtils {
|
|||
|
||||
@NonNull
|
||||
private static List<Chapter> readOggChaptersFromInputStream(InputStream input) throws VorbisCommentReaderException {
|
||||
VorbisCommentChapterReader reader = new VorbisCommentChapterReader(input);
|
||||
VorbisCommentChapterReader reader = new VorbisCommentChapterReader(new BufferedInputStream(input));
|
||||
reader.readInputStream();
|
||||
List<Chapter> chapters = reader.getChapters();
|
||||
if (chapters == null) {
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ID3Reader {
|
|||
}
|
||||
|
||||
protected void readFrame(@NonNull FrameHeader frameHeader) throws IOException, ID3ReaderException {
|
||||
Log.d(TAG, "Skipping frame: " + frameHeader.toString());
|
||||
Log.d(TAG, "Skipping frame: " + frameHeader.getId() + ", size: " + frameHeader.getSize());
|
||||
skipBytes(frameHeader.getSize());
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ public class ID3Reader {
|
|||
|
||||
@NonNull
|
||||
FrameHeader readFrameHeader() throws IOException {
|
||||
String id = readIsoStringFixed(FRAME_ID_LENGTH);
|
||||
String id = readPlainBytesToString(FRAME_ID_LENGTH);
|
||||
int size = readInt();
|
||||
if (tagHeader != null && tagHeader.getVersion() >= 0x0400) {
|
||||
size = unsynchsafe(size);
|
||||
|
@ -136,15 +136,14 @@ public class ID3Reader {
|
|||
return readEncodedString(encoding, max - 1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed")
|
||||
protected String readIsoStringFixed(int length) throws IOException {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
protected String readPlainBytesToString(int length) throws IOException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int bytesRead = 0;
|
||||
while (bytesRead < length) {
|
||||
bytes.write(readByte());
|
||||
stringBuilder.append((char) readByte());
|
||||
bytesRead++;
|
||||
}
|
||||
return Charset.forName("ISO-8859-1").newDecoder().decode(ByteBuffer.wrap(bytes.toByteArray())).toString();
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
protected String readIsoStringNullTerminated(int max) throws IOException {
|
||||
|
|
|
@ -1,18 +1,7 @@
|
|||
package de.danoeh.antennapod.parser.media.id3.model;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class FrameHeader extends Header {
|
||||
private final short flags;
|
||||
|
||||
public FrameHeader(String id, int size, short flags) {
|
||||
super(id, size);
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String toString() {
|
||||
return String.format("FrameHeader [flags=%s, id=%s, size=%s]", Integer.toBinaryString(flags), id, size);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue