improve media parsing / loadStreams()
* fix #20, return 0 as episode number on NumberFormatException * don't crash if a episode can not be parsed * update material components: 1.3.0-alpha04 -> 1.3.0-beta01
This commit is contained in:
parent
8fc2d69eb8
commit
8f60a30d61
|
@ -51,7 +51,7 @@ dependencies {
|
||||||
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
|
|
||||||
implementation 'com.google.android.material:material:1.3.0-alpha04'
|
implementation 'com.google.android.material:material:1.3.0-beta01'
|
||||||
implementation 'com.google.code.gson:gson:2.8.6'
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.12.2'
|
implementation 'com.google.android.exoplayer:exoplayer-core:2.12.2'
|
||||||
implementation 'com.google.android.exoplayer:exoplayer-hls:2.12.2'
|
implementation 'com.google.android.exoplayer:exoplayer-hls:2.12.2'
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.mosad.teapod.preferences.EncryptedPreferences
|
||||||
import org.mosad.teapod.util.*
|
import org.mosad.teapod.util.*
|
||||||
import org.mosad.teapod.util.DataTypes.MediaType
|
import org.mosad.teapod.util.DataTypes.MediaType
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.NumberFormatException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
@ -293,49 +294,42 @@ object AoDParser {
|
||||||
val secondaryPlaylist = parsePlaylistAsync(secondary)
|
val secondaryPlaylist = parsePlaylistAsync(secondary)
|
||||||
|
|
||||||
primaryPlaylist.await().playlist.forEach { ep ->
|
primaryPlaylist.await().playlist.forEach { ep ->
|
||||||
val epNumber = if (media.type == MediaType.TVSHOW) {
|
try {
|
||||||
ep.title.substringAfter(", Ep. ").toInt()
|
media.episodes.add(Episode(
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
media.episodes.add(
|
|
||||||
Episode(
|
|
||||||
id = ep.mediaid,
|
id = ep.mediaid,
|
||||||
priStreamUrl = ep.sources.first().file,
|
priStreamUrl = ep.sources.first().file,
|
||||||
posterUrl = ep.image,
|
posterUrl = ep.image,
|
||||||
title = ep.title,
|
title = ep.title,
|
||||||
description = ep.description,
|
description = ep.description,
|
||||||
number = epNumber
|
number = getNumberFromTitle(ep.title, media.type)
|
||||||
)
|
))
|
||||||
)
|
} catch (ex: Exception) {
|
||||||
|
Log.w(javaClass.name, "Could not parse episode information.", ex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Log.i(javaClass.name, "Loading primary playlist finished")
|
Log.i(javaClass.name, "Loading primary playlist finished")
|
||||||
|
|
||||||
secondaryPlaylist.await().playlist.forEach { ep ->
|
secondaryPlaylist.await().playlist.forEach { ep ->
|
||||||
|
try {
|
||||||
val episode = media.episodes.firstOrNull { it.id == ep.mediaid }
|
val episode = media.episodes.firstOrNull { it.id == ep.mediaid }
|
||||||
|
|
||||||
|
// if media contains already a episode with this id, add as secondary, else add as primary
|
||||||
if (episode != null) {
|
if (episode != null) {
|
||||||
episode.secStreamUrl = ep.sources.first().file
|
episode.secStreamUrl = ep.sources.first().file
|
||||||
episode.secStreamOmU = secondaryIsOmU
|
episode.secStreamOmU = secondaryIsOmU
|
||||||
} else {
|
} else {
|
||||||
val epNumber = if (media.type == MediaType.TVSHOW) {
|
media.episodes.add(Episode(
|
||||||
ep.title.substringAfter(", Ep. ").toInt()
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
media.episodes.add(
|
|
||||||
Episode(
|
|
||||||
id = ep.mediaid,
|
id = ep.mediaid,
|
||||||
secStreamUrl = ep.sources.first().file,
|
secStreamUrl = ep.sources.first().file,
|
||||||
secStreamOmU = secondaryIsOmU,
|
secStreamOmU = secondaryIsOmU,
|
||||||
posterUrl = ep.image,
|
posterUrl = ep.image,
|
||||||
title = ep.title,
|
title = ep.title,
|
||||||
description = ep.description,
|
description = ep.description,
|
||||||
number = epNumber
|
number = getNumberFromTitle(ep.title, media.type)
|
||||||
)
|
))
|
||||||
)
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Log.w(javaClass.name, "Could not parse episode information.", ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.i(javaClass.name, "Loading secondary playlist finished")
|
Log.i(javaClass.name, "Loading secondary playlist finished")
|
||||||
|
@ -416,4 +410,22 @@ object AoDParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the episode number from the title
|
||||||
|
* @param title the episode title, containing a number after "Ep."
|
||||||
|
* @param type the media type, if not TVSHOW, return 0
|
||||||
|
* @return the episode number, on NumberFormatException return 0
|
||||||
|
*/
|
||||||
|
private fun getNumberFromTitle(title: String, type: MediaType): Int {
|
||||||
|
return if (type == MediaType.TVSHOW) {
|
||||||
|
try {
|
||||||
|
title.substringAfter(", Ep. ").toInt()
|
||||||
|
} catch (nex: NumberFormatException) {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue