Skip to content

Commit

Permalink
Merge pull request #173 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Fix FetchOldEpisodeDescriptionJob.kt
  • Loading branch information
Ziedelth authored Feb 12, 2024
2 parents 4483ee0 + a47f8f8 commit 4368014
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ class FetchOldEpisodeDescriptionJob : AbstractJob() {
return null
}

val finalUrl = httpRequest.lastPageUrl!!
val split = finalUrl.split("/")
val id = split[split.size - 2]
val id = normalizeUrl(httpRequest.lastPageUrl!!)
CrunchyrollWrapper.getObject(episode.anime!!.countryCode!!.locale, accessToken, cms, id)[0]
}

Expand All @@ -95,6 +93,8 @@ class FetchOldEpisodeDescriptionJob : AbstractJob() {
}
}

fun normalizeUrl(url: String) ="/watch/([A-Z0-9]+)/".toRegex().find(url)!!.groupValues[1]

private fun normalizeDescription(episode: Episode, content: JsonObject): String? {
var description = when (episode.platform) {
Platform.CRUN -> content.getAsString("description")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.shikkanime.jobs

import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.*

class FetchOldEpisodeDescriptionJobTest {
private val fetchOldEpisodeDescriptionJob = FetchOldEpisodeDescriptionJob()

@Test
fun normalizeUrl() {
assertEquals("GMKUXPD53", fetchOldEpisodeDescriptionJob.normalizeUrl("https://www.crunchyroll.com/fr/watch/GMKUXPD53/"))
assertEquals("G14U415N4", fetchOldEpisodeDescriptionJob.normalizeUrl("https://www.crunchyroll.com/fr/watch/G14U415N4/the-panicked-foolish-angel-and-demon"))
assertEquals("G14U415D2", fetchOldEpisodeDescriptionJob.normalizeUrl("https://www.crunchyroll.com/fr/watch/G14U415D2/natsukawa-senpai-is-super-good-looking"))
assertEquals("G8WUN158J", fetchOldEpisodeDescriptionJob.normalizeUrl("https://www.crunchyroll.com/fr/watch/G8WUN158J/"))
assertEquals("GEVUZD021", fetchOldEpisodeDescriptionJob.normalizeUrl("https://www.crunchyroll.com/fr/watch/GEVUZD021/becoming-a-three-star-chef"))
assertEquals("GK9U3KWN4", fetchOldEpisodeDescriptionJob.normalizeUrl("https://www.crunchyroll.com/fr/watch/GK9U3KWN4/yukis-world"))
}
}

0 comments on commit 4368014

Please sign in to comment.