add Episode watched callback
This commit is contained in:
parent
cbfd186686
commit
03cd42773d
|
@ -12,6 +12,9 @@ import org.mosad.teapod.util.Media
|
|||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* maybe AoDParser as object would be useful
|
||||
*/
|
||||
class AoDParser {
|
||||
|
||||
private val baseUrl = "https://www.anime-on-demand.de"
|
||||
|
@ -19,6 +22,7 @@ class AoDParser {
|
|||
private val libraryPath = "/animes"
|
||||
|
||||
companion object {
|
||||
private var csrfToken: String = ""
|
||||
private var sessionCookies = mutableMapOf<String, String>()
|
||||
private var loginSuccess = false
|
||||
|
||||
|
@ -132,25 +136,31 @@ class AoDParser {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO tv show specific for each episode (div.episodebox)
|
||||
* * watchedCallback
|
||||
*/
|
||||
// parse additional information for tv shows
|
||||
val episodes = if (media.type == MediaType.TVSHOW) {
|
||||
res.select("div.three-box-container > div.episodebox").map { episodebox ->
|
||||
val episodeId = episodebox.select("div.flip-front").attr("id").substringAfter("-").toInt()
|
||||
val episodeWatched = episodebox.select("div.episodebox-icons > div").hasClass("status-icon-orange")
|
||||
val episodeShortDesc = episodebox.select("p.episodebox-shorttext").text()
|
||||
val episodeWatched = episodebox.select("div.episodebox-icons > div").hasClass("status-icon-orange")
|
||||
val episodeWatchedCallback = episodebox.select("input.streamstarter_html5").eachAttr("data-playlist").first()
|
||||
|
||||
Episode(id = episodeId, watched = episodeWatched, shortDesc = episodeShortDesc)
|
||||
Episode(
|
||||
id = episodeId,
|
||||
shortDesc = episodeShortDesc,
|
||||
watched = episodeWatched,
|
||||
watchedCallback = episodeWatchedCallback
|
||||
)
|
||||
}
|
||||
} else {
|
||||
listOf(Episode())
|
||||
}
|
||||
|
||||
if (csrfToken.isEmpty()) {
|
||||
csrfToken = res.select("meta[name=csrf-token]").attr("content")
|
||||
}
|
||||
|
||||
// has attr data-lag (ger or jap)
|
||||
val playlists = res.select("input.streamstarter_html5").eachAttr("data-playlist")
|
||||
val csrfToken = res.select("meta[name=csrf-token]").attr("content")
|
||||
|
||||
//println("first entry: ${playlists.first()}")
|
||||
//println("csrf token is: $csrfToken")
|
||||
|
@ -177,6 +187,8 @@ class AoDParser {
|
|||
Pair("X-Requested-With", "XMLHttpRequest"),
|
||||
)
|
||||
|
||||
println("loading streaminfo with cstf: $csrfToken")
|
||||
|
||||
val res = Jsoup.connect(baseUrl + playlistPath)
|
||||
.ignoreContentType(true)
|
||||
.cookies(sessionCookies)
|
||||
|
@ -230,4 +242,20 @@ class AoDParser {
|
|||
}
|
||||
}
|
||||
|
||||
fun sendCallback(callbackPath: String) = GlobalScope.launch {
|
||||
val headers = mutableMapOf(
|
||||
Pair("Accept", "application/json, text/javascript, */*; q=0.01"),
|
||||
Pair("Accept-Language", "de,en-US;q=0.7,en;q=0.3"),
|
||||
Pair("Accept-Encoding", "gzip, deflate, br"),
|
||||
Pair("X-CSRF-Token", csrfToken),
|
||||
Pair("X-Requested-With", "XMLHttpRequest"),
|
||||
)
|
||||
|
||||
Jsoup.connect(baseUrl + callbackPath)
|
||||
.ignoreContentType(true)
|
||||
.cookies(sessionCookies)
|
||||
.headers(headers)
|
||||
.execute()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation
|
|||
import kotlinx.android.synthetic.main.fragment_media.*
|
||||
import org.mosad.teapod.MainActivity
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import org.mosad.teapod.util.EpisodesAdapter
|
||||
import org.mosad.teapod.util.Media
|
||||
|
@ -91,6 +92,11 @@ class MediaFragment(private val media: Media, private val tmdb: TMDBResponse) :
|
|||
if (this::adapterRecEpisodes.isInitialized) {
|
||||
adapterRecEpisodes.onItemClick = { _, position ->
|
||||
playStream(media.episodes[position].streamUrl)
|
||||
|
||||
// update watched state
|
||||
AoDParser().sendCallback(media.episodes[position].watchedCallback)
|
||||
adapterRecEpisodes.updateWatchedState(true, position)
|
||||
adapterRecEpisodes.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ data class Episode(
|
|||
var description: String = "",
|
||||
var shortDesc: String = "",
|
||||
var number: Int = 0,
|
||||
var watched: Boolean = false
|
||||
var watched: Boolean = false,
|
||||
var watchedCallback: String = ""
|
||||
)
|
||||
|
||||
data class TMDBResponse(
|
||||
|
|
|
@ -40,6 +40,10 @@ class EpisodesAdapter(private val episodes: List<Episode>, private val context:
|
|||
return episodes.size
|
||||
}
|
||||
|
||||
fun updateWatchedState(watched: Boolean, position: Int) {
|
||||
episodes[position].watched = watched
|
||||
}
|
||||
|
||||
inner class MyViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
init {
|
||||
view.setOnClickListener {
|
||||
|
|
Loading…
Reference in New Issue