Skip to content

Commit

Permalink
fix(fr/animesama): Fix anime sama (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
hollowshiroyuki authored Oct 1, 2023
1 parent ed384f9 commit 8152bb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/fr/animesama/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ ext {
extName = 'Anime-Sama'
pkgNameSuffix = 'fr.animesama'
extClass = '.AnimeSama'
extVersionCode = 4
extVersionCode = 5
libVersion = 13
containsNsfw = false
}

dependencies {
implementation(project(':lib-mytv-extractor'))
implementation(project(':lib-sibnet-extractor'))
implementation(project(':lib-vk-extractor'))
implementation(project(':lib-sendvid-extractor'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
import eu.kanade.tachiyomi.lib.mytvextractor.MytvExtractor
import eu.kanade.tachiyomi.lib.sendvidextractor.SendvidExtractor
import eu.kanade.tachiyomi.lib.sibnetextractor.SibnetExtractor
import eu.kanade.tachiyomi.lib.vkextractor.VkExtractor
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import okhttp3.FormBody
Expand All @@ -34,7 +37,7 @@ class AnimeSama : ConfigurableAnimeSource, AnimeHttpSource() {

override val name = "Anime-Sama"

override val baseUrl = "https://www.anime-sama.fr"
override val baseUrl = "https://anime-sama.fr"

override val lang = "fr"

Expand Down Expand Up @@ -116,12 +119,12 @@ class AnimeSama : ConfigurableAnimeSource, AnimeHttpSource() {
val playerUrls = json.decodeFromString<List<List<String>>>(episode.url)
val videos = playerUrls.flatMapIndexed { i, it ->
val prefix = "(${VOICES_VALUES[i].uppercase()}) "
it.flatMap { playerUrl ->
it.parallelCatchingFlatMap { playerUrl ->
with(playerUrl) {
when {
contains("anime-sama.fr") -> listOf(Video(playerUrl, "${prefix}AS Player", playerUrl))
contains("sibnet.ru") -> SibnetExtractor(client).videosFromUrl(playerUrl, prefix)
contains("myvi.") -> MytvExtractor(client).videosFromUrl(playerUrl, prefix)
// contains("myvi.") -> MytvExtractor(client).videosFromUrl(playerUrl, prefix)
contains("vk.") -> VkExtractor(client, headers).videosFromUrl(playerUrl, prefix)
contains("sendvid.com") -> SendvidExtractor(client, headers).videosFromUrl(playerUrl, prefix)
else -> emptyList()
Expand All @@ -133,6 +136,11 @@ class AnimeSama : ConfigurableAnimeSource, AnimeHttpSource() {
}

// ============================ Utils =============================
inline fun <A, B> Iterable<A>.parallelCatchingFlatMap(crossinline f: suspend (A) -> Iterable<B>): List<B> =
runBlocking {
map { async(Dispatchers.Default) { runCatching { f(it) }.getOrElse { emptyList() } } }.awaitAll().flatten()
}

private fun removeDiacritics(string: String) = Normalizer.normalize(string, Normalizer.Form.NFD).replace(Regex("\\p{Mn}+"), "")
private fun sanitizeEpisodesJs(doc: String) = doc
.replace(Regex("[\"\t]"), "") // Fix trash format
Expand Down

0 comments on commit 8152bb6

Please sign in to comment.