Skip to content

Commit

Permalink
feat: support for uhd in bing (closes #186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Apr 15, 2024
1 parent d1aa1ea commit db1b9bd
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/src/main/java/com/bnyro/wallpaper/api/bi/BiApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ import com.bnyro.wallpaper.api.Api
import com.bnyro.wallpaper.db.obj.Wallpaper
import com.bnyro.wallpaper.util.RetrofitBuilder

class BiApi() : Api() {
class BiApi : Api() {
override val name: String = "Bing"
override val baseUrl: String = "https://www.bing.com"
override val filters: Map<String, List<String>> = mapOf(
"resolution" to listOf("1366x768", "1920x1080", "UHD")
)
private val previewResolution = "1366x768"

val api = RetrofitBuilder.create(baseUrl, Bing::class.java)

private fun getImgSrc(path: String, resolution: String): String {
return "$baseUrl${path}_${resolution}.jpg"
}

override suspend fun getWallpapers(page: Int): List<Wallpaper> {
// doesn't support pagination, at most 7 images are available
if (page != 1) return emptyList()
val resolution = getQuery("resolution")

return api.getImages().images.map {
val imgUrl = "$baseUrl${it.url}"
Wallpaper(
imgSrc = imgUrl,
imgSrc = getImgSrc(it.urlBase, resolution),
thumb = getImgSrc(it.urlBase, previewResolution),
title = it.title,
url = "$baseUrl${it.quiz}",
resolution = "1920x1080",
resolution = resolution,
// creation date doesn't contain any dividers by default
creationDate = it.startDate
?.replaceRange(6, 6, "-")
Expand All @@ -30,5 +39,8 @@ class BiApi() : Api() {
}

override suspend fun getRandomWallpaperUrl() = api.getImages(1).images
.firstOrNull()?.url?.let { "$baseUrl$it" }
.firstOrNull()
?.let {
getImgSrc(it.urlBase, getQuery("resolution"))
}
}

0 comments on commit db1b9bd

Please sign in to comment.