Skip to content

Commit

Permalink
Dot stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
bskjon committed Nov 19, 2024
1 parent 9ecdcd8 commit 01df7ef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.iktdev.mediaprocessing.shared.common.parsing

import org.apache.kafka.common.protocol.types.Field.Str

class FileNameParser(val fileName: String) {
var cleanedFileName: String
Expand Down Expand Up @@ -122,7 +121,7 @@ class FileNameParser(val fileName: String) {
fun removeDot(input: String): String {
//var text = Regex("(?<=\\s)\\.|\\.(?=\\s)").replace(input, "")
//return Regex("\\.(?<!(Dr|Mr|Ms|Mrs|Lt|Capt|Prof|St|Ave)\\.)\\b").replace(text, " ")
return Regex("(?<!\\b(?:Dr|Mr|Ms|Mrs|Lt|Capt|Prof|St|Ave))\\.+(?=\\s|\\w)").replace(input, " ")
return Regex("(?<!\\b(?:Dr|Mr|Ms|Mrs|Lt|Capt|Prof|St|Ave))\\.").replace(input, " ")
}

fun removeInBetweenCharacters(text: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ object NameHelper {
val normalized = Normalizer.normalize(text, Normalizer.Form.NFC)
val result = normalized.replace("\\p{M}".toRegex(), "")
val cleaned = "[^A-Za-z0-9 -]".toRegex().replace(result, "")
return StringUtils.stripAccents(cleaned)
return StringUtils.stripAccents(cleaned).trim()
}

fun cleanup(input: String): String {
var cleaned = Regex("(?<=\\w)[_.](?=\\w)").replace(input, " ")
cleaned = Regexes.illegalCharacters.replace(cleaned, " - ")
cleaned = Regexes.trimWhiteSpaces.replace(cleaned, " ")
return NameHelper.normalize(cleaned)
return NameHelper.normalize(cleaned).trim()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class FileNameParserTest {

}

@Test
fun assertDotRemoval() {
val input = "Like.a.Potato.Chef.S01E01.Departure.\\u0026.Skills.1080p.Potato"
val parser = FileNameParser(input)
val result = parser.guessDesiredTitle()
assertThat(result).isEqualTo("Like a Potato Chef")
assertThat(parser.guessDesiredFileName()).isEqualTo("Like a Potato Chef S01E01 Departure \\u0026 Skills")
}

@Test
fun movieName() {
val inName = "Wicket.Wicker.Potato.4.2023.UHD.BluRay.2160p"
Expand Down Expand Up @@ -89,5 +98,4 @@ class FileNameParserTest {
val result = FileNameParser(input).guessDesiredTitle()
assertThat(result).isEmpty()
}

}

0 comments on commit 01df7ef

Please sign in to comment.