2021-12-05 00:42:56 +01:00
package org.mosad.teapod.parser.crunchyroll
2021-12-20 22:14:58 +01:00
import kotlinx.serialization.SerialName
2021-12-05 00:42:56 +01:00
import kotlinx.serialization.Serializable
2021-12-28 20:32:44 +01:00
import java.util.*
2021-12-05 00:42:56 +01:00
/ * *
* data classes for browse
* TODO make class names more clear / possibly overlapping for now
* /
enum class SortBy ( val str : String ) {
ALPHABETICAL ( " alphabetical " ) ,
NEWLY _ADDED ( " newly_added " ) ,
POPULARITY ( " popularity " )
}
2021-12-27 22:50:29 +01:00
/ * *
* Search data type
* /
@Serializable
data class SearchResult (
@SerialName ( " total " ) val total : Int ,
@SerialName ( " items " ) val items : List < SearchCollection >
)
@Serializable
data class SearchCollection (
@SerialName ( " type " ) val type : String ,
@SerialName ( " items " ) val items : List < Item >
)
val NoneSearchResult = SearchResult ( 0 , emptyList ( ) )
2021-12-05 00:42:56 +01:00
@Serializable
data class BrowseResult ( val total : Int , val items : List < Item > )
2021-12-27 22:50:29 +01:00
// the data class Item is used in browse and search
2021-12-28 20:32:44 +01:00
// TODO rename to MediaPanel
2021-12-05 00:42:56 +01:00
@Serializable
data class Item (
val id : String ,
val title : String ,
val type : String ,
val channel _id : String ,
val description : String ,
val images : Images
// TODO metadata etc.
)
2021-12-20 22:14:58 +01:00
val NoneItem = Item ( " " , " " , " " , " " , " " , Images ( listOf ( ) , listOf ( ) ) )
val NoneBrowseResult = BrowseResult ( 0 , listOf ( ) )
2021-12-05 00:42:56 +01:00
@Serializable
data class Images ( val poster _tall : List < List < Poster > > , val poster _wide : List < List < Poster > > )
// crunchyroll why?
@Serializable
2021-12-20 22:14:58 +01:00
data class Poster ( val height : Int , val width : Int , val source : String , val type : String )
/ * *
2021-12-27 22:50:29 +01:00
* Series data type
2021-12-20 22:14:58 +01:00
* /
@Serializable
data class Series (
val id : String ,
val title : String ,
val description : String ,
val images : Images
)
val NoneSeries = Series ( " " , " " , " " , Images ( listOf ( ) , listOf ( ) ) )
/ * *
* Seasons data type
* /
@Serializable
2021-12-28 20:32:44 +01:00
data class Seasons (
val total : Int ,
val items : List < Season >
) {
2021-12-29 19:36:33 +01:00
fun getPreferredSeason ( local : Locale ) : Season {
2021-12-28 20:32:44 +01:00
// try to get the the first seasons which matches the preferred local
items . forEach { season ->
if ( season . title . startsWith ( " ( ${local.language} ) " , true ) ) {
2021-12-29 19:36:33 +01:00
return season
2021-12-28 20:32:44 +01:00
}
}
// if there is no season with the preferred local, try to find a subbed season
items . forEach { season ->
if ( season . isSubbed ) {
2021-12-29 19:36:33 +01:00
return season
2021-12-28 20:32:44 +01:00
}
}
// if there is no preferred language season and no sub, use the first season
2021-12-29 19:36:33 +01:00
return items . first ( )
2021-12-28 20:32:44 +01:00
}
}
2021-12-20 22:14:58 +01:00
@Serializable
data class Season (
2021-12-28 20:32:44 +01:00
@SerialName ( " id " ) val id : String ,
@SerialName ( " title " ) val title : String ,
@SerialName ( " series_id " ) val seriesId : String ,
@SerialName ( " season_number " ) val seasonNumber : Int ,
@SerialName ( " is_subbed " ) val isSubbed : Boolean ,
@SerialName ( " is_dubbed " ) val isDubbed : Boolean ,
2021-12-20 22:14:58 +01:00
)
val NoneSeasons = Seasons ( 0 , listOf ( ) )
2021-12-29 19:36:33 +01:00
val NoneSeason = Season ( " " , " " , " " , 0 , false , false )
2021-12-20 22:14:58 +01:00
/ * *
* Episodes data type
* /
@Serializable
data class Episodes ( val total : Int , val items : List < Episode > )
@Serializable
data class Episode (
@SerialName ( " id " ) val id : String ,
@SerialName ( " title " ) val title : String ,
@SerialName ( " series_id " ) val seriesId : String ,
@SerialName ( " season_title " ) val seasonTitle : String ,
@SerialName ( " season_id " ) val seasonId : String ,
@SerialName ( " season_number " ) val seasonNumber : Int ,
@SerialName ( " episode " ) val episode : String ,
2021-12-28 20:32:44 +01:00
@SerialName ( " episode_number " ) val episodeNumber : Int ? = null ,
2021-12-20 22:14:58 +01:00
@SerialName ( " description " ) val description : String ,
2021-12-26 20:22:00 +01:00
@SerialName ( " next_episode_id " ) val nextEpisodeId : String ? = null , // default/nullable value since optional
@SerialName ( " next_episode_title " ) val nextEpisodeTitle : String ? = null , // default/nullable value since optional
2021-12-20 22:14:58 +01:00
@SerialName ( " is_subbed " ) val isSubbed : Boolean ,
@SerialName ( " is_dubbed " ) val isDubbed : Boolean ,
@SerialName ( " images " ) val images : Thumbnail ,
@SerialName ( " duration_ms " ) val durationMs : Int ,
@SerialName ( " playback " ) val playback : String ,
)
@Serializable
data class Thumbnail (
@SerialName ( " thumbnail " ) val thumbnail : List < List < Poster > >
)
val NoneEpisodes = Episodes ( 0 , listOf ( ) )
val NoneEpisode = Episode (
id = " " ,
title = " " ,
seriesId = " " ,
seasonId = " " ,
seasonTitle = " " ,
seasonNumber = 0 ,
episode = " " ,
episodeNumber = 0 ,
description = " " ,
nextEpisodeId = " " ,
nextEpisodeTitle = " " ,
isSubbed = false ,
isDubbed = false ,
images = Thumbnail ( listOf ( ) ) ,
durationMs = 0 ,
playback = " "
)
/ * *
* Playback / stream data type
* /
@Serializable
data class Playback (
@SerialName ( " audio_locale " ) val audioLocale : String ,
@SerialName ( " subtitles " ) val subtitles : Map < String , Subtitle > ,
@SerialName ( " streams " ) val streams : Streams ,
)
@Serializable
data class Subtitle (
@SerialName ( " locale " ) val locale : String ,
@SerialName ( " url " ) val url : String ,
@SerialName ( " format " ) val format : String ,
)
@Serializable
data class Streams (
@SerialName ( " adaptive_dash " ) val adaptive _dash : Map < String , Stream > ,
@SerialName ( " adaptive_hls " ) val adaptive _hls : Map < String , Stream > ,
@SerialName ( " download_hls " ) val download _hls : Map < String , Stream > ,
@SerialName ( " drm_adaptive_dash " ) val drm _adaptive _dash : Map < String , Stream > ,
@SerialName ( " drm_adaptive_hls " ) val drm _adaptive _hls : Map < String , Stream > ,
@SerialName ( " drm_download_hls " ) val drm _download _hls : Map < String , Stream > ,
@SerialName ( " trailer_dash " ) val trailer _dash : Map < String , Stream > ,
@SerialName ( " trailer_hls " ) val trailer _hls : Map < String , Stream > ,
@SerialName ( " vo_adaptive_dash " ) val vo _adaptive _dash : Map < String , Stream > ,
@SerialName ( " vo_adaptive_hls " ) val vo _adaptive _hls : Map < String , Stream > ,
@SerialName ( " vo_drm_adaptive_dash " ) val vo _drm _adaptive _dash : Map < String , Stream > ,
@SerialName ( " vo_drm_adaptive_hls " ) val vo _drm _adaptive _hls : Map < String , Stream > ,
)
@Serializable
data class Stream (
@SerialName ( " hardsub_locale " ) val hardsubLocale : String ,
@SerialName ( " url " ) val url : String ,
@SerialName ( " vcodec " ) val vcodec : String ,
)
val NonePlayback = Playback (
" " ,
mapOf ( ) ,
Streams (
mapOf ( ) , mapOf ( ) , mapOf ( ) , mapOf ( ) , mapOf ( ) , mapOf ( ) ,
mapOf ( ) , mapOf ( ) , mapOf ( ) , mapOf ( ) , mapOf ( ) , mapOf ( ) ,
)
)