Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(en/superstream): enable NSFW & (en/nollyverse): added missing refactor #3064

Merged
merged 8 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed src/en/nollyverse/res/web_hi_res_512.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.lang.Exception

class NollyVerse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

Expand Down Expand Up @@ -260,7 +259,7 @@ class NollyVerse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

private fun nextPageSelector(): String = "ul.pagination.pagination-md li:nth-last-child(2)"

override fun searchAnimeNextPageSelector(): String = throw Exception("Not used")
override fun searchAnimeNextPageSelector(): String = throw UnsupportedOperationException()

// =========================== Anime Details ============================

Expand Down Expand Up @@ -339,7 +338,7 @@ class NollyVerse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
}
}

override fun episodeListSelector() = throw Exception("not used")
override fun episodeListSelector() = throw UnsupportedOperationException()

// ============================ Video Links =============================

Expand Down Expand Up @@ -385,11 +384,11 @@ class NollyVerse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
return videoList.sort()
}

override fun videoListSelector() = throw Exception("not used")
override fun videoListSelector() = throw UnsupportedOperationException()

override fun videoFromElement(element: Element) = throw Exception("not used")
override fun videoFromElement(element: Element) = throw UnsupportedOperationException()

override fun videoUrlParse(document: Document) = throw Exception("not used")
override fun videoUrlParse(document: Document) = throw UnsupportedOperationException()

// ============================= Utilities ==============================

Expand Down
3 changes: 2 additions & 1 deletion src/en/superstream/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ext {
extName = 'SuperStream'
extClass = '.SuperStream'
extVersionCode = 10
extVersionCode = 11
isNsfw = true
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package eu.kanade.tachiyomi.animeextension.en.superstream

import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
Expand Down Expand Up @@ -31,13 +33,13 @@ class SuperStream : ConfigurableAnimeSource, AnimeHttpSource() {

private val json: Json by injectLazy()

private val superStreamAPI = SuperStreamAPI(json)
private val preferences: SharedPreferences = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)

override val baseUrl = superStreamAPI.apiUrl
private val hideNsfw = if (preferences.getBoolean(PREF_HIDE_NSFW_KEY, PREF_HIDE_NSFW_DEFAULT)) 1 else 0

private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
private val superStreamAPI = SuperStreamAPI(json, hideNsfw)

override val baseUrl = superStreamAPI.apiUrl

override suspend fun getPopularAnime(page: Int): AnimesPage {
val animes = superStreamAPI.getMainPage(page)
Expand Down Expand Up @@ -187,8 +189,10 @@ class SuperStream : ConfigurableAnimeSource, AnimeHttpSource() {
}
override fun animeDetailsParse(response: Response) = throw UnsupportedOperationException()

// ============================== Settings ==============================

override fun setupPreferenceScreen(screen: PreferenceScreen) {
val videoQualityPref = ListPreference(screen.context).apply {
ListPreference(screen.context).apply {
key = "preferred_quality"
title = "Preferred quality"
entries = arrayOf("4k", "1080p", "720p", "480p", "360p", "240p")
Expand All @@ -202,8 +206,20 @@ class SuperStream : ConfigurableAnimeSource, AnimeHttpSource() {
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
}
}
screen.addPreference(videoQualityPref)
}.also(screen::addPreference)

SwitchPreferenceCompat(screen.context).apply {
key = PREF_HIDE_NSFW_KEY
title = "Hide NSFW content"
setDefaultValue(PREF_HIDE_NSFW_DEFAULT)
summary = "requires restart"

setOnPreferenceChangeListener { _, newValue ->
val new = newValue as Boolean
Toast.makeText(screen.context, "Restart Aniyomi to apply new setting.", Toast.LENGTH_LONG).show()
preferences.edit().putBoolean(key, new).commit()
}
}.also(screen::addPreference)
}

private fun LinkData.toJson(): String {
Expand All @@ -218,3 +234,6 @@ class SuperStream : ConfigurableAnimeSource, AnimeHttpSource() {
}
}
}

private const val PREF_HIDE_NSFW_KEY = "pref_hide_nsfw"
private const val PREF_HIDE_NSFW_DEFAULT = true
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,10 @@ const val TYPE_SERIES = 2
const val TYPE_MOVIES = 1

// Ported from CS3
class SuperStreamAPI(val json: Json) {
class SuperStreamAPI(private val json: Json, private val hideNsfw: Int) {

private val client = configureToIgnoreCertificate()

// 0 to get nsfw
private val hideNsfw = 1

private val headers = Headers.headersOf(
"Platform",
"android",
Expand Down