Skip to content

Commit

Permalink
refactor: Fix some codefactor warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky committed Oct 24, 2023
1 parent d5f81d5 commit bbd08fe
Show file tree
Hide file tree
Showing 49 changed files with 92 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,6 @@ class AutoEmbedExtractor(private val client: OkHttpClient) {
videoUrl.contains("rabbitstream") -> {
RabbitStreamExtractor(client).videosFromUrl(videoUrl, headers = videoHeaders, prefix = prefix)
}
videoUrl.contains("mixdrop") -> {
MixDropExtractor(client).videoFromUrl(videoUrl, prefix = prefix)
}
videoUrl.contains("https://dood") -> {
DoodExtractor(client).videoFromUrl(videoUrl, server.name, false)
?.let(::listOf)
Expand Down Expand Up @@ -863,7 +860,7 @@ class AutoEmbedExtractor(private val client: OkHttpClient) {
private fun getCaptchaToken(url: String, key: String): String? {
return runCatching {
val httpUrl = url.toHttpUrl()
val pureDomain = (httpUrl.scheme + "://" + httpUrl.host + ":443")
val pureDomain = httpUrl.scheme + "://" + httpUrl.host + ":443"
val domain = Base64.encodeToString(pureDomain.encodeToByteArray(), Base64.DEFAULT)
.replace("\n", "")
.replace("=", ".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Akwam : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
episode.setUrlWithoutDomain(element.attr("href"))
episode.name = element.text()
episode.episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloat()
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}
return episode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Anime4Up : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
episode.setUrlWithoutDomain(element.select("div.episodes-card-container div.episodes-card div.ehover6 h3 a").attr("href"))
// episode.episode_number = element.select("span:nth-child(3)").text().replace(" - ", "").toFloat()
episode.episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloat()
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}
episode.name = element.select("div.episodes-card-container div.episodes-card div.ehover6 h3 a").text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class AnimeBlkom : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val eptitle = element.selectFirst("span:nth-child(3)")!!.text()
val epNum = eptitle.filter { it.isDigit() }
episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloatOrNull() ?: 1F
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}
name = eptitle + " :" + element.selectFirst("span:nth-child(1)")!!.text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AnimeLek : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
name = text
val epNum = text.filter { it.isDigit() }
episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloatOrNull() ?: 1F
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MyCima : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
episode.setUrlWithoutDomain(if (type == "mSeries") element.select("a").attr("href") else element.attr("abs:href"))
if (type == "series") {
episode.episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloat()
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Okanime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
}

override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList) =
("$baseUrl/search/?s=$query")
"$baseUrl/search/?s=$query"
.let { if (page > 1) "$it&page=$page" else it }
.let(::GET)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class XsAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
episode.setUrlWithoutDomain(element.attr("abs:href"))
episode.name = element.select("a > em").text()
episode.episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloat()
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JsUnpacker(packedJS: String?) {
*/
fun unpack(): String? {
val js = packedJS
try {
runCatching {
var p =
Pattern.compile("""\}\s*\('(.*)',\s*(.*?),\s*(\d+),\s*'(.*?)'\.split\('\|'\)""", Pattern.DOTALL)
var m = p.matcher(js)
Expand All @@ -35,16 +35,8 @@ class JsUnpacker(packedJS: String?) {
val radixStr = m.group(2)
val countStr = m.group(3)
val symtab = m.group(4).split("\\|".toRegex()).toTypedArray()
var radix = 36
var count = 0
try {
radix = radixStr.toInt()
} catch (e: Exception) {
}
try {
count = countStr.toInt()
} catch (e: Exception) {
}
val radix = radixStr.toIntOrNull() ?: 36
val count = countStr.toIntOrNull() ?: 0
if (symtab.size != count) {
throw Exception("Unknown p.a.c.k.e.r. encoding")
}
Expand All @@ -67,7 +59,6 @@ class JsUnpacker(packedJS: String?) {
}
return decoded.toString()
}
} catch (e: Exception) {
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JsUnpacker(packedJS: String?) {
*/
fun unpack(): String? {
val js = packedJS
try {
runCatching {
var p =
Pattern.compile("""\}\s*\('(.*)',\s*(.*?),\s*(\d+),\s*'(.*?)'\.split\('\|'\)""", Pattern.DOTALL)
var m = p.matcher(js)
Expand All @@ -35,16 +35,8 @@ class JsUnpacker(packedJS: String?) {
val radixStr = m.group(2)
val countStr = m.group(3)
val symtab = m.group(4).split("\\|".toRegex()).toTypedArray()
var radix = 36
var count = 0
try {
radix = radixStr.toInt()
} catch (e: Exception) {
}
try {
count = countStr.toInt()
} catch (e: Exception) {
}
val radix = radixStr.toIntOrNull() ?: 36
val count = countStr.toIntOrNull() ?: 0
if (symtab.size != count) {
throw Exception("Unknown p.a.c.k.e.r. encoding")
}
Expand All @@ -67,7 +59,6 @@ class JsUnpacker(packedJS: String?) {
}
return decoded.toString()
}
} catch (e: Exception) {
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class StreamCloud : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
when {
li.text().contains("streamtape.com") && hosterSelection?.contains("stape") == true -> {
val url = li.attr("data-link")
try {
runCatching {
with(
client.newCall(GET(url, headers = Headers.headersOf("Referer", baseUrl, "Cookie", "Fuck Streamtape because they add concatenation to fuck up scrapers")))
.execute().asJsoup(),
Expand All @@ -108,7 +108,6 @@ class StreamCloud : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
videoList.add(Video(videoUrl, quality, videoUrl))
}
}
} catch (e: Exception) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() {
.toByteArray().map {
(it.toInt() xor 56).toChar()
}.joinToString("")
} else this
} else {
this
}
}

private fun prioritySort(pList: List<Pair<Video, Float>>): List<Video> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class AllAnimeExtractor(private val client: OkHttpClient, private val headers: H
if (videos != null) {
videoList.addAll(videos)
}
} else {}
}
}

return videoList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Animension() : ConfigurableAnimeSource, AnimeHttpSource() {

// Episode
override fun episodeListRequest(anime: SAnime): Request {
return (GET("$apiUrl/episodes.php?id=${anime.url}", headers))
return GET("$apiUrl/episodes.php?id=${anime.url}", headers)
}

override fun episodeListParse(response: Response): List<SEpisode> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
val subPreference = preferences.getString(PREF_SUB_KEY, PREF_SUB_DEFAULT)!!
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!
val shouldBeAv1 = preferences.getBoolean(PREF_AV1_KEY, PREF_AV1_DEFAULT)
val shouldEndWithEng = (subPreference == "eng")
val shouldEndWithEng = subPreference == "eng"

return this.sortedWith(
compareBy(
{ it.quality.contains(quality) },
{ (Regex("""\beng\b""").find(it.quality.lowercase()) != null) == shouldEndWithEng },
{ Regex("""\beng\b""").containsMatchIn(it.quality.lowercase()) == shouldEndWithEng },
{ it.quality.lowercase().contains("av1") == shouldBeAv1 },
),
).reversed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class KwikExtractor(private val client: OkHttpClient) {
.header("location")!!.substringAfterLast("https://")
val fContent =
client.newCall(GET(kwikUrl, Headers.headersOf("referer", "https://kwik.cx/"))).execute()
cookies += (fContent.header("set-cookie")!!)
cookies += fContent.header("set-cookie")!!
val fContentString = fContent.body.string()

val (fullString, key, v1, v2) = kwikParamsRegex.find(fContentString)!!.destructured
Expand Down Expand Up @@ -138,12 +138,10 @@ class KwikExtractor(private val client: OkHttpClient) {
var acc: Long = 0

for ((n, i) in content.reversed().withIndex()) {
acc += (
when (isNumber("$i")) {
true -> "$i".toLong()
false -> "0".toLong()
}
) * s1.toDouble().pow(n.toDouble()).toInt()
acc += when (isNumber("$i")) {
true -> "$i".toLong()
false -> 0L
} * s1.toDouble().pow(n.toDouble()).toInt()
}

var k = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class AsianLoad : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val epNum = element.selectFirst("div.name")!!.text().substringAfter("Episode ")
name = element.selectFirst("div.type span")!!.text() + " Episode: $epNum"
episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloatOrNull() ?: 1F
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}
date_upload = element.selectFirst("span.date")?.text()?.toDate() ?: 0L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DramaCool : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
setUrlWithoutDomain(element.attr("abs:href"))
name = element.select("span.type").text() + ": Episode " + element.select("h3").text().substringAfter("Episode ")
episode_number = when {
(epNum.isNotEmpty()) -> epNum.toFloat()
epNum.isNotEmpty() -> epNum.toFloatOrNull() ?: 1F
else -> 1F
}
date_upload = parseDate(element.select("span.time").text())
Expand Down Expand Up @@ -171,13 +171,6 @@ class DramaCool : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
videoList.add(video)
}
}

url.contains("streamtape") -> {
val video = StreamTapeExtractor(client).videoFromUrl(url)
if (video != null) {
videoList.add(video)
}
}
}
}
return videoList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class HentaiMama : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
.add("action", "get_player_contents")
.add(
"a",
(document.select("#post_report input:nth-child(5)").attr("value")).toString(),
document.selectFirst("#post_report input:nth-child(5)")?.attr("value").toString(),
)
.build()

Expand Down Expand Up @@ -196,7 +196,7 @@ class HentaiMama : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val parameters = getSearchParameters(filters)
return if (query.isNotEmpty()) {
filterSearch = false
GET("$baseUrl/page/$page/?s=${query.replace(("[\\W]").toRegex(), " ")}") // regular search
GET("$baseUrl/page/$page/?s=${query.replace(Regex("[\\W]"), " ")}") // regular search
} else {
filterSearch = true
GET("$baseUrl/advance-search/page/$page/?$parameters") // filter search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class KickAssAnimeExtractor(
fun videosFromUrl(url: String, name: String): List<Video> {
val host = url.toHttpUrl().host
val mid = if (name == "DuckStream") "mid" else "id"
val isBird = (name == "BirdStream")
val isBird = name == "BirdStream"

val query = url.toHttpUrl().queryParameter(mid)!!

Expand Down Expand Up @@ -134,7 +134,7 @@ class KickAssAnimeExtractor(
}

val cid = String(html.substringAfter("cid: '").substringBefore("'").decodeHex()).split("|")
val timeStamp = ((System.currentTimeMillis() / 1000) + 60).toString()
val timeStamp = (System.currentTimeMillis() / 1000 + 60).toString()
val route = cid[1].replace("player.php", "source.php")

val signature = buildString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class YouTubeExtractor(private val client: OkHttpClient) {

fun videosFromUrl(url: String, prefix: String): List<Video> {
// Ported from https://github.com/dermasmid/scrapetube/blob/master/scrapetube/scrapetube.py
// TODO: Make code prettier
// GET KEY
var ytcfgString = ""
val videoId = url.substringAfter("/embed/").substringBefore("?")
Expand Down Expand Up @@ -97,15 +96,15 @@ class YouTubeExtractor(private val client: OkHttpClient) {
// Get Audio
for (format in formats) {
if (format.jsonObject["mimeType"]!!.jsonPrimitive.content.startsWith("audio/webm")) {
try {
runCatching {
audioTracks.add(
Track(
format.jsonObject["url"]!!.jsonPrimitive.content,
format.jsonObject["audioQuality"]!!.jsonPrimitive.content +
" (${formatBits(format.jsonObject["averageBitrate"]!!.jsonPrimitive.long)}ps)",
),
)
} catch (a: Exception) { }
}
}
}

Expand All @@ -118,15 +117,14 @@ class YouTubeExtractor(private val client: OkHttpClient) {

for (caption in captionTracks) {
val captionJson = caption.jsonObject
try {
runCatching {
subtitleTracks.add(
Track(
// TODO: Would replacing srv3 with vtt work for every video?
captionJson["baseUrl"]!!.jsonPrimitive.content.replace("srv3", "vtt"),
captionJson["name"]!!.jsonObject["runs"]!!.jsonArray[0].jsonObject["text"]!!.jsonPrimitive.content,
),
)
} catch (a: Exception) { }
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MyRunningMan : ParsedAnimeHttpSource() {
title = it.label
thumbnail_url = buildString {
append("$baseUrl/assets/epimg/${it.value.padStart(3, '0')}")
if ((it.value.toIntOrNull() ?: 1) > 396) append("_temp")
if (it.value.toIntOrNull() ?: 1 > 396) append("_temp")
append(".jpg")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ public static String unescape(String input) {

int i = 0;
while (i < input.length()) {
char delimiter = input.charAt(i); i++; // consume letter or backslash
// consume letter or backslash
char delimiter = input.charAt(i);
i++;

if(delimiter == '\\' && i < input.length()) {

// consume first after backslash
char ch = input.charAt(i); i++;
char ch = input.charAt(i);
i++;

if(ch == '\\' || ch == '/' || ch == '"' || ch == '\'') {
builder.append(ch);
Expand Down
Loading

0 comments on commit bbd08fe

Please sign in to comment.