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

View File

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

View File

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