From a8f3d18c2eca4e284a2c00b4d4558fc7760f23c9 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Sat, 19 Nov 2022 18:53:34 +0800 Subject: [PATCH 1/2] [Feature] Get duration from string in format of '00 hr 00 min 00 sec', in any combination (#215) --- .../com/lagradost/cloudstream3/MainAPI.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 5c9f3071..95d1faaa 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -1153,6 +1153,27 @@ fun getDurationFromString(input: String?): Int? { 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 } From 9bca7a0780e69f1065ffb723de934c1f470cdf1c Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Mon, 21 Nov 2022 15:32:32 +0800 Subject: [PATCH 2/2] Fix duration regex, returning null on first checker (#218) --- app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 95d1faaa..e8ad476a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -1143,9 +1143,9 @@ fun getDurationFromString(input: String?): Int? { if (values.size == 3) { val hours = values[1].toIntOrNull() val minutes = values[2].toIntOrNull() - return if (minutes != null && hours != null) { - hours * 60 + minutes - } else null + if (minutes != null && hours != null) { + return hours * 60 + minutes + } } } Regex("([0-9]*)m").find(cleanInput)?.groupValues?.let { values ->