diff --git a/app/src/main/java/org/mosad/teapod/parser/crunchyroll/Crunchyroll.kt b/app/src/main/java/org/mosad/teapod/parser/crunchyroll/Crunchyroll.kt index 10693b7..aae91c1 100644 --- a/app/src/main/java/org/mosad/teapod/parser/crunchyroll/Crunchyroll.kt +++ b/app/src/main/java/org/mosad/teapod/parser/crunchyroll/Crunchyroll.kt @@ -34,7 +34,6 @@ import io.ktor.http.* import io.ktor.serialization.* import io.ktor.serialization.kotlinx.json.* import kotlinx.coroutines.* -import kotlinx.serialization.SerializationException import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject @@ -149,7 +148,7 @@ object Crunchyroll { } return@coroutineScope (Dispatchers.IO) { - val response: T = client.request(url) { + val response = client.request(url) { method = httpMethod header("Authorization", "${token.tokenType} ${token.accessToken}") params.forEach { @@ -161,9 +160,9 @@ object Crunchyroll { setBody(bodyObject) contentType(ContentType.Application.Json) } - }.body() + } - response + response.body() } } @@ -389,7 +388,7 @@ object Crunchyroll { return try { requestGet(seriesEndpoint, parameters) } catch (ex: Exception) { - Log.e(TAG, "Exception in series().", ex) + Log.e(TAG, "Exception in series() for id $seriesId.", ex) NoneSeries } } @@ -418,7 +417,7 @@ object Crunchyroll { Log.e(TAG, "JsonConvertException in upNextSeries() with seriesId=$seriesId", ex) NoneUpNextSeriesList } catch (ex: Exception) { - Log.e(TAG, "Exception in upNextSeries().", ex) + Log.e(TAG, "Exception in upNextSeries() for seriesId $seriesId.", ex) NoneUpNextSeriesList } } @@ -439,7 +438,7 @@ object Crunchyroll { return try { requestGet(seasonsEndpoint, parameters) } catch (ex: Exception) { - Log.e(TAG, "Exception in seasons().", ex) + Log.e(TAG, "Exception in seasons() for seriesId $seriesId.", ex) NoneSeasons } } @@ -460,7 +459,7 @@ object Crunchyroll { return try { requestGet(episodesEndpoint, parameters) } catch (ex: Exception) { - Log.e(TAG, "Exception in episodes().", ex) + Log.e(TAG, "Exception in episodes() for seasonId $seasonId.", ex) NoneEpisodes } } @@ -480,7 +479,7 @@ object Crunchyroll { return try { requestGet(url, parameters) } catch (ex: Exception) { - Log.e(TAG, "Exception in streams().", ex) + Log.e(TAG, "Exception in streams() with url $url.", ex) NoneStreams } } @@ -512,7 +511,7 @@ object Crunchyroll { (requestGet(watchlistSeriesEndpoint, parameters) as Collection2) .total == 1 } catch (ex: Exception) { - Log.e(TAG, "Exception in isWatchlist() with seriesId = $seriesId", ex) + Log.e(TAG, "Exception in isWatchlist() with seriesId $seriesId", ex) false } } @@ -536,7 +535,7 @@ object Crunchyroll { try { requestPost(watchlistPostEndpoint, parameters, json) } catch (ex: Exception) { - Log.e(TAG, "Exception in postWatchlist() with seriesId = $seriesId", ex) + Log.e(TAG, "Exception in postWatchlist() with seriesId $seriesId", ex) } } @@ -555,7 +554,7 @@ object Crunchyroll { try { requestDelete(watchlistDeleteEndpoint, parameters) } catch (ex: Exception) { - Log.e(TAG, "Exception in deleteWatchlist() with seriesId = $seriesId", ex) + Log.e(TAG, "Exception in deleteWatchlist() with seriesId $seriesId", ex) } } @@ -575,7 +574,6 @@ object Crunchyroll { "locale" to Preferences.preferredSubtitleLocale.toLanguageTag() ) - return try { requestGet(playheadsEndpoint, parameters) } catch (ex: Exception) { diff --git a/app/src/main/java/org/mosad/teapod/parser/crunchyroll/DataTypes.kt b/app/src/main/java/org/mosad/teapod/parser/crunchyroll/DataTypes.kt index a03c366..cae9899 100644 --- a/app/src/main/java/org/mosad/teapod/parser/crunchyroll/DataTypes.kt +++ b/app/src/main/java/org/mosad/teapod/parser/crunchyroll/DataTypes.kt @@ -302,7 +302,7 @@ data class Episode( @SerialName("is_dubbed") val isDubbed: Boolean, @SerialName("images") val images: Thumbnail, @SerialName("duration_ms") val durationMs: Int, - @SerialName("versions") val versions: List, + @SerialName("versions") val versions: List? = null, @SerialName("streams_link") val streamsLink: String, ) diff --git a/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt b/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt index 55ff137..24bafa0 100644 --- a/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt +++ b/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt @@ -157,9 +157,9 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application) if (newAudioLocale != currentAudioLocale) { currentAudioLocale = newAudioLocale - currentVersion = currentEpisode.versions.firstOrNull { + currentVersion = currentEpisode.versions?.firstOrNull { it.audioLocale == currentAudioLocale.toLanguageTag() - } ?: currentEpisode.versions.first() + } ?: currentEpisode.versions?.first() ?: NoneVersion viewModelScope.launch { currentStreams = Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID) @@ -223,14 +223,18 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application) joinAll( viewModelScope.launch(Dispatchers.IO) { currentVersion = if (Preferences.preferSubbed) { - currentEpisode.versions.first { it.original } + currentEpisode.versions?.first { it.original } ?: NoneVersion } else { - currentEpisode.versions - .firstOrNull { it.audioLocale == currentAudioLocale.toLanguageTag() } - ?: currentEpisode.versions.first() + currentEpisode.versions?.firstOrNull { it.audioLocale == currentAudioLocale.toLanguageTag() } + ?: currentEpisode.versions?.first() ?: NoneVersion } - currentStreams = Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID) + // get the current streams object, if no version is set, use streamsLink + currentStreams = if (currentVersion != NoneVersion) { + Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID) + } else { + Crunchyroll.streams(currentEpisode.streamsLink) + } Log.d(classTag, currentVersion.toString()) }, viewModelScope.launch(Dispatchers.IO) { diff --git a/app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/LanguageSettingsDialogFragment.kt b/app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/LanguageSettingsDialogFragment.kt index ca68b77..e413c6d 100644 --- a/app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/LanguageSettingsDialogFragment.kt +++ b/app/src/main/java/org/mosad/teapod/ui/activity/player/fragment/LanguageSettingsDialogFragment.kt @@ -64,7 +64,7 @@ class LanguageSettingsDialogFragment : DialogFragment() { val currentAudioLocal = Locale.forLanguageTag(model.currentVersion.audioLocale) var selectedAudioView: TextView? = null - model.currentEpisode.versions.forEach { version -> + model.currentEpisode.versions?.forEach { version -> val locale = Locale.forLanguageTag(version.audioLocale) val audioView = addLanguage(binding.linearAudioLanguages, locale) { v -> selectedAudioLocale = locale diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index 7174db9..1422a5f 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -8,7 +8,8 @@ + android:layout_height="match_parent" + android:scrollbars="none"> - + android:text="@string/info_about_desc" /> diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index ff9a700..f2129c9 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -9,7 +9,8 @@ + android:layout_height="match_parent" + android:scrollbars="none">