-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for Microsoft Spotlight (closes #207)
- Loading branch information
Showing
13 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.bnyro.wallpaper.api.sp | ||
|
||
import com.bnyro.wallpaper.api.Api | ||
import com.bnyro.wallpaper.api.sp.obj.SpotlightImage | ||
import com.bnyro.wallpaper.db.obj.Wallpaper | ||
import com.bnyro.wallpaper.util.RetrofitHelper | ||
import kotlinx.serialization.decodeFromString | ||
import java.util.Locale | ||
|
||
// Credits to https://github.com/ORelio/Spotlight-Downloader/blob/master/SpotlightAPI.md | ||
|
||
class SpApi: Api() { | ||
override val name = "Windows Spotlight" | ||
override val baseUrl = "https://fd.api.iris.microsoft.com" | ||
override val filters: Map<String, List<String>> = mapOf( | ||
"country" to listOf("US") + Locale.getISOCountries().toList().filter { it != "US" }.sorted() | ||
) | ||
|
||
private val api = RetrofitHelper.create(baseUrl, Spotlight::class.java) | ||
|
||
override suspend fun getWallpapers(page: Int): List<Wallpaper> { | ||
val country = getQuery("country") | ||
val apiResp = api.getLatestPage(country = country, locale = "en-${country}") | ||
val images = apiResp.batchrsp.items.map { | ||
RetrofitHelper.json.decodeFromString<SpotlightImage>(it.item) | ||
} | ||
return images.map { | ||
Wallpaper( | ||
title = it.ad.title, | ||
imgSrc = it.ad.portraitImage.asset, | ||
author = it.ad.copyright, | ||
url = it.ad.ctaUri.replaceFirst("microsoft-edge:", "") | ||
) | ||
} | ||
} | ||
|
||
override suspend fun getRandomWallpaperUrl(): String { | ||
val country = getQuery("country") | ||
return api.getLatest(country = country, locale = "en-${country}").ad.portraitImage.asset | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.bnyro.wallpaper.api.sp | ||
|
||
import com.bnyro.wallpaper.api.sp.obj.SpotlightImage | ||
import com.bnyro.wallpaper.api.sp.obj.SpotlightImageItem | ||
import com.bnyro.wallpaper.api.sp.obj.SpotlightPage | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
private const val PLACEMENT_ID = "88000820" | ||
|
||
interface Spotlight { | ||
@GET("v4/api/selection") | ||
suspend fun getLatestPage( | ||
@Query("country") country: String = "US", | ||
@Query("locale") locale: String = "en-US", | ||
@Query("fmt") format: String = "json", | ||
@Query("placement") placement: String = PLACEMENT_ID, | ||
@Query("bcnt") limit: Int = 4 | ||
): SpotlightPage | ||
|
||
@GET("v4/api/selection") | ||
suspend fun getLatest( | ||
@Query("country") country: String = "US", | ||
@Query("locale") locale: String = "en-US", | ||
@Query("fmt") format: String = "json", | ||
@Query("placement") placement: String = PLACEMENT_ID | ||
): SpotlightImage | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/bnyro/wallpaper/api/sp/obj/SpotlightBatchrsp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.bnyro.wallpaper.api.sp.obj | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SpotlightBatchrsp( | ||
val items: List<SpotlightData>, | ||
val ver: String | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/bnyro/wallpaper/api/sp/obj/SpotlightData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.bnyro.wallpaper.api.sp.obj | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SpotlightData( | ||
val item: String | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/bnyro/wallpaper/api/sp/obj/SpotlightImage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.bnyro.wallpaper.api.sp.obj | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SpotlightImage( | ||
val ad: SpotlightInfo, | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/bnyro/wallpaper/api/sp/obj/SpotlightImageItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.bnyro.wallpaper.api.sp.obj | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SpotlightImageItem( | ||
val asset: String | ||
) |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/bnyro/wallpaper/api/sp/obj/SpotlightInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bnyro.wallpaper.api.sp.obj | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SpotlightInfo( | ||
val copyright: String, | ||
val ctaText: String, | ||
val ctaUri: String, | ||
val description: String, | ||
val dislikeGlyph: String, | ||
val entityId: String, | ||
val iconHoverText: String, | ||
val iconLabel: String, | ||
val landscapeImage: SpotlightImageItem, | ||
val likeGlyph: String, | ||
val portraitImage: SpotlightImageItem, | ||
val title: String | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/bnyro/wallpaper/api/sp/obj/SpotlightPage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.bnyro.wallpaper.api.sp.obj | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SpotlightPage( | ||
val batchrsp: SpotlightBatchrsp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters