Compare commits
9 Commits
5785fc91c1
...
528e74fda4
Author | SHA1 | Date | |
---|---|---|---|
528e74fda4 | |||
6ca1ea63fe | |||
ac7d0d0277 | |||
73909a6a63 | |||
7a90199923 | |||
f841d0c57f | |||
0b5eb885de | |||
7cdaa7a116 | |||
9df5be003b |
@ -11,7 +11,7 @@ android {
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 4200 //00.04.200
|
||||
versionName "0.4.2"
|
||||
versionName "0.5.0-alpha1"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
resValue "string", "build_time", buildTime()
|
||||
@ -29,6 +29,7 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
@ -44,7 +45,7 @@ dependencies {
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.6.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
|
||||
@ -55,11 +56,11 @@ dependencies {
|
||||
|
||||
implementation 'com.google.android.material:material:1.4.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.7'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.14.1'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-hls:2.14.1'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-dash:2.14.1'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.1'
|
||||
implementation 'com.google.android.exoplayer:extension-mediasession:2.14.1'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.14.2'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-hls:2.14.2'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-dash:2.14.2'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.2'
|
||||
implementation 'com.google.android.exoplayer:extension-mediasession:2.14.2'
|
||||
|
||||
implementation 'org.jsoup:jsoup:1.13.1'
|
||||
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
||||
|
@ -49,7 +49,9 @@ object AoDParser {
|
||||
private var loginSuccess = false
|
||||
|
||||
private val mediaList = arrayListOf<Media>() // actual media (data)
|
||||
val itemMediaList = arrayListOf<ItemMedia>() // gui media
|
||||
|
||||
// gui media
|
||||
val guiMediaList = arrayListOf<ItemMedia>()
|
||||
val highlightsList = arrayListOf<ItemMedia>()
|
||||
val newEpisodesList = arrayListOf<ItemMedia>()
|
||||
val newSimulcastsList = arrayListOf<ItemMedia>()
|
||||
@ -110,8 +112,8 @@ object AoDParser {
|
||||
* get a media by it's ID (int)
|
||||
* @return Media
|
||||
*/
|
||||
suspend fun getMediaById(mediaId: Int): Media {
|
||||
val media = mediaList.first { it.id == mediaId }
|
||||
suspend fun getMediaById(aodId: Int): Media {
|
||||
val media = mediaList.first { it.id == aodId }
|
||||
|
||||
if (media.episodes.isEmpty()) {
|
||||
loadStreams(media).join()
|
||||
@ -180,24 +182,39 @@ object AoDParser {
|
||||
val resAnimes = Jsoup.connect(baseUrl + libraryPath).get()
|
||||
//println(resAnimes)
|
||||
|
||||
itemMediaList.clear()
|
||||
guiMediaList.clear()
|
||||
mediaList.clear()
|
||||
resAnimes.select("div.animebox").forEach {
|
||||
val type = if (it.select("p.animebox-link").select("a").text().lowercase(Locale.ROOT) == "zur serie") {
|
||||
MediaType.TVSHOW
|
||||
} else {
|
||||
MediaType.MOVIE
|
||||
}
|
||||
val mediaTitle = it.select("h3.animebox-title").text()
|
||||
val mediaLink = it.select("p.animebox-link").select("a").attr("href")
|
||||
val mediaImage = it.select("p.animebox-image").select("img").attr("src")
|
||||
val mediaShortText = it.select("p.animebox-shorttext").text()
|
||||
val mediaId = mediaLink.substringAfterLast("/").toInt()
|
||||
val animes = resAnimes.select("div.animebox")
|
||||
|
||||
itemMediaList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
|
||||
mediaList.add(Media(mediaId, mediaLink, type).apply {
|
||||
info.title = mediaTitle
|
||||
info.posterUrl = mediaImage
|
||||
guiMediaList.addAll(
|
||||
animes.map {
|
||||
ItemMedia(
|
||||
id = it.select("p.animebox-link").select("a")
|
||||
.attr("href").substringAfterLast("/").toInt(),
|
||||
title = it.select("h3.animebox-title").text(),
|
||||
posterUrl = it.select("p.animebox-image").select("img")
|
||||
.attr("src")
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
// TODO legacy
|
||||
resAnimes.select("div.animebox").forEach {
|
||||
val id = it.select("p.animebox-link").select("a").attr("href")
|
||||
.substringAfterLast("/").toInt()
|
||||
val title = it.select("h3.animebox-title").text()
|
||||
val image = it.select("p.animebox-image").select("img").attr("src")
|
||||
val link = it.select("p.animebox-link").select("a").attr("href")
|
||||
val type = when (it.select("p.animebox-link").select("a").text().lowercase(Locale.ROOT)) {
|
||||
"zur serie" -> MediaType.TVSHOW
|
||||
"zum film" -> MediaType.MOVIE
|
||||
else -> MediaType.OTHER
|
||||
}
|
||||
val mediaShortText = it.select("p.animebox-shorttext").text()
|
||||
|
||||
mediaList.add(Media(id, link, type).apply {
|
||||
info.title = title
|
||||
info.posterUrl = image
|
||||
info.shortDesc = mediaShortText
|
||||
})
|
||||
}
|
||||
@ -327,23 +344,16 @@ object AoDParser {
|
||||
}.awaitAll()
|
||||
|
||||
playlists.forEach { aod ->
|
||||
// TODO improve language handling
|
||||
val locale = when (aod.extLanguage) {
|
||||
"ger" -> Locale.GERMAN
|
||||
"jap" -> Locale.JAPANESE
|
||||
else -> Locale.ROOT
|
||||
}
|
||||
|
||||
aod.playlist.forEach { ep ->
|
||||
aod.list.forEach { ep ->
|
||||
try {
|
||||
if (media.hasEpisode(ep.mediaid)) {
|
||||
media.getEpisodeById(ep.mediaid).streams.add(
|
||||
Stream(ep.sources.first().file, locale)
|
||||
Stream(ep.sources.first().file, aod.language)
|
||||
)
|
||||
} else {
|
||||
media.episodes.add(Episode(
|
||||
id = ep.mediaid,
|
||||
streams = mutableListOf(Stream(ep.sources.first().file, locale)),
|
||||
streams = mutableListOf(Stream(ep.sources.first().file, aod.language)),
|
||||
posterUrl = ep.image,
|
||||
title = ep.title,
|
||||
description = ep.description,
|
||||
@ -410,9 +420,9 @@ object AoDParser {
|
||||
/**
|
||||
* don't use Gson().fromJson() as we don't have any control over the api and it may change
|
||||
*/
|
||||
private fun parsePlaylistAsync(playlistPath: String, language: String): Deferred<AoDObject> {
|
||||
private fun parsePlaylistAsync(playlistPath: String, language: String): Deferred<AoDPlaylist> {
|
||||
if (playlistPath == "[]") {
|
||||
return CompletableDeferred(AoDObject(listOf(), language))
|
||||
return CompletableDeferred(AoDPlaylist(listOf(), Locale.ROOT))
|
||||
}
|
||||
|
||||
return CoroutineScope(Dispatchers.IO).async(Dispatchers.IO) {
|
||||
@ -435,7 +445,7 @@ object AoDParser {
|
||||
|
||||
//Gson().fromJson(res.body(), AoDObject::class.java)
|
||||
|
||||
return@async AoDObject(JsonParser.parseString(res.body()).asJsonObject
|
||||
return@async AoDPlaylist(JsonParser.parseString(res.body()).asJsonObject
|
||||
.get("playlist").asJsonArray.map {
|
||||
Playlist(
|
||||
sources = it.asJsonObject.get("sources").asJsonArray.map { source ->
|
||||
@ -447,7 +457,12 @@ object AoDParser {
|
||||
mediaid = it.asJsonObject.get("mediaid").asInt
|
||||
)
|
||||
},
|
||||
language
|
||||
// TODO improve language handling (via display language etc.)
|
||||
language = when (language) {
|
||||
"ger" -> Locale.GERMAN
|
||||
"jap" -> Locale.JAPANESE
|
||||
else -> Locale.ROOT
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ import org.mosad.teapod.ui.activity.onboarding.OnboardingActivity
|
||||
import org.mosad.teapod.ui.activity.player.PlayerActivity
|
||||
import org.mosad.teapod.ui.components.LoginDialog
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import org.mosad.teapod.util.MetaDBController
|
||||
import org.mosad.teapod.util.StorageController
|
||||
import org.mosad.teapod.util.exitAndRemoveTask
|
||||
import java.net.SocketTimeoutException
|
||||
@ -137,8 +138,12 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen
|
||||
*/
|
||||
private fun load() {
|
||||
val time = measureTimeMillis {
|
||||
// start the initial loading
|
||||
val loadingJob = CoroutineScope(Dispatchers.IO + CoroutineName("InitialLoadingScope"))
|
||||
.async { AoDParser.initialLoading() } // start the initial loading
|
||||
.async {
|
||||
launch { AoDParser.initialLoading() }
|
||||
launch { MetaDBController.list() }
|
||||
}
|
||||
|
||||
// load all saved stuff here
|
||||
Preferences.load(this)
|
||||
|
@ -120,24 +120,24 @@ class HomeFragment : Fragment() {
|
||||
activity?.showFragment(MediaFragment(highlightMedia.id))
|
||||
}
|
||||
|
||||
adapterMyList.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterMyList.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
|
||||
adapterNewEpisodes.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterNewEpisodes.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
|
||||
adapterNewSimulcasts.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterNewSimulcasts.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
|
||||
adapterNewTitles.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterNewTitles.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
|
||||
adapterTopTen.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterTopTen.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ class HomeFragment : Fragment() {
|
||||
|
||||
private fun mapMyListToItemMedia(): List<ItemMedia> {
|
||||
return StorageController.myList.mapNotNull { elementId ->
|
||||
AoDParser.itemMediaList.firstOrNull { it.id == elementId }.also {
|
||||
AoDParser.guiMediaList.firstOrNull { it.id == elementId }.also {
|
||||
// it the my list entry wasn't found in itemMediaList Log it
|
||||
if (it == null) {
|
||||
Log.w(javaClass.name, "The element with the id $elementId was not found.")
|
||||
|
@ -30,7 +30,7 @@ class LibraryFragment : Fragment() {
|
||||
lifecycleScope.launch {
|
||||
// create and set the adapter, needs context
|
||||
context?.let {
|
||||
adapter = MediaItemAdapter(AoDParser.itemMediaList)
|
||||
adapter = MediaItemAdapter(AoDParser.guiMediaList)
|
||||
adapter.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.util.StorageController
|
||||
import org.mosad.teapod.util.tmdb.TMDBMovie
|
||||
import org.mosad.teapod.util.tmdb.TMDBApiController
|
||||
|
||||
/**
|
||||
* The media detail fragment.
|
||||
@ -62,7 +64,6 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
}
|
||||
}.attach()
|
||||
|
||||
|
||||
lifecycleScope.launch {
|
||||
model.load(mediaId) // load the streams and tmdb for the selected media
|
||||
|
||||
@ -85,21 +86,25 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
*/
|
||||
private fun updateGUI() = with(model) {
|
||||
// generic gui
|
||||
val backdropUrl = if (tmdb.backdropUrl.isNotEmpty()) tmdb.backdropUrl else media.info.posterUrl
|
||||
val posterUrl = if (tmdb.posterUrl.isNotEmpty()) tmdb.posterUrl else media.info.posterUrl
|
||||
val backdropUrl = tmdbResult?.backdropPath?.let { TMDBApiController.imageUrl + it }
|
||||
?: media.info.posterUrl
|
||||
val posterUrl = tmdbResult?.posterPath?.let { TMDBApiController.imageUrl + it }
|
||||
?: media.info.posterUrl
|
||||
|
||||
// load poster and backdrop
|
||||
Glide.with(requireContext()).load(posterUrl)
|
||||
.into(binding.imagePoster)
|
||||
Glide.with(requireContext()).load(backdropUrl)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(20, 3)))
|
||||
.into(binding.imageBackdrop)
|
||||
|
||||
Glide.with(requireContext()).load(posterUrl)
|
||||
.into(binding.imagePoster)
|
||||
|
||||
binding.textTitle.text = media.info.title
|
||||
binding.textYear.text = media.info.year.toString()
|
||||
binding.textAge.text = media.info.age.toString()
|
||||
binding.textOverview.text = media.info.shortDesc
|
||||
|
||||
// set "my list" indicator
|
||||
if (StorageController.myList.contains(media.id)) {
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
|
||||
} else {
|
||||
@ -133,12 +138,13 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
fragments.add(MediaFragmentEpisodes())
|
||||
pagerAdapter.notifyDataSetChanged()
|
||||
} else if (media.type == MediaType.MOVIE) {
|
||||
val tmdbMovie = (tmdbResult as TMDBMovie?)
|
||||
|
||||
if (tmdb.runtime > 0) {
|
||||
if (tmdbMovie?.runtime != null) {
|
||||
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
R.plurals.text_runtime,
|
||||
tmdb.runtime,
|
||||
tmdb.runtime
|
||||
tmdbMovie.runtime,
|
||||
tmdbMovie.runtime
|
||||
)
|
||||
} else {
|
||||
binding.textEpisodesOrRuntime.visibility = View.GONE
|
||||
@ -165,7 +171,7 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
when (media.type) {
|
||||
MediaType.MOVIE -> playEpisode(media.episodes.first())
|
||||
MediaType.TVSHOW -> playEpisode(nextEpisode)
|
||||
else -> Log.e(javaClass.name, "Wrong Type: $media.type")
|
||||
else -> Log.e(javaClass.name, "Wrong Type: ${media.type}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class MediaFragmentEpisodes : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
adapterRecEpisodes = EpisodeItemAdapter(model.media.episodes)
|
||||
adapterRecEpisodes = EpisodeItemAdapter(model.media.episodes, model.tmdbTVSeason?.episodes)
|
||||
binding.recyclerEpisodes.adapter = adapterRecEpisodes
|
||||
|
||||
// set onItemClick only in adapter is initialized
|
||||
|
@ -30,7 +30,7 @@ class SearchFragment : Fragment() {
|
||||
lifecycleScope.launch {
|
||||
// create and set the adapter, needs context
|
||||
context?.let {
|
||||
adapter = MediaItemAdapter(AoDParser.itemMediaList)
|
||||
adapter = MediaItemAdapter(AoDParser.guiMediaList)
|
||||
adapter!!.onItemClick = { mediaId, _ ->
|
||||
binding.searchText.clearFocus()
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
|
@ -1,13 +1,18 @@
|
||||
package org.mosad.teapod.ui.activity.main.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.*
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import org.mosad.teapod.util.tmdb.TMDBApiController
|
||||
import org.mosad.teapod.util.tmdb.TMDBResult
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVSeason
|
||||
|
||||
/**
|
||||
* handle media, next ep and tmdb
|
||||
* TODO this lives in activity, is this correct?
|
||||
*/
|
||||
class MediaFragmentViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
@ -15,22 +20,55 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
|
||||
internal set
|
||||
var nextEpisode = Episode()
|
||||
internal set
|
||||
var tmdb = TMDBResponse()
|
||||
var tmdbResult: TMDBResult? = null // TODO rename
|
||||
internal set
|
||||
var tmdbTVSeason: TMDBTVSeason? =null
|
||||
internal set
|
||||
var mediaMeta: Meta? = null
|
||||
internal set
|
||||
|
||||
/**
|
||||
* set media, tmdb and nextEpisode
|
||||
* TODO run aod and tmdb load parallel
|
||||
*/
|
||||
suspend fun load(mediaId: Int) {
|
||||
val tmdbApiController = TMDBApiController()
|
||||
media = AoDParser.getMediaById(mediaId)
|
||||
tmdb = TMDBApiController().search(media.info.title, media.type)
|
||||
|
||||
// check if metaDB knows the title
|
||||
val tmdbId: Int = if (MetaDBController.mediaList.media.contains(media.id)) {
|
||||
// load media info from metaDB
|
||||
val metaDB = MetaDBController()
|
||||
mediaMeta = when (media.type) {
|
||||
MediaType.MOVIE -> metaDB.getMovieMetadata(media.id)
|
||||
MediaType.TVSHOW -> metaDB.getTVShowMetadata(media.id)
|
||||
else -> null
|
||||
}
|
||||
|
||||
mediaMeta?.tmdbId ?: -1
|
||||
} else {
|
||||
// use tmdb search to get media info
|
||||
mediaMeta = null // set mediaMeta to null, if metaDB doesn't know the media
|
||||
tmdbApiController.search(stripTitleInfo(media.info.title), media.type)
|
||||
}
|
||||
|
||||
tmdbResult = when (media.type) {
|
||||
MediaType.MOVIE -> tmdbApiController.getMovieDetails(tmdbId)
|
||||
MediaType.TVSHOW -> tmdbApiController.getTVShowDetails(tmdbId)
|
||||
else -> null
|
||||
}
|
||||
println(tmdbResult) // TODO
|
||||
|
||||
// get season info, if metaDB knows the tv show
|
||||
tmdbTVSeason = if (media.type == MediaType.TVSHOW && mediaMeta != null) {
|
||||
val tvShowMeta = mediaMeta as TVShowMeta
|
||||
tmdbApiController.getTVSeasonDetails(tvShowMeta.tmdbId, tvShowMeta.tmdbSeasonNumber)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
if (media.type == MediaType.TVSHOW) {
|
||||
nextEpisode = if (media.episodes.firstOrNull{ !it.watched } != null) {
|
||||
media.episodes.first{ !it.watched }
|
||||
} else {
|
||||
media.episodes.first()
|
||||
}
|
||||
nextEpisode = media.episodes.firstOrNull{ !it.watched } ?: media.episodes.first()
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,4 +83,30 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
|
||||
?: media.episodes.first()
|
||||
}
|
||||
|
||||
// remove unneeded info from the media title before searching
|
||||
private fun stripTitleInfo(title: String): String {
|
||||
return title.replace("(Sub)", "")
|
||||
.replace(Regex("-?\\s?[0-9]+.\\s?(Staffel|Season)"), "")
|
||||
.replace(Regex("(Staffel|Season)\\s?[0-9]+"), "")
|
||||
.trim()
|
||||
}
|
||||
|
||||
/** guess Season from title
|
||||
* if the title ends with a number, that could be the season
|
||||
* if the title ends with Regex("-?\\s?[0-9]+.\\s?(Staffel|Season)") or
|
||||
* Regex("(Staffel|Season)\\s?[0-9]+"), that is the season information
|
||||
*/
|
||||
private fun guessSeasonFromTitle(title: String): Int {
|
||||
val helpTitle = title.replace("(Sub)", "").trim()
|
||||
Log.d("test", "helpTitle: $helpTitle")
|
||||
|
||||
return if (helpTitle.last().isDigit()) {
|
||||
helpTitle.last().digitToInt()
|
||||
} else {
|
||||
Regex("([0-9]+.\\s?(Staffel|Season))|((Staffel|Season)\\s?[0-9]+)")
|
||||
.find(helpTitle)
|
||||
?.value?.filter { it.isDigit() }?.toInt() ?: 1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -32,10 +32,7 @@ import org.mosad.teapod.R
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.ui.components.EpisodesListPlayer
|
||||
import org.mosad.teapod.ui.components.LanguageSettingsPlayer
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import org.mosad.teapod.util.hideBars
|
||||
import org.mosad.teapod.util.isInPiPMode
|
||||
import org.mosad.teapod.util.navToLauncherTask
|
||||
import org.mosad.teapod.util.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.concurrent.scheduleAtFixedRate
|
||||
@ -226,7 +223,10 @@ class PlayerActivity : AppCompatActivity() {
|
||||
// when the player controls get hidden, hide the bars too
|
||||
video_view.setControllerVisibilityListener {
|
||||
when (it) {
|
||||
View.GONE -> hideBars()
|
||||
View.GONE -> {
|
||||
hideBars()
|
||||
// TODO also hide the skip op button
|
||||
}
|
||||
View.VISIBLE -> updateControls()
|
||||
}
|
||||
}
|
||||
@ -244,6 +244,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
rwd_10.setOnButtonClickListener { rewind() }
|
||||
ffwd_10.setOnButtonClickListener { fastForward() }
|
||||
button_next_ep.setOnClickListener { playNextEpisode() }
|
||||
button_skip_op.setOnClickListener { skipOpening() }
|
||||
button_language.setOnClickListener { showLanguageSettings() }
|
||||
button_episodes.setOnClickListener { showEpisodesList() }
|
||||
button_next_ep_c.setOnClickListener { playNextEpisode() }
|
||||
@ -262,16 +263,20 @@ class PlayerActivity : AppCompatActivity() {
|
||||
|
||||
timerUpdates = Timer().scheduleAtFixedRate(0, 500) {
|
||||
lifecycleScope.launch {
|
||||
val currentPosition = model.player.currentPosition
|
||||
val btnNextEpIsVisible = button_next_ep.isVisible
|
||||
val controlsVisible = controller.isVisible
|
||||
|
||||
// make sure remaining time is > 0
|
||||
if (model.player.duration > 0) {
|
||||
remainingTime = model.player.duration - model.player.currentPosition
|
||||
remainingTime = model.player.duration - currentPosition
|
||||
remainingTime = if (remainingTime < 0) 0 else remainingTime
|
||||
}
|
||||
|
||||
// TODO add metaDB ending_start support
|
||||
// if remaining time < 20 sec, a next ep is set, autoplay is enabled and not in pip:
|
||||
// show next ep button
|
||||
if (remainingTime in 1..20000) {
|
||||
// if the next ep button is not visible, make it visible. Don't show in pip mode
|
||||
if (!btnNextEpIsVisible && model.nextEpisode != null && Preferences.autoplay && !isInPiPMode()) {
|
||||
showButtonNextEp()
|
||||
}
|
||||
@ -279,6 +284,19 @@ class PlayerActivity : AppCompatActivity() {
|
||||
hideButtonNextEp()
|
||||
}
|
||||
|
||||
// if meta data is present and opening_start & opening_duration are valid, show skip opening
|
||||
model.currentEpisodeMeta?.let {
|
||||
if (it.openingDuration > 0 &&
|
||||
currentPosition in it.openingStart..(it.openingStart + 10000) &&
|
||||
!button_skip_op.isVisible
|
||||
) {
|
||||
showButtonSkipOp()
|
||||
} else if (button_skip_op.isVisible && currentPosition !in it.openingStart..(it.openingStart + 10000)) {
|
||||
// the button should only be visible, if currentEpisodeMeta != null
|
||||
hideButtonSkipOp()
|
||||
}
|
||||
}
|
||||
|
||||
// if controls are visible, update them
|
||||
if (controlsVisible) {
|
||||
updateControls()
|
||||
@ -376,12 +394,21 @@ class PlayerActivity : AppCompatActivity() {
|
||||
hideButtonNextEp()
|
||||
}
|
||||
|
||||
private fun skipOpening() {
|
||||
// calculate the seek time
|
||||
model.currentEpisodeMeta?.let {
|
||||
val seekTime = (it.openingStart + it.openingDuration) - model.player.currentPosition
|
||||
model.seekToOffset(seekTime)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* show the next episode button
|
||||
* TODO improve the show animation
|
||||
*/
|
||||
private fun showButtonNextEp() {
|
||||
button_next_ep.visibility = View.VISIBLE
|
||||
button_next_ep.isVisible = true
|
||||
button_next_ep.alpha = 0.0f
|
||||
|
||||
button_next_ep.animate()
|
||||
@ -399,7 +426,28 @@ class PlayerActivity : AppCompatActivity() {
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator?) {
|
||||
super.onAnimationEnd(animation)
|
||||
button_next_ep.visibility = View.GONE
|
||||
button_next_ep.isVisible = false
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun showButtonSkipOp() {
|
||||
button_skip_op.isVisible = true
|
||||
button_skip_op.alpha = 0.0f
|
||||
|
||||
button_skip_op.animate()
|
||||
.alpha(1.0f)
|
||||
.setListener(null)
|
||||
}
|
||||
|
||||
private fun hideButtonSkipOp() {
|
||||
button_skip_op.animate()
|
||||
.alpha(0.0f)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator?) {
|
||||
super.onAnimationEnd(animation)
|
||||
button_skip_op.isVisible = false
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -19,9 +19,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.util.Media
|
||||
import org.mosad.teapod.util.*
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@ -29,6 +27,9 @@ import kotlin.collections.ArrayList
|
||||
* PlayerViewModel handles all stuff related to media/episodes.
|
||||
* When currentEpisode is changed the player will start playing it (not initial media),
|
||||
* the next episode will be update and the callback is handled.
|
||||
*
|
||||
* TODO rework don't use episodes for everything, use media instead
|
||||
* this is a major rework of the AoDParser/Player/Media architecture
|
||||
*/
|
||||
class PlayerViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
@ -45,6 +46,10 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
||||
internal set
|
||||
var nextEpisode: Episode? = null
|
||||
internal set
|
||||
var mediaMeta: Meta? = null
|
||||
internal set
|
||||
var currentEpisodeMeta: EpisodeMeta? = null
|
||||
internal set
|
||||
var currentLanguage: Locale = Locale.ROOT
|
||||
internal set
|
||||
|
||||
@ -75,10 +80,12 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
||||
fun loadMedia(mediaId: Int, episodeId: Int) {
|
||||
runBlocking {
|
||||
media = AoDParser.getMediaById(mediaId)
|
||||
mediaMeta = loadMediaMeta(media.id) // can be done blocking, since it should be cached
|
||||
}
|
||||
|
||||
currentEpisode = media.getEpisodeById(episodeId)
|
||||
nextEpisode = selectNextEpisode()
|
||||
currentEpisodeMeta = getEpisodeMetaByAoDMediaId(currentEpisode.id)
|
||||
currentLanguage = currentEpisode.getPreferredStream(preferredLanguage).language
|
||||
}
|
||||
|
||||
@ -120,6 +127,7 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
||||
currentLanguage = preferredStream.language // update current language, since it may have changed
|
||||
currentEpisode = episode
|
||||
nextEpisode = selectNextEpisode()
|
||||
currentEpisodeMeta = getEpisodeMetaByAoDMediaId(episode.id)
|
||||
currentEpisodeChangedListener.forEach { it() } // update player gui (title)
|
||||
|
||||
val mediaSource = HlsMediaSource.Factory(dataSourceFactory).createMediaSource(
|
||||
@ -159,6 +167,23 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun getEpisodeMetaByAoDMediaId(aodMediaId: Int): EpisodeMeta? {
|
||||
val meta = mediaMeta
|
||||
return if (meta is TVShowMeta) {
|
||||
meta.episodes.firstOrNull { it.aodMediaId == aodMediaId }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun loadMediaMeta(aodId: Int): Meta? {
|
||||
return if (media.type == DataTypes.MediaType.TVSHOW) {
|
||||
MetaDBController().getTVShowMetadata(aodId)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the current episodeId, get the next episode. If there is no next
|
||||
* episode, return null
|
||||
|
@ -36,7 +36,7 @@ data class ThirdPartyComponent(
|
||||
* it is uses in the ItemMediaAdapter (RecyclerView)
|
||||
*/
|
||||
data class ItemMedia(
|
||||
val id: Int,
|
||||
val id: Int, // aod path id
|
||||
val title: String,
|
||||
val posterUrl: String
|
||||
)
|
||||
@ -98,24 +98,12 @@ data class Stream(
|
||||
val language : Locale
|
||||
)
|
||||
|
||||
/**
|
||||
* this class is used for tmdb responses
|
||||
*/
|
||||
data class TMDBResponse(
|
||||
val id: Int = 0,
|
||||
val title: String = "",
|
||||
val overview: String = "",
|
||||
val posterUrl: String = "",
|
||||
val backdropUrl: String = "",
|
||||
val runtime: Int = 0
|
||||
)
|
||||
|
||||
/**
|
||||
* this class is used to represent the aod json API?
|
||||
*/
|
||||
data class AoDObject(
|
||||
val playlist: List<Playlist>,
|
||||
val extLanguage: String
|
||||
data class AoDPlaylist(
|
||||
val list: List<Playlist>,
|
||||
val language: Locale
|
||||
)
|
||||
|
||||
data class Playlist(
|
||||
|
156
app/src/main/java/org/mosad/teapod/util/MetaDBController.kt
Normal file
156
app/src/main/java/org/mosad/teapod/util/MetaDBController.kt
Normal file
@ -0,0 +1,156 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2021 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.FileNotFoundException
|
||||
import java.net.URL
|
||||
|
||||
class MetaDBController {
|
||||
|
||||
companion object {
|
||||
private const val repoUrl = "https://gitlab.com/Seil0/teapodmetadb/-/raw/main/aod/"
|
||||
|
||||
var mediaList = MediaList(listOf())
|
||||
private var metaCacheList = arrayListOf<Meta>()
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
suspend fun list() = withContext(Dispatchers.IO) {
|
||||
val url = URL("$repoUrl/list.json")
|
||||
val json = url.readText()
|
||||
|
||||
mediaList = Gson().fromJson(json, MediaList::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta data for a movie from MetaDB
|
||||
* @param aodId The AoD id of the media
|
||||
* @return A meta movie object, or null if not found
|
||||
*/
|
||||
suspend fun getMovieMetadata(aodId: Int): MovieMeta? {
|
||||
return metaCacheList.firstOrNull {
|
||||
it.aodId == aodId
|
||||
} as MovieMeta? ?: getMovieMetadataFromDB(aodId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta data for a tv show from MetaDB
|
||||
* @param aodId The AoD id of the media
|
||||
* @return A meta tv show object, or null if not found
|
||||
*/
|
||||
suspend fun getTVShowMetadata(aodId: Int): TVShowMeta? {
|
||||
return metaCacheList.firstOrNull {
|
||||
it.aodId == aodId
|
||||
} as TVShowMeta? ?: getTVShowMetadataFromDB(aodId)
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun getMovieMetadataFromDB(aodId: Int): MovieMeta? = withContext(Dispatchers.IO) {
|
||||
val url = URL("$repoUrl/movie/$aodId/media.json")
|
||||
return@withContext try {
|
||||
val json = url.readText()
|
||||
val meta = Gson().fromJson(json, MovieMeta::class.java)
|
||||
metaCacheList.add(meta)
|
||||
|
||||
meta
|
||||
} catch (ex: FileNotFoundException) {
|
||||
Log.w(javaClass.name, "Waring: The requested file was not found. Requested ID: $aodId", ex)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun getTVShowMetadataFromDB(aodId: Int): TVShowMeta? = withContext(Dispatchers.IO) {
|
||||
val url = URL("$repoUrl/tv/$aodId/media.json")
|
||||
return@withContext try {
|
||||
val json = url.readText()
|
||||
val meta = Gson().fromJson(json, TVShowMeta::class.java)
|
||||
metaCacheList.add(meta)
|
||||
|
||||
meta
|
||||
} catch (ex: FileNotFoundException) {
|
||||
Log.w(javaClass.name, "Waring: The requested file was not found. Requested ID: $aodId", ex)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// class representing the media list json object
|
||||
data class MediaList(
|
||||
val media: List<Int>
|
||||
)
|
||||
|
||||
// abstract class used for meta data objects (tv, movie)
|
||||
abstract class Meta {
|
||||
abstract val id: Int
|
||||
abstract val aodId: Int
|
||||
abstract val tmdbId: Int
|
||||
}
|
||||
|
||||
// class representing the movie json object
|
||||
data class MovieMeta(
|
||||
override val id: Int,
|
||||
@SerializedName("aod_id")
|
||||
override val aodId: Int,
|
||||
@SerializedName("tmdb_id")
|
||||
override val tmdbId: Int
|
||||
): Meta()
|
||||
|
||||
// class representing the tv show json object
|
||||
data class TVShowMeta(
|
||||
override val id: Int,
|
||||
@SerializedName("aod_id")
|
||||
override val aodId: Int,
|
||||
@SerializedName("tmdb_id")
|
||||
override val tmdbId: Int,
|
||||
@SerializedName("tmdb_season_id")
|
||||
val tmdbSeasonId: Int,
|
||||
@SerializedName("tmdb_season_number")
|
||||
val tmdbSeasonNumber: Int,
|
||||
@SerializedName("episodes")
|
||||
val episodes: List<EpisodeMeta>
|
||||
): Meta()
|
||||
|
||||
// class used in TVShowMeta, part of the tv show json object
|
||||
data class EpisodeMeta(
|
||||
val id: Int,
|
||||
@SerializedName("aod_media_id")
|
||||
val aodMediaId: Int,
|
||||
@SerializedName("tmdb_id")
|
||||
val tmdbId: Int,
|
||||
@SerializedName("tmdb_number")
|
||||
val tmdbNumber: Int,
|
||||
@SerializedName("opening_start")
|
||||
val openingStart: Long,
|
||||
@SerializedName("opening_duration")
|
||||
val openingDuration: Long,
|
||||
@SerializedName("ending_start")
|
||||
val endingStart: Long,
|
||||
@SerializedName("ending_duration")
|
||||
val endingDuration: Long
|
||||
)
|
@ -1,121 +0,0 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import java.net.URL
|
||||
import java.net.URLEncoder
|
||||
|
||||
class TMDBApiController {
|
||||
|
||||
private val apiUrl = "https://api.themoviedb.org/3"
|
||||
private val searchMovieUrl = "$apiUrl/search/movie"
|
||||
private val searchTVUrl = "$apiUrl/search/tv"
|
||||
private val getMovieUrl = "$apiUrl/movie"
|
||||
private val apiKey = "de959cf9c07a08b5ca7cb51cda9a40c2"
|
||||
private val language = "de"
|
||||
private val preparedParameters = "?api_key=$apiKey&language=$language"
|
||||
|
||||
private val imageUrl = "https://image.tmdb.org/t/p/w500"
|
||||
|
||||
suspend fun search(title: String, type: MediaType): TMDBResponse {
|
||||
// remove unneeded text from the media title before searching
|
||||
val searchTerm = title.replace("(Sub)", "")
|
||||
.replace(Regex("-?\\s?[0-9]+.\\s?(Staffel|Season)"), "")
|
||||
.replace(Regex("(Staffel|Season)\\s?[0-9]+"), "")
|
||||
.trim()
|
||||
|
||||
return when (type) {
|
||||
MediaType.MOVIE -> searchMovie(searchTerm)
|
||||
MediaType.TVSHOW -> searchTVShow(searchTerm)
|
||||
else -> {
|
||||
Log.e(javaClass.name, "Wrong Type: $type")
|
||||
TMDBResponse()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun searchTVShow(title: String): TMDBResponse = withContext(Dispatchers.IO) {
|
||||
val url = URL("$searchTVUrl$preparedParameters&query=${URLEncoder.encode(title, "UTF-8")}")
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
// println(response)
|
||||
|
||||
val sortedResults = response.get("results").asJsonArray.toList().sortedBy {
|
||||
getStringNotNull(it.asJsonObject, "name")
|
||||
}
|
||||
|
||||
return@withContext if (sortedResults.isNotEmpty()) {
|
||||
sortedResults.first().asJsonObject.let {
|
||||
val id = getStringNotNull(it, "id").toInt()
|
||||
val overview = getStringNotNull(it, "overview")
|
||||
val posterPath = getStringNotNullPrefix(it, "poster_path", imageUrl)
|
||||
val backdropPath = getStringNotNullPrefix(it, "backdrop_path", imageUrl)
|
||||
|
||||
TMDBResponse(id, "", overview, posterPath, backdropPath)
|
||||
}
|
||||
} else {
|
||||
TMDBResponse()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun searchMovie(title: String): TMDBResponse = withContext(Dispatchers.IO) {
|
||||
val url = URL("$searchMovieUrl$preparedParameters&query=${URLEncoder.encode(title, "UTF-8")}")
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
// println(response)
|
||||
|
||||
val sortedResults = response.get("results").asJsonArray.toList().sortedBy {
|
||||
getStringNotNull(it.asJsonObject, "title")
|
||||
}
|
||||
|
||||
return@withContext if (sortedResults.isNotEmpty()) {
|
||||
sortedResults.first().asJsonObject.let {
|
||||
val id = getStringNotNull(it,"id").toInt()
|
||||
val overview = getStringNotNull(it,"overview")
|
||||
val posterPath = getStringNotNullPrefix(it, "poster_path", imageUrl)
|
||||
val backdropPath = getStringNotNullPrefix(it, "backdrop_path", imageUrl)
|
||||
val runtime = getMovieRuntime(id)
|
||||
|
||||
TMDBResponse(id, "", overview, posterPath, backdropPath, runtime)
|
||||
}
|
||||
} else {
|
||||
TMDBResponse()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* currently only used for runtime, need a rework
|
||||
*/
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
suspend fun getMovieRuntime(id: Int): Int = withContext(Dispatchers.IO) {
|
||||
val url = URL("$getMovieUrl/$id?api_key=$apiKey&language=$language")
|
||||
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
return@withContext getStringNotNull(response,"runtime").toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* return memberName as string if it's not JsonNull,
|
||||
* else return an empty string
|
||||
*/
|
||||
private fun getStringNotNull(jsonObject: JsonObject, memberName: String): String {
|
||||
return getStringNotNullPrefix(jsonObject, memberName, "")
|
||||
}
|
||||
|
||||
/**
|
||||
* return memberName as string with a prefix if it's not JsonNull,
|
||||
* else return an empty string
|
||||
*/
|
||||
private fun getStringNotNullPrefix(jsonObject: JsonObject, memberName: String, prefix: String): String {
|
||||
return if (!jsonObject.get(memberName).isJsonNull) {
|
||||
prefix + jsonObject.get(memberName).asString
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,8 +12,9 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemEpisodeBinding
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVEpisode
|
||||
|
||||
class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Adapter<EpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
class EpisodeItemAdapter(private val episodes: List<Episode>, private val tmdbEpisodes: List<TMDBTVEpisode>?) : RecyclerView.Adapter<EpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
|
||||
var onImageClick: ((String, Int) -> Unit)? = null
|
||||
|
||||
@ -32,7 +33,13 @@ class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Ada
|
||||
}
|
||||
|
||||
holder.binding.textEpisodeTitle.text = titleText
|
||||
holder.binding.textEpisodeDesc.text = ep.shortDesc
|
||||
holder.binding.textEpisodeDesc.text = if (ep.shortDesc.isNotEmpty()) {
|
||||
ep.shortDesc
|
||||
} else if (tmdbEpisodes != null && position < tmdbEpisodes.size){
|
||||
tmdbEpisodes[position].overview
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
if (episodes[position].posterUrl.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.posterUrl)
|
||||
|
@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2021 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.util.tmdb
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonParser
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import java.io.FileNotFoundException
|
||||
import java.net.URL
|
||||
import java.net.URLEncoder
|
||||
|
||||
/**
|
||||
* Controller for tmdb api integration.
|
||||
* Data types are in TMDBDataTypes. For the type definitions see:
|
||||
* https://developers.themoviedb.org/3/getting-started/introduction
|
||||
*
|
||||
* TODO evaluate Klaxon
|
||||
*/
|
||||
class TMDBApiController {
|
||||
|
||||
private val apiUrl = "https://api.themoviedb.org/3"
|
||||
private val searchMovieUrl = "$apiUrl/search/movie"
|
||||
private val searchTVUrl = "$apiUrl/search/tv"
|
||||
private val detailsMovieUrl = "$apiUrl/movie"
|
||||
private val detailsTVUrl = "$apiUrl/tv"
|
||||
private val apiKey = "de959cf9c07a08b5ca7cb51cda9a40c2"
|
||||
private val language = "de"
|
||||
private val preparedParameters = "?api_key=$apiKey&language=$language"
|
||||
|
||||
companion object{
|
||||
const val imageUrl = "https://image.tmdb.org/t/p/w500"
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
/**
|
||||
* Search for a media(movie or tv show) in tmdb
|
||||
* @param query The query text
|
||||
* @param type The media type (movie or tv show)
|
||||
* @return The media tmdb id, or -1 if not found
|
||||
*/
|
||||
suspend fun search(query: String, type: MediaType): Int = withContext(Dispatchers.IO) {
|
||||
val searchUrl = when (type) {
|
||||
MediaType.MOVIE -> searchMovieUrl
|
||||
MediaType.TVSHOW -> searchTVUrl
|
||||
else -> {
|
||||
Log.e(javaClass.name, "Wrong Type: $type")
|
||||
return@withContext -1
|
||||
}
|
||||
}
|
||||
|
||||
val url = URL("$searchUrl$preparedParameters&query=${URLEncoder.encode(query, "UTF-8")}")
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
val sortedResults = response.get("results").asJsonArray.toList().sortedBy {
|
||||
it.asJsonObject.get("title")?.asString
|
||||
}
|
||||
|
||||
return@withContext sortedResults.firstOrNull()?.asJsonObject?.get("id")?.asInt ?: -1
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
/**
|
||||
* Get details for a movie from tmdb
|
||||
* @param movieId The tmdb ID of the movie
|
||||
* @return A tmdb movie object, or null if not found
|
||||
*/
|
||||
suspend fun getMovieDetails(movieId: Int): TMDBMovie? = withContext(Dispatchers.IO) {
|
||||
val url = URL("$detailsMovieUrl/$movieId?api_key=$apiKey&language=$language")
|
||||
|
||||
return@withContext try {
|
||||
val json = url.readText()
|
||||
Gson().fromJson(json, TMDBMovie::class.java)
|
||||
} catch (ex: FileNotFoundException) {
|
||||
Log.w(javaClass.name, "Waring: The requested media was not found. Requested ID: $movieId", ex)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
/**
|
||||
* Get details for a tv show from tmdb
|
||||
* @param tvId The tmdb ID of the tv show
|
||||
* @return A tmdb tv show object, or null if not found
|
||||
*/
|
||||
suspend fun getTVShowDetails(tvId: Int): TMDBTVShow? = withContext(Dispatchers.IO) {
|
||||
val url = URL("$detailsTVUrl/$tvId?api_key=$apiKey&language=$language")
|
||||
|
||||
return@withContext try {
|
||||
val json = url.readText()
|
||||
Gson().fromJson(json, TMDBTVShow::class.java)
|
||||
} catch (ex: FileNotFoundException) {
|
||||
Log.w(javaClass.name, "Waring: The requested media was not found. Requested ID: $tvId", ex)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
/**
|
||||
* Get details for a tv show season from tmdb
|
||||
* @param tvId The tmdb ID of the tv show
|
||||
* @param seasonNumber The tmdb season number
|
||||
* @return A tmdb tv season object, or null if not found
|
||||
*/
|
||||
suspend fun getTVSeasonDetails(tvId: Int, seasonNumber: Int): TMDBTVSeason? = withContext(Dispatchers.IO) {
|
||||
val url = URL("$detailsTVUrl/$tvId/season/$seasonNumber?api_key=$apiKey&language=$language")
|
||||
|
||||
return@withContext try {
|
||||
val json = url.readText()
|
||||
Gson().fromJson(json, TMDBTVSeason::class.java)
|
||||
} catch (ex: FileNotFoundException) {
|
||||
Log.w(javaClass.name, "Waring: The requested media was not found. Requested ID: $tvId, Season: $seasonNumber", ex)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2021 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.util.tmdb
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* These data classes represent the tmdb api json objects.
|
||||
* Fields which are nullable in the tmdb api are also nullable here.
|
||||
*/
|
||||
|
||||
abstract class TMDBResult{
|
||||
abstract val id: Int
|
||||
abstract val name: String
|
||||
abstract val overview: String? // for movies tmdb return string or null
|
||||
abstract val posterPath: String?
|
||||
abstract val backdropPath: String?
|
||||
}
|
||||
|
||||
data class TMDBMovie(
|
||||
override val id: Int,
|
||||
override val name: String,
|
||||
override val overview: String?,
|
||||
@SerializedName("poster_path")
|
||||
override val posterPath: String?,
|
||||
@SerializedName("backdrop_path")
|
||||
override val backdropPath: String?,
|
||||
@SerializedName("release_date")
|
||||
val releaseDate: String,
|
||||
@SerializedName("runtime")
|
||||
val runtime: Int?,
|
||||
// TODO generes
|
||||
): TMDBResult()
|
||||
|
||||
data class TMDBTVShow(
|
||||
override val id: Int,
|
||||
override val name: String,
|
||||
override val overview: String,
|
||||
@SerializedName("poster_path")
|
||||
override val posterPath: String?,
|
||||
@SerializedName("backdrop_path")
|
||||
override val backdropPath: String?,
|
||||
@SerializedName("first_air_date")
|
||||
val firstAirDate: String,
|
||||
@SerializedName("status")
|
||||
val status: String,
|
||||
// TODO generes
|
||||
): TMDBResult()
|
||||
|
||||
data class TMDBTVSeason(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val overview: String,
|
||||
@SerializedName("poster_path")
|
||||
val posterPath: String?,
|
||||
@SerializedName("air_date")
|
||||
val airDate: String,
|
||||
@SerializedName("episodes")
|
||||
val episodes: List<TMDBTVEpisode>,
|
||||
@SerializedName("season_number")
|
||||
val seasonNumber: Int
|
||||
)
|
||||
|
||||
data class TMDBTVEpisode(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val overview: String,
|
||||
@SerializedName("air_date")
|
||||
val airDate: String,
|
||||
@SerializedName("episode_number")
|
||||
val episodeNumber: Int
|
||||
)
|
@ -89,4 +89,20 @@
|
||||
app:backgroundTint="@color/exo_white"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_skip_op"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_marginBottom="70dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/skip_opening"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="@color/exo_white"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
</FrameLayout>
|
@ -69,6 +69,7 @@
|
||||
<string name="play_pause">Abspielen/Pause</string>
|
||||
<string name="forward_10">10 Sekunden vorwärts</string>
|
||||
<string name="next_episode">Nächste Folge</string>
|
||||
<string name="skip_opening">Intro überspringen</string>
|
||||
<string name="language">Sprache</string>
|
||||
<string name="episodes">Folgen</string>
|
||||
<string name="episode">Folge</string>
|
||||
|
@ -88,6 +88,7 @@
|
||||
<string name="rwd_10_s" translatable="false">- 10 s</string>
|
||||
<string name="fwd_10_s" translatable="false">+ 10 s</string>
|
||||
<string name="next_episode">Next Episode</string>
|
||||
<string name="skip_opening">Skip Opening</string>
|
||||
<string name="time_min_sec" translatable="false">%1$02d:%2$02d</string>
|
||||
<string name="time_hour_min_sec" translatable="false">%1$d:%2$02d:%3$02d</string>
|
||||
<string name="language">Language</string>
|
||||
|
@ -1,12 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.5.20"
|
||||
ext.kotlin_version = "1.5.21"
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.2.2'
|
||||
classpath 'com.android.tools.build:gradle:7.0.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
Loading…
Reference in New Issue
Block a user