Skip to content

Commit

Permalink
refactor: Minor refactoration
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky committed Oct 13, 2023
1 parent fe41c38 commit 49bf3de
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 109 deletions.
1 change: 1 addition & 0 deletions multisrc/overrides/animestream/animexin/additional.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ dependencies {
implementation(project(':lib-dailymotion-extractor'))
implementation(project(':lib-okru-extractor'))
implementation(project(':lib-gdriveplayer-extractor'))
implementation(project(':lib-dood-extractor'))
implementation "dev.datlag.jsunpacker:jsunpacker:1.0.1"
}
40 changes: 17 additions & 23 deletions multisrc/overrides/animestream/animexin/src/AnimeXin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package eu.kanade.tachiyomi.animeextension.all.animexin

import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.all.animexin.extractors.DoodExtractor
import eu.kanade.tachiyomi.animeextension.all.animexin.extractors.VidstreamingExtractor
import eu.kanade.tachiyomi.animeextension.all.animexin.extractors.YouTubeExtractor
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.dailymotionextractor.DailymotionExtractor
import eu.kanade.tachiyomi.lib.doodextractor.DoodExtractor
import eu.kanade.tachiyomi.lib.gdriveplayerextractor.GdrivePlayerExtractor
import eu.kanade.tachiyomi.lib.okruextractor.OkruExtractor
import eu.kanade.tachiyomi.multisrc.animestream.AnimeStream
Expand All @@ -19,41 +19,37 @@ class AnimeXin : AnimeStream(
override val id = 4620219025406449669

// ============================ Video Links =============================
private val dailymotionExtractor by lazy { DailymotionExtractor(client, headers) }
private val doodExtractor by lazy { DoodExtractor(client) }
private val gdrivePlayerExtractor by lazy { GdrivePlayerExtractor(client) }
private val okruExtractor by lazy { OkruExtractor(client) }
private val vidstreamingExtractor by lazy { VidstreamingExtractor(client) }
private val youTubeExtractor by lazy { YouTubeExtractor(client) }

override fun getVideoList(url: String, name: String): List<Video> {
val prefix = "$name - "
return when {
url.contains("ok.ru") -> {
OkruExtractor(client).videosFromUrl(url, prefix = prefix)
}

url.contains("dailymotion") -> {
DailymotionExtractor(client, headers).videosFromUrl(url, prefix)
}
url.contains("https://dood") -> {
DoodExtractor(client).videosFromUrl(url, quality = name)
}
url.contains("ok.ru") -> okruExtractor.videosFromUrl(url, prefix)
url.contains("dailymotion") -> dailymotionExtractor.videosFromUrl(url, prefix)
url.contains("https://dood") -> doodExtractor.videosFromUrl(url, name)
url.contains("gdriveplayer") -> {
val gdriveHeaders = headersBuilder()
.add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8")
.add("Host", "gdriveplayer.to")
.add("Referer", "$baseUrl/")
.build()
GdrivePlayerExtractor(client).videosFromUrl(url, name = name, headers = gdriveHeaders)
}
url.contains("youtube.com") -> {
YouTubeExtractor(client).videosFromUrl(url, prefix = prefix)
}
url.contains("vidstreaming") -> {
VidstreamingExtractor(client).videosFromUrl(url, prefix = prefix)
gdrivePlayerExtractor.videosFromUrl(url, name, gdriveHeaders)
}
url.contains("youtube.com") -> youTubeExtractor.videosFromUrl(url, prefix)
url.contains("vidstreaming") -> vidstreamingExtractor.videosFromUrl(url, prefix)
else -> emptyList()
}
}

// ============================== Settings ==============================
override fun setupPreferenceScreen(screen: PreferenceScreen) {
super.setupPreferenceScreen(screen) // Quality preferences
val videoLangPref = ListPreference(screen.context).apply {

ListPreference(screen.context).apply {
key = PREF_LANG_KEY
title = PREF_LANG_TITLE
entries = PREF_LANG_VALUES
Expand All @@ -67,9 +63,7 @@ class AnimeXin : AnimeStream(
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
}
}

screen.addPreference(videoLangPref)
}.also(screen::addPreference)
}

// ============================= Utilities ==============================
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class YouTubeExtractor(private val client: OkHttpClient) {

val ytcfg = document.selectFirst("script:containsData(window.ytcfg=window.ytcfg)")
?.data() ?: run {
Log.e("YouTubeExtractor", "Failed while trying to fetch the api key >:(")
return emptyList()
}
Log.e("YouTubeExtractor", "Failed while trying to fetch the api key >:(")
return emptyList()
}

val clientName = ytcfg.substringAfter("INNERTUBE_CONTEXT_CLIENT_NAME\":", "")
.substringBefore(",", "").ifEmpty { "5" }
Expand Down Expand Up @@ -74,9 +74,7 @@ class YouTubeExtractor(private val client: OkHttpClient) {

val headers = Headers.Builder().apply {
add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
add("Content-Type", "application/json")
add("Host", "www.youtube.com")
add("Origin", "https://www.youtube.com")
add("Origin", YOUTUBE_URL)
add("User-Agent", "com.google.ios.youtube/17.33.2 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)")
add("X-Youtube-Client-Name", clientName)
add("X-Youtube-Client-Version", "17.33.2")
Expand Down

0 comments on commit 49bf3de

Please sign in to comment.