forked from recloudstream/cloudstream
[Feature] Get duration from string in format of '00 hr 00 min 00 sec', in any combination (#215)
This commit is contained in:
parent
263f74fb9c
commit
a8f3d18c2e
1 changed files with 21 additions and 0 deletions
|
@ -1153,6 +1153,27 @@ fun getDurationFromString(input: String?): Int? {
|
||||||
return values[1].toIntOrNull()
|
return values[1].toIntOrNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Regex("(\\s\\d+\\shr)|(\\s\\d+\\shour)|(\\s\\d+\\smin)|(\\s\\d+\\ssec)").findAll(input).let { values ->
|
||||||
|
var seconds = 0
|
||||||
|
values.forEach {
|
||||||
|
val time_text = it.value
|
||||||
|
if (time_text.isNotBlank()) {
|
||||||
|
val time = time_text.filter { s -> s.isDigit() }.trim().toInt()
|
||||||
|
val scale = time_text.filter { s -> !s.isDigit() }.trim()
|
||||||
|
//println("Scale: $scale")
|
||||||
|
val timeval = when (scale) {
|
||||||
|
"hr", "hour" -> time * 60 * 60
|
||||||
|
"min" -> time * 60
|
||||||
|
"sec" -> time
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
seconds += timeval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (seconds > 0) {
|
||||||
|
return seconds / 60
|
||||||
|
}
|
||||||
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue