Skip to content

Commit

Permalink
Let the ogg reader take a file, not an input stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulWoitaschek committed Jul 30, 2017
1 parent a6d1c27 commit 95dc920
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/de/ph1b/audiobook/features/BookAdder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ import javax.inject.Singleton
val marks = when (f.extension) {
"mp3" -> iD3ChapterReader.read(f)
"mp4", "m4a", "m4b", "aac" -> mp4ChapterReader.readChapters(f)
"opus", "ogg", "oga" -> f.inputStream().use { oggChapterReader.read(it) }
"opus", "ogg", "oga" -> oggChapterReader.read(f)
"mka", "mkv", "webm" -> matroskaChapterReader.read(f)
else -> emptyMap()
}.toSparseArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import de.ph1b.audiobook.chapterreader.ogg.vorbisComment.*
import de.ph1b.audiobook.common.Logger
import de.ph1b.audiobook.common.readAmountOfBytes
import de.ph1b.audiobook.common.startsWith
import java.io.BufferedInputStream
import java.io.ByteArrayInputStream
import java.io.IOException
import java.io.InputStream
import java.io.*
import javax.inject.Inject


Expand All @@ -25,7 +22,11 @@ import javax.inject.Inject
private val VORBIS_HEAD_MAGIC = "${1.toChar()}vorbis".toByteArray()
private val VORBIS_TAGS_MAGIC = "${3.toChar()}vorbis".toByteArray()

fun read(inputStream: InputStream): Map<Int, String> {
fun read(file: File) = file.inputStream().use {
read(it)
}

private fun read(inputStream: InputStream): Map<Int, String> {
try {
val oggPages = readOggPages(BufferedInputStream(inputStream))
val streams = demuxOggStreams(oggPages).values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class OggChapterReadingTest {

@Test
fun readChaptersFromOggOpusTest() {
val simpleOpusResource = javaClass.classLoader.getResource("ogg/simple.opus")
val chapters = File(simpleOpusResource.path).inputStream().use {
oggChapterReader.read(it)
}
val file = File(javaClass.classLoader.getResource("ogg/simple.opus").file)
val chapters = oggChapterReader.read(file)

assertThat(chapters).isEqualTo(mapOf(
0 to "Chapter 1",
Expand All @@ -32,10 +30,8 @@ class OggChapterReadingTest {

@Test
fun readChaptersFromOggVorbisTest() {
val simpleOpusResource = javaClass.classLoader.getResource("ogg/simple_vorbis.ogg")
val chapters = File(simpleOpusResource.path).inputStream().use {
oggChapterReader.read(it)
}
val file = File(javaClass.classLoader.getResource("ogg/simple_vorbis.ogg").file)
val chapters = oggChapterReader.read(file)

assertThat(chapters).isEqualTo(mapOf(
0 to "Part 1",
Expand Down

0 comments on commit 95dc920

Please sign in to comment.