refactor(MediaServiceRepository): use lists for SponsorBlock categories

According to the SponsorBlock API documentation categories and
actionTypes are string arrays.
This commit is contained in:
FineFindus 2025-03-13 15:53:14 +01:00
parent 4f4b090fc0
commit 2497fa8702
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
4 changed files with 13 additions and 8 deletions

View File

@ -17,8 +17,8 @@ interface MediaServiceRepository {
suspend fun getComments(videoId: String): CommentsPage
suspend fun getSegments(
videoId: String,
category: String,
actionType: String? = null
category: List<String>,
actionType: List<String>? = null
): SegmentData
suspend fun getDeArrowContent(videoIds: String): Map<String, DeArrowContent>

View File

@ -13,6 +13,7 @@ import com.github.libretube.api.obj.StreamItem
import com.github.libretube.api.obj.Streams
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.helpers.PreferenceHelper
import kotlinx.serialization.encodeToString
import retrofit2.HttpException
open class PipedMediaServiceRepository : MediaServiceRepository {
@ -36,9 +37,13 @@ open class PipedMediaServiceRepository : MediaServiceRepository {
override suspend fun getSegments(
videoId: String,
category: String,
actionType: String?
): SegmentData = api.getSegments(videoId, category, actionType)
category: List<String>,
actionType: List<String>?
): SegmentData = api.getSegments(
videoId,
JsonHelper.json.encodeToString(category),
JsonHelper.json.encodeToString(actionType)
)
override suspend fun getDeArrowContent(videoIds: String): Map<String, DeArrowContent> =
api.getDeArrowContent(videoIds)

View File

@ -209,8 +209,8 @@ open class OnlinePlayerService : AbstractPlayerService() {
if (sponsorBlockConfig.isEmpty()) return@runCatching
sponsorBlockSegments = MediaServiceRepository.instance.getSegments(
videoId,
JsonHelper.json.encodeToString(sponsorBlockConfig.keys),
"""["skip","mute","full","poi","chapter"]"""
sponsorBlockConfig.keys.toList(),
listOf("skip","mute","full","poi","chapter")
).segments
withContext(Dispatchers.Main) {

View File

@ -147,7 +147,7 @@ class SubmitSegmentDialog : DialogFragment() {
private suspend fun fetchSegments() {
val categories = resources.getStringArray(R.array.sponsorBlockSegments).toList()
segments = try {
MediaServiceRepository.instance.getSegments(videoId, JsonHelper.json.encodeToString(categories)).segments
MediaServiceRepository.instance.getSegments(videoId, categories).segments
} catch (e: Exception) {
Log.e(TAG(), e.toString())
return