mirror of
https://github.com/imputnet/cobalt.git
synced 2026-10-25 03:22:19 +00:00
fix(android): download original X images
This commit is contained in:
parent
acca00242d
commit
90d421c4fb
2 changed files with 23 additions and 1 deletions
|
|
@ -317,7 +317,7 @@ class XPostResolver(
|
|||
val item = items.optJSONObject(index) ?: continue
|
||||
val type = item.optString("type")
|
||||
val source = when (type) {
|
||||
"photo" -> item.optString("media_url_https")
|
||||
"photo" -> originalPhotoUrl(item.optString("media_url_https"))
|
||||
"video", "animated_gif" -> videoCandidates(item.optJSONObject("video_info")?.optJSONArray("variants")).firstOrNull().orEmpty()
|
||||
else -> ""
|
||||
}
|
||||
|
|
@ -331,6 +331,15 @@ class XPostResolver(
|
|||
}
|
||||
}
|
||||
|
||||
/** Requests the original X image instead of the default 1200-pixel rendition. */
|
||||
internal fun originalPhotoUrl(rawUrl: String): String {
|
||||
if (rawUrl.isBlank()) return ""
|
||||
return rawUrl.toHttpUrl().newBuilder()
|
||||
.setQueryParameter("name", "orig")
|
||||
.build()
|
||||
.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns only directly downloadable MP4 variants. X also exposes HLS manifests,
|
||||
* which cannot be saved as a video file by the foreground downloader.
|
||||
|
|
|
|||
|
|
@ -34,6 +34,18 @@ class XPostResolverTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun requestsOriginalPhotosLikeCobalt() {
|
||||
assertEquals(
|
||||
"https://pbs.twimg.com/media/example.jpg?name=orig",
|
||||
resolver.originalPhotoUrl("https://pbs.twimg.com/media/example.jpg"),
|
||||
)
|
||||
assertEquals(
|
||||
"https://pbs.twimg.com/media/example?format=jpg&name=orig",
|
||||
resolver.originalPhotoUrl("https://pbs.twimg.com/media/example?format=jpg&name=small"),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ranksDirectVariantsByResolutionThenMuxedAudioVideoBitrate() {
|
||||
val variants = listOf(
|
||||
|
|
@ -123,6 +135,7 @@ class XPostResolverTest {
|
|||
val post = resolver.resolve("123")
|
||||
|
||||
assertEquals("example", post.metadata.username)
|
||||
assertEquals("https://pbs.twimg.com/media/example.jpg?name=orig", post.media.single().sourceUrl)
|
||||
assertEquals(0, nonSyndicationRequests)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue