From dad0c702119cc681910287d6ac304f3e8615b458 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Fri, 5 Jun 2026 16:15:25 -0600 Subject: [PATCH 1/2] OpenSubtitlesApi: migrate to kotlinx serialization --- .../providers/OpenSubtitlesApi.kt | 89 ++++++++++--------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt index 4b17fdb2920..34afba92256 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt @@ -1,7 +1,6 @@ package com.lagradost.cloudstream3.syncproviders.providers import android.util.Log -import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.ErrorLoadingException import com.lagradost.cloudstream3.R @@ -18,6 +17,8 @@ import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.SubtitleHelper.fromCodeToLangTagIETF import com.lagradost.cloudstream3.utils.SubtitleHelper.fromCodeToOpenSubtitlesTag +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable class OpenSubtitlesApi : SubtitleAPI() { override val name = "OpenSubtitles" @@ -97,7 +98,7 @@ class OpenSubtitlesApi : SubtitleAPI() { /** * Fetch subtitles using token authenticated on previous method (see authorize). * Returns list of Subtitles which user can select to download (see load). - * */ + */ override suspend fun search( auth : AuthData?, query: AbstractSubtitleEntities.SubtitleSearch @@ -177,16 +178,15 @@ class OpenSubtitlesApi : SubtitleAPI() { return results } - /* - Process data returned from search. - Returns string url for the subtitle file. - */ - + /** + * Process data returned from search. + * Returns string url for the subtitle file. + */ override suspend fun load( auth : AuthData?, subtitle: AbstractSubtitleEntities.SubtitleEntity ): String? { - if(auth == null) return null + if (auth == null) return null throwIfCantDoRequest() val req = app.post( @@ -218,57 +218,64 @@ class OpenSubtitlesApi : SubtitleAPI() { return null } + @Serializable data class OAuthToken( - @JsonProperty("token") var token: String? = null, - @JsonProperty("status") var status: Int? = null + @SerialName("token") var token: String? = null, + @SerialName("status") var status: Int? = null, ) + @Serializable data class Results( - @JsonProperty("data") var data: List? = listOf() + @SerialName("data") var data: List? = listOf(), ) + @Serializable data class ResultData( - @JsonProperty("id") var id: String? = null, - @JsonProperty("type") var type: String? = null, - @JsonProperty("attributes") var attributes: ResultAttributes? = ResultAttributes() + @SerialName("id") var id: String? = null, + @SerialName("type") var type: String? = null, + @SerialName("attributes") var attributes: ResultAttributes? = ResultAttributes(), ) + @Serializable data class ResultAttributes( - @JsonProperty("subtitle_id") var subtitleId: String? = null, - @JsonProperty("language") var language: String? = null, - @JsonProperty("release") var release: String? = null, - @JsonProperty("url") var url: String? = null, - @JsonProperty("files") var files: List? = listOf(), - @JsonProperty("feature_details") var featDetails: ResultFeatureDetails? = ResultFeatureDetails(), - @JsonProperty("hearing_impaired") var hearingImpaired: Boolean? = null, + @SerialName("subtitle_id") var subtitleId: String? = null, + @SerialName("language") var language: String? = null, + @SerialName("release") var release: String? = null, + @SerialName("url") var url: String? = null, + @SerialName("files") var files: List? = listOf(), + @SerialName("feature_details") var featDetails: ResultFeatureDetails? = ResultFeatureDetails(), + @SerialName("hearing_impaired") var hearingImpaired: Boolean? = null, ) + @Serializable data class ResultFiles( - @JsonProperty("file_id") var fileId: Int? = null, - @JsonProperty("file_name") var fileName: String? = null + @SerialName("file_id") var fileId: Int? = null, + @SerialName("file_name") var fileName: String? = null, ) + @Serializable data class ResultDownloadLink( - @JsonProperty("link") var link: String? = null, - @JsonProperty("file_name") var fileName: String? = null, - @JsonProperty("requests") var requests: Int? = null, - @JsonProperty("remaining") var remaining: Int? = null, - @JsonProperty("message") var message: String? = null, - @JsonProperty("reset_time") var resetTime: String? = null, - @JsonProperty("reset_time_utc") var resetTimeUtc: String? = null + @SerialName("link") var link: String? = null, + @SerialName("file_name") var fileName: String? = null, + @SerialName("requests") var requests: Int? = null, + @SerialName("remaining") var remaining: Int? = null, + @SerialName("message") var message: String? = null, + @SerialName("reset_time") var resetTime: String? = null, + @SerialName("reset_time_utc") var resetTimeUtc: String? = null, ) + @Serializable data class ResultFeatureDetails( - @JsonProperty("year") var year: Int? = null, - @JsonProperty("title") var title: String? = null, - @JsonProperty("movie_name") var movieName: String? = null, - @JsonProperty("imdb_id") var imdbId: Int? = null, - @JsonProperty("tmdb_id") var tmdbId: Int? = null, - @JsonProperty("season_number") var seasonNumber: Int? = null, - @JsonProperty("episode_number") var episodeNumber: Int? = null, - @JsonProperty("parent_imdb_id") var parentImdbId: Int? = null, - @JsonProperty("parent_title") var parentTitle: String? = null, - @JsonProperty("parent_tmdb_id") var parentTmdbId: Int? = null, - @JsonProperty("parent_feature_id") var parentFeatureId: Int? = null + @SerialName("year") var year: Int? = null, + @SerialName("title") var title: String? = null, + @SerialName("movie_name") var movieName: String? = null, + @SerialName("imdb_id") var imdbId: Int? = null, + @SerialName("tmdb_id") var tmdbId: Int? = null, + @SerialName("season_number") var seasonNumber: Int? = null, + @SerialName("episode_number") var episodeNumber: Int? = null, + @SerialName("parent_imdb_id") var parentImdbId: Int? = null, + @SerialName("parent_title") var parentTitle: String? = null, + @SerialName("parent_tmdb_id") var parentTmdbId: Int? = null, + @SerialName("parent_feature_id") var parentFeatureId: Int? = null, ) } From c20d849ff834eaa765cd0a481be5bafa08e23f70 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Tue, 9 Jun 2026 10:47:12 -0600 Subject: [PATCH 2/2] Keep JsonProperty where different than variable name --- .../providers/OpenSubtitlesApi.kt | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt index 34afba92256..13f43c93c1a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt @@ -1,6 +1,7 @@ package com.lagradost.cloudstream3.syncproviders.providers import android.util.Log +import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.ErrorLoadingException import com.lagradost.cloudstream3.R @@ -238,44 +239,44 @@ class OpenSubtitlesApi : SubtitleAPI() { @Serializable data class ResultAttributes( - @SerialName("subtitle_id") var subtitleId: String? = null, + @JsonProperty("subtitle_id") @SerialName("subtitle_id") var subtitleId: String? = null, @SerialName("language") var language: String? = null, @SerialName("release") var release: String? = null, @SerialName("url") var url: String? = null, @SerialName("files") var files: List? = listOf(), - @SerialName("feature_details") var featDetails: ResultFeatureDetails? = ResultFeatureDetails(), - @SerialName("hearing_impaired") var hearingImpaired: Boolean? = null, + @JsonProperty("feature_details") @SerialName("feature_details") var featDetails: ResultFeatureDetails? = ResultFeatureDetails(), + @JsonProperty("hearing_impaired") @SerialName("hearing_impaired") var hearingImpaired: Boolean? = null, ) @Serializable data class ResultFiles( - @SerialName("file_id") var fileId: Int? = null, - @SerialName("file_name") var fileName: String? = null, + @JsonProperty("file_id") @SerialName("file_id") var fileId: Int? = null, + @JsonProperty("file_name") @SerialName("file_name") var fileName: String? = null, ) @Serializable data class ResultDownloadLink( @SerialName("link") var link: String? = null, - @SerialName("file_name") var fileName: String? = null, + @JsonProperty("file_name") @SerialName("file_name") var fileName: String? = null, @SerialName("requests") var requests: Int? = null, @SerialName("remaining") var remaining: Int? = null, @SerialName("message") var message: String? = null, - @SerialName("reset_time") var resetTime: String? = null, - @SerialName("reset_time_utc") var resetTimeUtc: String? = null, + @JsonProperty("reset_time") @SerialName("reset_time") var resetTime: String? = null, + @JsonProperty("reset_time_utc") @SerialName("reset_time_utc") var resetTimeUtc: String? = null, ) @Serializable data class ResultFeatureDetails( @SerialName("year") var year: Int? = null, @SerialName("title") var title: String? = null, - @SerialName("movie_name") var movieName: String? = null, - @SerialName("imdb_id") var imdbId: Int? = null, - @SerialName("tmdb_id") var tmdbId: Int? = null, - @SerialName("season_number") var seasonNumber: Int? = null, - @SerialName("episode_number") var episodeNumber: Int? = null, - @SerialName("parent_imdb_id") var parentImdbId: Int? = null, - @SerialName("parent_title") var parentTitle: String? = null, - @SerialName("parent_tmdb_id") var parentTmdbId: Int? = null, - @SerialName("parent_feature_id") var parentFeatureId: Int? = null, + @JsonProperty("movie_name") @SerialName("movie_name") var movieName: String? = null, + @JsonProperty("imdb_id") @SerialName("imdb_id") var imdbId: Int? = null, + @JsonProperty("tmdb_id") @SerialName("tmdb_id") var tmdbId: Int? = null, + @JsonProperty("season_number") @SerialName("season_number") var seasonNumber: Int? = null, + @JsonProperty("episode_number") @SerialName("episode_number") var episodeNumber: Int? = null, + @JsonProperty("parent_imdb_id") @SerialName("parent_imdb_id") var parentImdbId: Int? = null, + @JsonProperty("parent_title") @SerialName("parent_title") var parentTitle: String? = null, + @JsonProperty("parent_tmdb_id") @SerialName("parent_tmdb_id") var parentTmdbId: Int? = null, + @JsonProperty("parent_feature_id") @SerialName("parent_feature_id") var parentFeatureId: Int? = null, ) }