forked from recloudstream/cloudstream
[Bugfix] Re arrange Regex for Duration, fixing issue if inaccurate results. (#239)
This commit is contained in:
parent
6d13cf0b01
commit
56c79e3b6a
1 changed files with 19 additions and 15 deletions
|
@ -1139,21 +1139,8 @@ interface LoadResponse {
|
|||
|
||||
fun getDurationFromString(input: String?): Int? {
|
||||
val cleanInput = input?.trim()?.replace(" ", "") ?: return null
|
||||
Regex("([0-9]*)h.*?([0-9]*)m").find(cleanInput)?.groupValues?.let { values ->
|
||||
if (values.size == 3) {
|
||||
val hours = values[1].toIntOrNull()
|
||||
val minutes = values[2].toIntOrNull()
|
||||
if (minutes != null && hours != null) {
|
||||
return hours * 60 + minutes
|
||||
}
|
||||
}
|
||||
}
|
||||
Regex("([0-9]*)m").find(cleanInput)?.groupValues?.let { values ->
|
||||
if (values.size == 2) {
|
||||
return values[1].toIntOrNull()
|
||||
}
|
||||
}
|
||||
Regex("(\\s\\d+\\shr)|(\\s\\d+\\shour)|(\\s\\d+\\smin)|(\\s\\d+\\ssec)").findAll(input).let { values ->
|
||||
//Use first as sometimes the text passes on the 2 other Regex, but failed to provide accurate return value
|
||||
Regex("(\\d+\\shr)|(\\d+\\shour)|(\\d+\\smin)|(\\d+\\ssec)").findAll(input).let { values ->
|
||||
var seconds = 0
|
||||
values.forEach {
|
||||
val time_text = it.value
|
||||
|
@ -1174,6 +1161,23 @@ fun getDurationFromString(input: String?): Int? {
|
|||
return seconds / 60
|
||||
}
|
||||
}
|
||||
Regex("([0-9]*)h.*?([0-9]*)m").find(cleanInput)?.groupValues?.let { values ->
|
||||
if (values.size == 3) {
|
||||
val hours = values[1].toIntOrNull()
|
||||
val minutes = values[2].toIntOrNull()
|
||||
if (minutes != null && hours != null) {
|
||||
return hours * 60 + minutes
|
||||
}
|
||||
}
|
||||
}
|
||||
Regex("([0-9]*)m").find(cleanInput)?.groupValues?.let { values ->
|
||||
if (values.size == 2) {
|
||||
val return_value = values[1].toIntOrNull()
|
||||
if (return_value != null) {
|
||||
return return_value
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue