diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/HtmlParser.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/HtmlParser.kt index 9f77cd2f2..e76b66440 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/HtmlParser.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/HtmlParser.kt @@ -24,7 +24,6 @@ import com.vitorpamplona.amethyst.commons.preview.MetaTag import com.vitorpamplona.amethyst.commons.preview.MetaTagsParser import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import okhttp3.MediaType import okio.BufferedSource import okio.ByteString.Companion.decodeHex import okio.Options @@ -56,11 +55,11 @@ class HtmlParser { suspend fun parseHtml( source: BufferedSource, - type: MediaType, + type: Charset?, ): Sequence = withContext(Dispatchers.IO) { // sniff charset from Content-Type header or BOM - val sniffedCharset = type.charset() ?: source.readBomAsCharset() + val sniffedCharset = type ?: source.readBomAsCharset() if (sniffedCharset != null) { val content = source.readByteArray().toString(sniffedCharset) return@withContext MetaTagsParser.parse(content) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreview.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreview.kt index 3d25f3886..c7ea3eed4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreview.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreview.kt @@ -62,7 +62,7 @@ class UrlPreview { response.headers["Content-Type"]?.toMediaType() ?: throw IllegalArgumentException("Website returned unknown mimetype: ${response.headers["Content-Type"]}") if (mimeType.type == "text" && mimeType.subtype == "html") { - val metaTags = HtmlParser().parseHtml(response.body.source(), mimeType) + val metaTags = HtmlParser().parseHtml(response.body.source(), mimeType.charset()) val data = OpenGraphParser().extractUrlInfo(metaTags) UrlInfoItem(url, data.title, data.description, data.image, mimeType.toString()) } else if (mimeType.type == "image") {