Skip to content

Commit

Permalink
Merge branch 'feature/112-implement-subtitles-for-sorastream'
Browse files Browse the repository at this point in the history
Close #112
  • Loading branch information
stantanasi committed Apr 18, 2024
2 parents 94f8c94 + e7d1706 commit dd845ce
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tanasi.streamflix.extractors
import android.util.Base64
import com.tanasi.retrofit_jsoup.converter.JsoupConverterFactory
import com.tanasi.streamflix.models.Video
import com.tanasi.streamflix.utils.OpenSubtitles
import org.jsoup.nodes.Document
import retrofit2.Retrofit
import retrofit2.http.GET
Expand All @@ -27,6 +28,7 @@ object SoraExtractor {

val doc = service.get(iframedoc, referer = url)

val imdbId = doc.select("body").attr("data-i").toIntOrNull()
val srcrcp = Regex("src: '(//vidsrc\\.net/srcrcp/.*?)'")
.find(doc.toString())?.groupValues?.get(1)
?: throw Exception("Can't retrieve source")
Expand All @@ -47,7 +49,18 @@ object SoraExtractor {
).apply {
video = Video(
source = source,
subtitles = emptyList(),
subtitles = if (imdbId != null) {
listOf(
OpenSubtitles.search(imdbId, "eng").sortedBy { it.subDownloadsCnt },
OpenSubtitles.search(imdbId, "fre").sortedBy { it.subDownloadsCnt },
OpenSubtitles.search(imdbId, "ger").sortedBy { it.subDownloadsCnt },
).flatten().map {
Video.Subtitle(
label = it.languageName ?: it.subFileName ?: "",
file = "https://vidsrc.stream/sub/ops-${it.idSubtitleFile}.vtt",
)
}
} else emptyList(),
referer = iframedoc,
)
}
Expand Down
107 changes: 107 additions & 0 deletions app/src/main/java/com/tanasi/streamflix/utils/OpenSubtitles.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.tanasi.streamflix.utils

import com.google.gson.annotations.SerializedName
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path

object OpenSubtitles {

private const val URL = "https://rest.opensubtitles.org/"

private val service = Service.build()

suspend fun search(
imdbId: Int,
languageId: String,
): List<Subtitle> {
return try {
service.search(imdbId, languageId)
} catch (_: Exception) {
emptyList()
}
}


private interface Service {

companion object {
fun build(): Service {
val retrofit = Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build()

return retrofit.create(Service::class.java)
}
}


@GET("search/imdbid-{imdbId}/sublanguageid-{languageId}")
suspend fun search(
@Path("imdbId") imdbId: Int,
@Path("languageId") languageId: String,
): List<Subtitle>
}

data class Subtitle(
@SerializedName("MatchedBy") val matchedBy: String? = null,
@SerializedName("IDSubMovieFile") val idSubMovieFile: String? = null,
@SerializedName("MovieHash") val movieHash: String? = null,
@SerializedName("MovieByteSize") val movieByteSize: String? = null,
@SerializedName("MovieTimeMS") val movieTimeMS: String? = null,
@SerializedName("IDSubtitleFile") val idSubtitleFile: String? = null,
@SerializedName("SubFileName") val subFileName: String? = null,
@SerializedName("SubActualCD") val subActualCD: String? = null,
@SerializedName("SubSize") val subSize: String? = null,
@SerializedName("SubHash") val subHash: String? = null,
@SerializedName("SubLastTS") val subLastTS: String? = null,
@SerializedName("SubTSGroup") val subTSGroup: String? = null,
@SerializedName("InfoReleaseGroup") val infoReleaseGroup: String? = null,
@SerializedName("InfoFormat") val infoFormat: String? = null,
@SerializedName("InfoOther") val infoOther: String? = null,
@SerializedName("IDSubtitle") val idSubtitle: String? = null,
@SerializedName("UserID") val userID: String? = null,
@SerializedName("SubLanguageID") val subLanguageID: String? = null,
@SerializedName("SubFormat") val subFormat: String? = null,
@SerializedName("SubSumCD") val subSumCD: String? = null,
@SerializedName("SubAuthorComment") val subAuthorComment: String? = null,
@SerializedName("SubAddDate") val subAddDate: String? = null,
@SerializedName("SubBad") val subBad: String? = null,
@SerializedName("SubRating") val subRating: String? = null,
@SerializedName("SubSumVotes") val subSumVotes: String? = null,
@SerializedName("SubDownloadsCnt") val subDownloadsCnt: String? = null,
@SerializedName("MovieReleaseName") val movieReleaseName: String? = null,
@SerializedName("MovieFPS") val movieFPS: String? = null,
@SerializedName("IDMovie") val idMovie: String? = null,
@SerializedName("IDMovieImdb") val idMovieImdb: String? = null,
@SerializedName("MovieName") val movieName: String? = null,
@SerializedName("MovieNameEng") val movieNameEng: String? = null,
@SerializedName("MovieYear") val movieYear: String? = null,
@SerializedName("MovieImdbRating") val movieImdbRating: String? = null,
@SerializedName("SubFeatured") val subFeatured: String? = null,
@SerializedName("UserNickName") val userNickName: String? = null,
@SerializedName("SubTranslator") val subTranslator: String? = null,
@SerializedName("ISO639") val iso639: String? = null,
@SerializedName("LanguageName") val languageName: String? = null,
@SerializedName("SubComments") val subComments: String? = null,
@SerializedName("SubHearingImpaired") val subHearingImpaired: String? = null,
@SerializedName("UserRank") val userRank: String? = null,
@SerializedName("SeriesSeason") val seriesSeason: String? = null,
@SerializedName("SeriesEpisode") val seriesEpisode: String? = null,
@SerializedName("MovieKind") val movieKind: String? = null,
@SerializedName("SubHD") val subHD: String? = null,
@SerializedName("SeriesIMDBParent") val seriesIMDBParent: String? = null,
@SerializedName("SubEncoding") val subEncoding: String? = null,
@SerializedName("SubAutoTranslation") val subAutoTranslation: String? = null,
@SerializedName("SubForeignPartsOnly") val subForeignPartsOnly: String? = null,
@SerializedName("SubFromTrusted") val subFromTrusted: String? = null,
@SerializedName("QueryCached") val queryCached: Int? = null,
@SerializedName("SubDownloadLink") val subDownloadLink: String? = null,
@SerializedName("ZipDownloadLink") val zipDownloadLink: String? = null,
@SerializedName("SubtitlesLink") val subtitlesLink: String? = null,
@SerializedName("QueryNumber") val queryNumber: String? = null,
@SerializedName("Score") val score: Double? = null
)
}

0 comments on commit dd845ce

Please sign in to comment.