diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f8e98aa2..866574f9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -230,7 +230,7 @@ dependencies { // Downloading & Networking implementation("androidx.work:work-runtime:2.9.0") implementation("androidx.work:work-runtime-ktx:2.9.0") - implementation("com.github.Blatzar:NiceHttp:0.4.5") // HTTP Lib + implementation("com.github.Blatzar:NiceHttp:0.4.11") // HTTP Lib } tasks.register("androidSourcesJar", Jar::class) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index a4edec33..7a25b738 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -1587,8 +1587,15 @@ data class AnimeLoadResponse( } override fun getTotalEpisodeIndex(episode: Int, season: Int): Int { + val displayMap = this.seasonNames?.associate { it.season to it.displaySeason } ?: emptyMap() + return this.episodes.maxOf { (_, episodes) -> - episodes.count { ((it.season ?: Int.MIN_VALUE) < season) && it.season != 0 } + episodes.count { episodeData -> + // Prioritize display season as actual season may be something random to fit multiple seasons into one. + val episodeSeason = displayMap[episodeData.season] ?: episodeData.season ?: Int.MIN_VALUE + // Count all episodes from season 1 to below the current season. + episodeSeason in 1.. + // Prioritize display season as actual season may be something random to fit multiple seasons into one. + val episodeSeason = displayMap[episodeData.season] ?: episodeData.season ?: Int.MIN_VALUE + // Count all episodes from season 1 to below the current season. + episodeSeason in 1.. + // This needs to be persistent because the application may exit without calling onDestroy. + get() = getKey>(FILE_DELETE_KEY) ?: setOf() + private set(value) = setKey(FILE_DELETE_KEY, value) + + /** + * Add file to delete on Exit. + */ + fun deleteFileOnExit(file: File) { + filesToDelete = filesToDelete + file.path + } + /** * Setting this will automatically enter the query in the search * next time the search fragment is opened. @@ -676,6 +695,15 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } override fun onDestroy() { + filesToDelete.forEach { path -> + val result = File(path).deleteRecursively() + if (result) { + Log.d(TAG, "Deleted temporary file: $path") + } else { + Log.d(TAG, "Failed to delete temporary file: $path") + } + } + filesToDelete = setOf() val broadcastIntent = Intent() broadcastIntent.action = "restart_service" broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java) @@ -1654,7 +1682,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { // this ensures that no unnecessary space is taken loadCache() File(filesDir, "exoplayer").deleteRecursively() // old cache - File(cacheDir, "exoplayer").deleteOnExit() // current cache + deleteFileOnExit(File(cacheDir, "exoplayer")) // current cache } catch (e: Exception) { logError(e) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/Acefile.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/Acefile.kt index c3af8bee..3f910cd4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/Acefile.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/Acefile.kt @@ -2,7 +2,6 @@ package com.lagradost.cloudstream3.extractors import com.lagradost.cloudstream3.SubtitleFile import com.lagradost.cloudstream3.app -import com.lagradost.cloudstream3.base64Decode import com.lagradost.cloudstream3.utils.* open class Acefile : ExtractorApi() { @@ -16,22 +15,19 @@ open class Acefile : ExtractorApi() { subtitleCallback: (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit ) { - val script = getAndUnpack(app.get(url).text) - val id = script.substringAfter("\"code\":\"").substringBefore("\",") - val doc = app.get("https://drive.google.com/uc?id=${base64Decode(id)}&export=download").document - val form = doc.select("form#download-form").attr("action") - val uc = doc.select("input#uc-download-link").attr("value") - val video = app.post( - form, data = mapOf( - "uc-download-link" to uc - ) - ).url + val id = "/(?:d|download|player|f|file)/(\\w+)".toRegex().find(url)?.groupValues?.get(1) + val script = getAndUnpack(app.get("$mainUrl/player/${id ?: return}").text) + val service = """service\s*=\s*['"]([^'"]+)""".toRegex().find(script)?.groupValues?.get(1) + val serverUrl = """['"](\S+check&id\S+?)['"]""".toRegex().find(script)?.groupValues?.get(1) + ?.replace("\"+service+\"", service ?: return) + + val video = app.get(serverUrl ?: return, referer = "$mainUrl/").parsedSafe()?.data callback.invoke( ExtractorLink( this.name, this.name, - video, + video ?: return, "", Qualities.Unknown.value, INFER_TYPE @@ -40,4 +36,8 @@ open class Acefile : ExtractorApi() { } + data class Source( + val data: String? = null, + ) + } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt index 68d543d3..f03a5525 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt @@ -49,8 +49,23 @@ open class Chillx : ExtractorApi() { val decrypt = cryptoAESHandler(master ?: return, getKey().toByteArray(), false)?.replace("\\", "") ?: throw ErrorLoadingException("failed to decrypt") val source = Regex(""""?file"?:\s*"([^"]+)""").find(decrypt)?.groupValues?.get(1) - val tracks = Regex("""tracks:\s*\[(.+)]""").find(decrypt)?.groupValues?.get(1) + val subtitles = Regex("""subtitle"?:\s*"([^"]+)""").find(decrypt)?.groupValues?.get(1) + val subtitlePattern = """\[(.*?)\](https?://[^\s,]+)""".toRegex() + val matches = subtitlePattern.findAll(subtitles ?: "") + val languageUrlPairs = matches.map { matchResult -> + val (language, url) = matchResult.destructured + decodeUnicodeEscape(language) to url + }.toList() + + languageUrlPairs.forEach{ (name, file) -> + subtitleCallback.invoke( + SubtitleFile( + name, + file + ) + ) + } // required val headers = mapOf( "Accept" to "*/*", @@ -67,18 +82,15 @@ open class Chillx : ExtractorApi() { "$mainUrl/", headers = headers ).forEach(callback) - - AppUtils.tryParseJson>("[$tracks]") - ?.filter { it.kind == "captions" }?.map { track -> - subtitleCallback.invoke( - SubtitleFile( - track.label ?: "", - track.file ?: return@map null - ) - ) - } } - + + private fun decodeUnicodeEscape(input: String): String { + val regex = Regex("u([0-9a-fA-F]{4})") + return regex.replace(input) { + it.groupValues[1].toInt(16).toChar().toString() + } + } + suspend fun getKey() = key ?: fetchKey().also { key = it } private suspend fun fetchKey(): String { diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/Gofile.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/Gofile.kt index eaf9c65f..8d78c1a4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/Gofile.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/Gofile.kt @@ -22,9 +22,9 @@ open class Gofile : ExtractorApi() { val id = Regex("/(?:\\?c=|d/)([\\da-zA-Z-]+)").find(url)?.groupValues?.get(1) val token = app.get("$mainApi/createAccount").parsedSafe()?.data?.get("token") val websiteToken = app.get("$mainUrl/dist/js/alljs.js").text.let { - Regex("websiteToken\\s*=\\s*\"([^\"]+)").find(it)?.groupValues?.get(1) + Regex("fetchData.wt\\s*=\\s*\"([^\"]+)").find(it)?.groupValues?.get(1) } - app.get("$mainApi/getContent?contentId=$id&token=$token&websiteToken=$websiteToken") + app.get("$mainApi/getContent?contentId=$id&token=$token&wt=$websiteToken") .parsedSafe()?.data?.contents?.forEach { callback.invoke( ExtractorLink( diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/HotlingerExtractor.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/HotlingerExtractor.kt index 7389db68..b557a53e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/HotlingerExtractor.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/HotlingerExtractor.kt @@ -10,4 +10,14 @@ class Hotlinger : ContentX() { class FourCX : ContentX() { override var name = "FourCX" override var mainUrl = "https://four.contentx.me" +} + +class PlayRu : ContentX() { + override var name = "PlayRu" + override var mainUrl = "https://playru.net" +} + +class FourPlayRu : ContentX() { + override var name = "FourPlayRu" + override var mainUrl = "https://four.playru.net" } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/Rabbitstream.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/Rabbitstream.kt index d5b52dd7..2df81bc6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/Rabbitstream.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/Rabbitstream.kt @@ -5,6 +5,7 @@ import com.lagradost.cloudstream3.ErrorLoadingException import com.lagradost.cloudstream3.SubtitleFile import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.base64DecodeArray +import com.lagradost.cloudstream3.base64Encode import com.lagradost.cloudstream3.utils.AppUtils import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.ExtractorApi @@ -16,13 +17,52 @@ import javax.crypto.Cipher import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec -// Code found in https://github.com/theonlymo/keys -// special credits to @theonlymo for providing key class Megacloud : Rabbitstream() { override val name = "Megacloud" override val mainUrl = "https://megacloud.tv" override val embed = "embed-2/ajax/e-1" - override val key = "https://raw.githubusercontent.com/theonlymo/keys/e1/key" + private val scriptUrl = "$mainUrl/js/player/a/prod/e1-player.min.js" + + override suspend fun extractRealKey(sources: String): Pair { + val rawKeys = getKeys() + val sourcesArray = sources.toCharArray() + + var extractedKey = "" + var currentIndex = 0 + for (index in rawKeys) { + val start = index[0] + currentIndex + val end = start + index[1] + for (i in start until end) { + extractedKey += sourcesArray[i].toString() + sourcesArray[i] = ' ' + } + currentIndex += index[1] + } + + return extractedKey to sourcesArray.joinToString("").replace(" ", "") + } + + private suspend fun getKeys(): List> { + val script = app.get(scriptUrl).text + fun matchingKey(value: String): String { + return Regex(",$value=((?:0x)?([0-9a-fA-F]+))").find(script)?.groupValues?.get(1) + ?.removePrefix("0x") ?: throw ErrorLoadingException("Failed to match the key") + } + + val regex = Regex("case\\s*0x[0-9a-f]+:(?![^;]*=partKey)\\s*\\w+\\s*=\\s*(\\w+)\\s*,\\s*\\w+\\s*=\\s*(\\w+);") + val indexPairs = regex.findAll(script).toList().map { match -> + val matchKey1 = matchingKey(match.groupValues[1]) + val matchKey2 = matchingKey(match.groupValues[2]) + try { + listOf(matchKey1.toInt(16), matchKey2.toInt(16)) + } catch (e: NumberFormatException) { + emptyList() + } + }.filter { it.isNotEmpty() } + + return indexPairs + } + } class Dokicloud : Rabbitstream() { @@ -30,12 +70,14 @@ class Dokicloud : Rabbitstream() { override val mainUrl = "https://dokicloud.one" } +// Code found in https://github.com/eatmynerds/key +// special credits to @eatmynerds for providing key open class Rabbitstream : ExtractorApi() { override val name = "Rabbitstream" override val mainUrl = "https://rabbitstream.net" override val requiresReferer = false open val embed = "ajax/embed-4" - open val key = "https://raw.githubusercontent.com/theonlymo/keys/e4/key" + open val key = "https://raw.githubusercontent.com/eatmynerds/key/e4/key.txt" override suspend fun getUrl( url: String, @@ -56,7 +98,7 @@ open class Rabbitstream : ExtractorApi() { val decryptedSources = if (sources == null || encryptedMap.encrypted == false) { response.parsedSafe() } else { - val (key, encData) = extractRealKey(sources, getRawKey()) + val (key, encData) = extractRealKey(sources) val decrypted = decryptMapped>(encData, key) SourcesResponses( sources = decrypted, @@ -75,8 +117,8 @@ open class Rabbitstream : ExtractorApi() { decryptedSources?.tracks?.map { track -> subtitleCallback.invoke( SubtitleFile( - track?.label ?: "", - track?.file ?: return@map + track?.label ?: return@map, + track.file ?: return@map ) ) } @@ -84,25 +126,10 @@ open class Rabbitstream : ExtractorApi() { } - private suspend fun getRawKey(): String = app.get(key).text - - private fun extractRealKey(sources: String, stops: String): Pair { - val decryptKey = parseJson>>(stops) - val sourcesArray = sources.toCharArray() - - var extractedKey = "" - var currentIndex = 0 - for (index in decryptKey) { - val start = index[0] + currentIndex - val end = start + index[1] - for (i in start until end) { - extractedKey += sourcesArray[i].toString() - sourcesArray[i] = ' ' - } - currentIndex += index[1] - } - - return extractedKey to sourcesArray.joinToString("") + open suspend fun extractRealKey(sources: String): Pair { + val rawKeys = parseJson>(app.get(key).text) + val extractedKey = base64Encode(rawKeys.map { it.toByte() }.toByteArray()) + return extractedKey to sources } private inline fun decryptMapped(input: String, key: String): T? { diff --git a/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt b/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt index 2c11bcdd..90872d94 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt @@ -31,6 +31,7 @@ import java.net.URI * @param useOkhttp will try to use the okhttp client as much as possible, but this might cause some requests to fail. Disable for cloudflare. * @param script pass custom js to execute * @param scriptCallback will be called with the result from custom js + * @param timeout close webview after timeout * */ class WebViewResolver( val interceptUrl: Regex, @@ -38,18 +39,29 @@ class WebViewResolver( val userAgent: String? = USER_AGENT, val useOkhttp: Boolean = true, val script: String? = null, - val scriptCallback: ((String) -> Unit)? = null + val scriptCallback: ((String) -> Unit)? = null, + val timeout: Long = DEFAULT_TIMEOUT ) : Interceptor { + constructor( + interceptUrl: Regex, + additionalUrls: List = emptyList(), + userAgent: String? = USER_AGENT, + useOkhttp: Boolean = true, + script: String? = null, + scriptCallback: ((String) -> Unit)? = null, + ) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, script, scriptCallback, DEFAULT_TIMEOUT) + constructor( interceptUrl: Regex, additionalUrls: List = emptyList(), userAgent: String? = USER_AGENT, useOkhttp: Boolean = true - ) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, null, null) + ) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, null, null, DEFAULT_TIMEOUT) companion object { + private const val DEFAULT_TIMEOUT = 60_000L var webViewUserAgent: String? = null @JvmName("getWebViewUserAgent1") @@ -262,7 +274,7 @@ class WebViewResolver( var loop = 0 // Timeouts after this amount, 60s - val totalTime = 60000L + val totalTime = timeout val delayTime = 100L diff --git a/app/src/main/java/com/lagradost/cloudstream3/subtitles/AbstractSubProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/subtitles/AbstractSubProvider.kt index 77a1b0b5..857fba11 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/subtitles/AbstractSubProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/subtitles/AbstractSubProvider.kt @@ -1,11 +1,23 @@ package com.lagradost.cloudstream3.subtitles import androidx.annotation.WorkerThread +import androidx.core.net.toUri +import com.lagradost.cloudstream3.MainActivity.Companion.deleteFileOnExit +import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities.SubtitleEntity import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities.SubtitleSearch import com.lagradost.cloudstream3.syncproviders.AuthAPI +import com.lagradost.cloudstream3.ui.player.SubtitleOrigin +import okio.BufferedSource +import okio.buffer +import okio.sink +import okio.source +import java.io.File +import java.util.zip.ZipInputStream interface AbstractSubProvider { + val idPrefix: String + @WorkerThread suspend fun search(query: SubtitleSearch): List? { throw NotImplementedError() @@ -15,6 +27,98 @@ interface AbstractSubProvider { suspend fun load(data: SubtitleEntity): String? { throw NotImplementedError() } + + @WorkerThread + suspend fun SubtitleResource.getResources(data: SubtitleEntity) { + this.addUrl(load(data)) + } + + @WorkerThread + suspend fun getResource(data: SubtitleEntity): SubtitleResource { + return SubtitleResource().apply { + this.getResources(data) + } + } +} + +/** + * A builder for subtitle files. + * @see addUrl + * @see addFile + */ +class SubtitleResource { + fun downloadFile(source: BufferedSource): File { + val file = File.createTempFile("temp-subtitle", ".tmp").apply { + deleteFileOnExit(this) + } + val sink = file.sink().buffer() + sink.writeAll(source) + sink.close() + source.close() + + return file + } + + fun unzip(file: File): List> { + val entries = mutableListOf>() + + ZipInputStream(file.inputStream()).use { zipInputStream -> + var zipEntry = zipInputStream.nextEntry + + while (zipEntry != null) { + val tempFile = File.createTempFile("unzipped-subtitle", ".tmp").apply { + deleteFileOnExit(this) + } + entries.add(zipEntry.name to tempFile) + + tempFile.sink().buffer().use { buffer -> + buffer.writeAll(zipInputStream.source()) + } + + zipEntry = zipInputStream.nextEntry + } + } + return entries + } + + data class SingleSubtitleResource( + val name: String?, + val url: String, + val origin: SubtitleOrigin + ) + + private var resources: MutableList = mutableListOf() + + fun getSubtitles(): List { + return resources.toList() + } + + fun addUrl(url: String?, name: String? = null) { + if (url == null) return + this.resources.add( + SingleSubtitleResource(name, url, SubtitleOrigin.URL) + ) + } + + fun addFile(file: File, name: String? = null) { + this.resources.add( + SingleSubtitleResource(name, file.toUri().toString(), SubtitleOrigin.DOWNLOADED_FILE) + ) + deleteFileOnExit(file) + } + + suspend fun addZipUrl( + url: String, + nameGenerator: (String, File) -> String? = { _, _ -> null } + ) { + val source = app.get(url).okhttpResponse.body.source() + val zip = downloadFile(source) + val realFiles = unzip(zip) + zip.deleteRecursively() + realFiles.forEach { (name, subtitleFile) -> + addFile(subtitleFile, nameGenerator(name, subtitleFile)) + } + } } interface AbstractSubApi : AbstractSubProvider, AuthAPI \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt index 8bf8dffa..bae8a5df 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt @@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.syncproviders import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys import com.lagradost.cloudstream3.AcraApplication.Companion.setKey +import com.lagradost.cloudstream3.syncproviders.providers.SubScene import com.lagradost.cloudstream3.syncproviders.providers.* import java.util.concurrent.TimeUnit @@ -14,6 +15,7 @@ abstract class AccountManager(private val defIndex: Int) : AuthAPI { val simklApi = SimklApi(0) val indexSubtitlesApi = IndexSubtitleApi() val addic7ed = Addic7ed() + val subScene = SubScene() val localListApi = LocalList() // used to login via app intent @@ -41,7 +43,8 @@ abstract class AccountManager(private val defIndex: Int) : AuthAPI { get() = listOf( openSubtitlesApi, indexSubtitlesApi, // they got anti scraping measures in place :( - addic7ed + addic7ed, + subScene ) const val appString = "cloudstreamapp" diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/IndexSubtitleApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/IndexSubtitleApi.kt index 668d10bd..1adecce9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/IndexSubtitleApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/IndexSubtitleApi.kt @@ -23,6 +23,47 @@ class IndexSubtitleApi : AbstractSubApi { companion object { const val host = "https://indexsubtitle.com" const val TAG = "INDEXSUBS" + + fun getOrdinal(num: Int?): String? { + return when (num) { + 1 -> "First" + 2 -> "Second" + 3 -> "Third" + 4 -> "Fourth" + 5 -> "Fifth" + 6 -> "Sixth" + 7 -> "Seventh" + 8 -> "Eighth" + 9 -> "Ninth" + 10 -> "Tenth" + 11 -> "Eleventh" + 12 -> "Twelfth" + 13 -> "Thirteenth" + 14 -> "Fourteenth" + 15 -> "Fifteenth" + 16 -> "Sixteenth" + 17 -> "Seventeenth" + 18 -> "Eighteenth" + 19 -> "Nineteenth" + 20 -> "Twentieth" + 21 -> "Twenty-First" + 22 -> "Twenty-Second" + 23 -> "Twenty-Third" + 24 -> "Twenty-Fourth" + 25 -> "Twenty-Fifth" + 26 -> "Twenty-Sixth" + 27 -> "Twenty-Seventh" + 28 -> "Twenty-Eighth" + 29 -> "Twenty-Ninth" + 30 -> "Thirtieth" + 31 -> "Thirty-First" + 32 -> "Thirty-Second" + 33 -> "Thirty-Third" + 34 -> "Thirty-Fourth" + 35 -> "Thirty-Fifth" + else -> null + } + } } private fun fixUrl(url: String): String { @@ -44,47 +85,6 @@ class IndexSubtitleApi : AbstractSubApi { } } - private fun getOrdinal(num: Int?): String? { - return when (num) { - 1 -> "First" - 2 -> "Second" - 3 -> "Third" - 4 -> "Fourth" - 5 -> "Fifth" - 6 -> "Sixth" - 7 -> "Seventh" - 8 -> "Eighth" - 9 -> "Ninth" - 10 -> "Tenth" - 11 -> "Eleventh" - 12 -> "Twelfth" - 13 -> "Thirteenth" - 14 -> "Fourteenth" - 15 -> "Fifteenth" - 16 -> "Sixteenth" - 17 -> "Seventeenth" - 18 -> "Eighteenth" - 19 -> "Nineteenth" - 20 -> "Twentieth" - 21 -> "Twenty-First" - 22 -> "Twenty-Second" - 23 -> "Twenty-Third" - 24 -> "Twenty-Fourth" - 25 -> "Twenty-Fifth" - 26 -> "Twenty-Sixth" - 27 -> "Twenty-Seventh" - 28 -> "Twenty-Eighth" - 29 -> "Twenty-Ninth" - 30 -> "Thirtieth" - 31 -> "Thirty-First" - 32 -> "Thirty-Second" - 33 -> "Thirty-Third" - 34 -> "Thirty-Fourth" - 35 -> "Thirty-Fifth" - else -> null - } - } - private fun isRightEps(text: String, seasonNum: Int?, epNum: Int?): Boolean { val FILTER_EPS_REGEX = Regex("(?i)((Chapter\\s?0?${epNum})|((Season)?\\s?0?${seasonNum}?\\s?(Episode)\\s?0?${epNum}[^0-9]))|(?i)((S?0?${seasonNum}?E0?${epNum}[^0-9])|(0?${seasonNum}[a-z]0?${epNum}[^0-9]))") diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/SubScene.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/SubScene.kt new file mode 100644 index 00000000..fbe05026 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/SubScene.kt @@ -0,0 +1,118 @@ +package com.lagradost.cloudstream3.syncproviders.providers + +import com.lagradost.cloudstream3.app +import com.lagradost.cloudstream3.mvvm.debugPrint +import com.lagradost.cloudstream3.subtitles.AbstractSubProvider +import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities +import com.lagradost.cloudstream3.subtitles.SubtitleResource +import com.lagradost.cloudstream3.syncproviders.providers.IndexSubtitleApi.Companion.getOrdinal +import com.lagradost.cloudstream3.utils.SubtitleHelper + +class SubScene : AbstractSubProvider { + val mainUrl = "https://subscene.com" + val name = "Subscene" + override val idPrefix = "subscene" + + override suspend fun search(query: AbstractSubtitleEntities.SubtitleSearch): List? { + val seasonName = + query.seasonNumber?.let { number -> + // Need to translate "7" to "Seventh Season" + getOrdinal(number)?.let { words -> " - $words Season" } + } ?: "" + + val fullQuery = query.query + seasonName + + val doc = app.post( + "$mainUrl/subtitles/searchbytitle", + data = mapOf("query" to fullQuery, "l" to "") + ).document + + return doc.select("div.title a").map { element -> + val href = "$mainUrl${element.attr("href")}" + val title = element.text() + + AbstractSubtitleEntities.SubtitleEntity( + idPrefix = idPrefix, + name = title, + source = name, + data = href, + lang = query.lang ?: "en", + epNumber = query.epNumber + ) + }.distinctBy { it.data } + } + + override suspend fun SubtitleResource.getResources(data: AbstractSubtitleEntities.SubtitleEntity) { + val resultDoc = app.get(data.data).document + val queryLanguage = SubtitleHelper.fromTwoLettersToLanguage(data.lang) ?: "English" + + val results = resultDoc.select("table tbody tr").mapNotNull { element -> + val anchor = element.select("a") + val href = anchor.attr("href") ?: return@mapNotNull null + val fixedHref = "$mainUrl${href}" + val spans = anchor.select("span") + val language = spans.firstOrNull()?.text() + val title = spans.getOrNull(1)?.text() + val isPositive = anchor.select("span.positive-icon").isNotEmpty() + + TableElement(title, language, fixedHref, isPositive) + }.sortedBy { + it.getScore(queryLanguage, data.epNumber) + } + + debugPrint { "$name found subtitles: ${results.takeLast(3)}" } + // Last = highest score + val selectedResult = results.lastOrNull() ?: return + + val subtitleDocument = app.get(selectedResult.href).document + val subtitleDownloadUrl = + "$mainUrl${subtitleDocument.select("div.download a").attr("href")}" + + this.addZipUrl(subtitleDownloadUrl) { name, _ -> + name + } + } + + /** + * Class to manage the various different subtitle results and rank them. + */ + data class TableElement( + val title: String?, + val language: String?, + val href: String, + val isPositive: Boolean + ) { + private fun matchesLanguage(other: String): Boolean { + return language != null && (language.contains(other, ignoreCase = true) || + other.contains(language, ignoreCase = true)) + } + + /** + * Scores in this order: + * Preferred Language > Episode number > Positive rating > English Language + */ + fun getScore(queryLanguage: String, episodeNum: Int?): Int { + var score = 0 + if (this.matchesLanguage(queryLanguage)) { + score += 8 + } + // Matches Episode 7 using "E07" with any number of leading zeroes + if (episodeNum != null && title != null && title.contains( + Regex( + """E0*${episodeNum}""", + RegexOption.IGNORE_CASE + ) + ) + ) { + score += 4 + } + if (isPositive) { + score += 2 + } + if (this.matchesLanguage("English")) { + score += 1 + } + return score + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt index b7f601ff..0e397f81 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt @@ -317,7 +317,7 @@ class HomeParentItemAdapterPreview( homePreviewText.text = item.name populateChips( homePreviewTags, - item.tags ?: emptyList(), + item.tags?.take(6) ?: emptyList(), R.style.ChipFilledSemiTransparent ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index 031f14fe..210bfdca 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -50,6 +50,7 @@ import androidx.preference.PreferenceManager import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey +import com.lagradost.cloudstream3.MainActivity.Companion.deleteFileOnExit import com.lagradost.cloudstream3.USER_AGENT import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.mvvm.debugAssert @@ -657,7 +658,7 @@ class CS3IPlayer : IPlayer { SimpleCache( File( context.cacheDir, "exoplayer" - ).also { it.deleteOnExit() }, // Ensures always fresh file + ).also { deleteFileOnExit(it) }, // Ensures always fresh file LeastRecentlyUsedCacheEvictor(cacheSize), databaseProvider ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index ceb4728d..01069f66 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -30,6 +30,7 @@ import com.lagradost.cloudstream3.databinding.FragmentPlayerBinding import com.lagradost.cloudstream3.databinding.PlayerSelectSourceAndSubsBinding import com.lagradost.cloudstream3.databinding.PlayerSelectTracksBinding import com.lagradost.cloudstream3.mvvm.* +import com.lagradost.cloudstream3.subtitles.AbstractSubApi import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.subtitleProviders import com.lagradost.cloudstream3.ui.player.CS3IPlayer.Companion.preferredAudioTrackLanguage @@ -69,7 +70,10 @@ class GeneratorPlayer : FullScreenPlayer() { } val subsProviders - get() = subtitleProviders.filter { !it.requiresLogin || it.loginInfo() != null } + get() = subtitleProviders.filter { provider -> + (provider as? AbstractSubApi)?.let { !it.requiresLogin || it.loginInfo() != null } + ?: true + } val subsProvidersIsActive get() = subsProviders.isNotEmpty() } @@ -147,7 +151,7 @@ class GeneratorPlayer : FullScreenPlayer() { } override fun playerStatusChanged() { - if(player.getIsPlaying()){ + if (player.getIsPlaying()) { viewModel.forceClearCache = false } } @@ -473,17 +477,21 @@ class GeneratorPlayer : FullScreenPlayer() { currentSubtitle?.let { currentSubtitle -> providers.firstOrNull { it.idPrefix == currentSubtitle.idPrefix }?.let { api -> ioSafe { - val url = api.load(currentSubtitle) ?: return@ioSafe - val subtitle = SubtitleData( - name = getName(currentSubtitle, true), - url = url, - origin = SubtitleOrigin.URL, - mimeType = url.toSubtitleMimeType(), - headers = currentSubtitle.headers, - currentSubtitle.lang - ) - runOnMainThread { - addAndSelectSubtitles(subtitle) + val subtitles = + api.getResource(currentSubtitle).getSubtitles().map { resource -> + SubtitleData( + name = resource.name ?: getName(currentSubtitle, true), + url = resource.url, + origin = resource.origin, + mimeType = resource.url.toSubtitleMimeType(), + headers = currentSubtitle.headers, + currentSubtitle.lang + ) + } + if (subtitles.isNotEmpty()) { + runOnMainThread { + addAndSelectSubtitles(*subtitles.toTypedArray()) + } } } } @@ -521,7 +529,11 @@ class GeneratorPlayer : FullScreenPlayer() { } } - private fun addAndSelectSubtitles(subtitleData: SubtitleData) { + private fun addAndSelectSubtitles( + vararg subtitleData: SubtitleData + ) { + if (subtitleData.isEmpty()) return + val selectedSubtitle = subtitleData.first() val ctx = context ?: return val subs = currentSubs + subtitleData @@ -533,13 +545,13 @@ class GeneratorPlayer : FullScreenPlayer() { player.saveData() player.reloadPlayer(ctx) - setSubtitles(subtitleData) - viewModel.addSubtitles(setOf(subtitleData)) + setSubtitles(selectedSubtitle) + viewModel.addSubtitles(subtitleData.toSet()) selectSourceDialog?.dismissSafe() showToast( - String.format(ctx.getString(R.string.player_loaded_subtitles), subtitleData.name), + String.format(ctx.getString(R.string.player_loaded_subtitles), selectedSubtitle.name), Toast.LENGTH_LONG ) } @@ -919,7 +931,7 @@ class GeneratorPlayer : FullScreenPlayer() { override fun playerError(exception: Throwable) { Log.i(TAG, "playerError = $currentSelectedLink") - if(!hasNextMirror()){ + if (!hasNextMirror()) { viewModel.forceClearCache = true } super.playerError(exception) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt index e7e50b9d..76066c2e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt @@ -681,6 +681,7 @@ open class ResultFragmentPhone : FullScreenPlayer() { resultMetaYear.setText(d.yearText) resultMetaDuration.setText(d.durationText) resultMetaRating.setText(d.ratingText) + resultMetaStatus.setText(d.onGoingText) resultMetaContentRating.setText(d.contentRatingText) resultCastText.setText(d.actorsText) resultNextAiring.setText(d.nextAiringEpisode) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt index 602b45e4..7ac7cbb2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt @@ -1,10 +1,17 @@ package com.lagradost.cloudstream3.ui.settings.extensions +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.os.Build import android.view.LayoutInflater import android.view.ViewGroup +import android.widget.Toast import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding +import com.lagradost.cloudstream3.CommonActivity.activity +import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.databinding.RepositoryItemBinding import com.lagradost.cloudstream3.databinding.RepositoryItemTvBinding @@ -112,6 +119,17 @@ class RepoAdapter( repositoryItemRoot.setOnClickListener { clickCallback(repositoryData) } + + repositoryItemRoot.setOnLongClickListener { + val clipboardManager = + activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager? + clipboardManager?.setPrimaryClip(ClipData.newPlainText("RepoUrl", repositoryData.url)) + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) { + showToast(R.string.copyRepoUrl, Toast.LENGTH_SHORT) + } + return@setOnLongClickListener true + } + mainText.text = repositoryData.name subText.text = repositoryData.url } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/testing/TestViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/testing/TestViewModel.kt index 4fd24afe..9e6f8a06 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/testing/TestViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/testing/TestViewModel.kt @@ -10,7 +10,6 @@ import com.lagradost.cloudstream3.utils.TestingUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.cancel -import okhttp3.internal.toImmutableList class TestViewModel : ViewModel() { data class TestProgress( diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt index 4f9c5e8c..637f65b9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt @@ -106,6 +106,8 @@ import com.lagradost.cloudstream3.extractors.ContentX import com.lagradost.cloudstream3.extractors.EmturbovidExtractor import com.lagradost.cloudstream3.extractors.Hotlinger import com.lagradost.cloudstream3.extractors.FourCX +import com.lagradost.cloudstream3.extractors.PlayRu +import com.lagradost.cloudstream3.extractors.FourPlayRu import com.lagradost.cloudstream3.extractors.HDMomPlayer import com.lagradost.cloudstream3.extractors.HDPlayerSystem import com.lagradost.cloudstream3.extractors.VideoSeyred @@ -704,6 +706,8 @@ val extractorApis: MutableList = arrayListOf( ContentX(), Hotlinger(), FourCX(), + PlayRu(), + FourPlayRu(), HDMomPlayer(), HDPlayerSystem(), VideoSeyred(), diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index 28c18fec..d9a31b4e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -23,6 +23,7 @@ import okio.buffer import okio.sink import java.io.File import android.text.TextUtils +import com.lagradost.cloudstream3.MainActivity.Companion.deleteFileOnExit import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import java.io.BufferedReader import java.io.IOException @@ -213,7 +214,7 @@ class InAppUpdater { this.cacheDir.listFiles()?.filter { it.name.startsWith(appUpdateName) && it.extension == appUpdateSuffix }?.forEach { - it.deleteOnExit() + deleteFileOnExit(it) } val downloadedFile = File.createTempFile(appUpdateName, ".$appUpdateSuffix") diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/PackageInstallerService.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/PackageInstallerService.kt index 7ff7b067..322547f4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/PackageInstallerService.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/PackageInstallerService.kt @@ -12,6 +12,7 @@ import android.os.IBinder import android.util.Log import androidx.core.app.NotificationCompat import com.lagradost.cloudstream3.MainActivity +import com.lagradost.cloudstream3.MainActivity.Companion.deleteFileOnExit import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.utils.AppUtils.createNotificationChannel @@ -75,7 +76,7 @@ class PackageInstallerService : Service() { this@PackageInstallerService.cacheDir.listFiles()?.filter { it.name.startsWith(appUpdateName) && it.extension == appUpdateSuffix }?.forEach { - it.deleteOnExit() + deleteFileOnExit(it) } } diff --git a/app/src/main/res/layout/fragment_home_head_tv.xml b/app/src/main/res/layout/fragment_home_head_tv.xml index 6db7536f..ccc3a8e1 100644 --- a/app/src/main/res/layout/fragment_home_head_tv.xml +++ b/app/src/main/res/layout/fragment_home_head_tv.xml @@ -137,7 +137,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="end" - android:maxLines="5" + android:maxLines="3" android:paddingBottom="5dp" android:textSize="15sp" tools:text="very nice tv series" /> diff --git a/app/src/main/res/layout/fragment_result_swipe.xml b/app/src/main/res/layout/fragment_result_swipe.xml index eb2653d0..bb8a5c10 100644 --- a/app/src/main/res/layout/fragment_result_swipe.xml +++ b/app/src/main/res/layout/fragment_result_swipe.xml @@ -83,7 +83,7 @@ android:layout_height="25dp" android:layout_margin="5dp" android:elevation="10dp" - + android:tooltipText="@string/subscribe_tooltip" android:background="?android:attr/selectableItemBackgroundBorderless" android:src="@drawable/baseline_notifications_none_24" android:layout_gravity="end|center_vertical" @@ -100,7 +100,7 @@ android:layout_height="25dp" android:layout_margin="5dp" android:elevation="10dp" - + android:tooltipText="@string/action_add_to_favorites" android:background="?android:attr/selectableItemBackgroundBorderless" android:src="@drawable/ic_baseline_favorite_border_24" android:layout_gravity="end|center_vertical" @@ -117,7 +117,7 @@ android:layout_height="25dp" android:layout_margin="5dp" android:elevation="10dp" - + android:tooltipText="@string/result_share" android:background="?android:attr/selectableItemBackgroundBorderless" android:src="@drawable/ic_outline_share_24" android:layout_gravity="end|center_vertical" @@ -135,7 +135,7 @@ android:layout_height="25dp" android:layout_margin="5dp" android:elevation="10dp" - + android:tooltipText="@string/result_open_in_browser" android:background="?android:attr/selectableItemBackgroundBorderless" android:src="@drawable/ic_baseline_public_24" android:layout_gravity="end|center_vertical" @@ -153,7 +153,7 @@ android:layout_height="30dp" android:layout_margin="5dp" android:elevation="10dp" - + android:tooltipText="@string/result_search_tooltip" android:background="?android:attr/selectableItemBackgroundBorderless" android:src="@drawable/search_icon" android:layout_gravity="end|center_vertical" @@ -171,7 +171,7 @@ android:layout_height="25dp" android:layout_margin="5dp" android:elevation="10dp" - + android:tooltipText="@string/recommendations_tooltip" android:background="?android:attr/selectableItemBackgroundBorderless" android:src="@drawable/baseline_list_alt_24" android:layout_gravity="end|center_vertical" diff --git a/app/src/main/res/layout/fragment_result_tv.xml b/app/src/main/res/layout/fragment_result_tv.xml index 7b5fc291..a7ba4334 100644 --- a/app/src/main/res/layout/fragment_result_tv.xml +++ b/app/src/main/res/layout/fragment_result_tv.xml @@ -387,6 +387,7 @@ https://developer.android.com/design/ui/tv/samples/jet-fit Download Done %s - %s Update Started - Stream + Network stream Error Loading Links Links Reloaded Internal Storage @@ -174,6 +174,10 @@ Clear Save Title copied! + Repo URL copied! + New episode notification + Search in other extensions + Show recommendations Player Speed Subtitle Settings Text Color @@ -213,8 +217,8 @@ Player subtitles settings Chromecast Subtitles Chromecast subtitles settings - Eigengravy Mode - Adds a speed option in the player + Playback speed + Adds a speed option in the player Swipe to seek Swipe from side to side to control your position in a video Swipe to change settings @@ -391,9 +395,9 @@ Causes problems if set too high on devices with low storage space, such as Android TV. DNS over HTTPS Useful for bypassing ISP blocks - raw.githubusercontent.com Proxy + GitHub Proxy Could not reach GitHub. Turning on jsDelivr proxy… - Bypasses blocking of GitHub using jsDelivr. May cause updates to be delayed by few days. + Bypass blocking of raw github URLs using jsDelivr. May cause updates to be delayed by few days. Clone site Remove site Add a clone of an existing site, with a different URL @@ -439,13 +443,15 @@ General Random Button Show random button on Homepage and Library - Provider languages + Extension languages App Layout Preferred media - Enable NSFW on supported providers + Enable NSFW on supported Extensions Subtitle encoding Providers Provider test + Test all Extensions + This Test is meant for developers only and does not verifies or denies working of any extension. Layout Auto TV layout @@ -462,11 +468,11 @@ opensubtitles_key nginx_key password123 - MyCoolUsername + Username hello@world.com 127.0.0.1 - MyCoolSite - example.com + NewSiteName + https://example.com Language code (en)