This commit is contained in:
Brage 2023-07-28 01:40:42 +02:00
parent d9c8cab1fe
commit b38b6b83dd
3 changed files with 27 additions and 7 deletions

View File

@ -22,16 +22,18 @@ class FileNameDeterminate(val title: String, val sanitizedName: String, val ctyp
private fun determineMovieFileName(): MovieInfo? {
val movieEx = MovieEx(title, sanitizedName)
val result = when {
val stripped = when {
movieEx.isDefinedWithYear() != null -> sanitizedName.replace(movieEx.isDefinedWithYear()!!, "").trim()
movieEx.doesContainMovieKeywords() -> sanitizedName.replace(Regex("(?i)\\s*\\(\\s*movie\\s*\\)\\s*"), "").trim()
else -> title
}
return MovieInfo(title, result)
val nonResolutioned = movieEx.removeResolutionAndBeyond(stripped) ?: stripped
return MovieInfo(cleanup(nonResolutioned), cleanup(nonResolutioned))
}
private fun determineSerieFileName(): EpisodeInfo? {
val serieEx = SerieEx(title, sanitizedName)
val (season, episode) = serieEx.findSeasonAndEpisode(sanitizedName)
val episodeNumberSingle = serieEx.findEpisodeNumber()
@ -69,10 +71,20 @@ class FileNameDeterminate(val title: String, val sanitizedName: String, val ctyp
}
}
private fun cleanup(input: String): String {
val cleaned = Regex("(?<=\\w)[_.](?=\\w)").replace(input, " ")
return Regex("\\s{2,}").replace(cleaned, " ")
}
open internal class Base(val title: String, val sanitizedName: String) {
fun getMatch(regex: String): String? {
return Regex(regex, RegexOption.IGNORE_CASE).find(sanitizedName)?.value
}
fun removeResolutionAndBeyond(input: String): String? {
val removalValue = Regex("(i?)([0-9].*[pk]|[ ._-]+[UHD]+[ ._-])").find(input)?.value ?: return null
return input.substring(0, input.indexOf(removalValue))
}
}
internal class MovieEx(title: String, sanitizedName: String) : Base(title, sanitizedName) {

View File

@ -31,20 +31,19 @@ class FileWatcher: FileWatcherEvents {
val queue = FileWatcherQueue()
val watcherChannel = CommonConfig.incomingContent?.asWatchChannel()
val watcherChannel = CommonConfig.incomingContent.asWatchChannel()
init {
Coroutines.io().launch {
if (watcherChannel == null) {
logger.error { "Can't start watcherChannel on null!" }
}
watcherChannel?.consumeEach {
watcherChannel.consumeEach {
when (it.kind) {
KWatchEvent.Kind.Deleted -> {
queue.removeFromQueue(it.file, this@FileWatcher::onFileRemoved)
}
KWatchEvent.Kind.Created, KWatchEvent.Kind.Initialized -> {
queue.addToQueue(it.file, this@FileWatcher::onFilePending, this@FileWatcher::onFileAvailable)
}
else -> {
logger.info { "Ignoring event kind: ${it.kind.name} for file ${it.file.name}" }
}

View File

@ -58,6 +58,15 @@ class FileNameDeterminateTest {
assertThat(fileNameDeterminate.getDeterminedVideoInfo()?.fullName).isEqualTo(namedTestData.expected)
}
@Test
fun testWildStuff() {
val namedTestData = TestData("The Potato man", "The.Potato.man.2023.1080p.L950XL.x265-WIN10")
val fileNameDeterminate = FileNameDeterminate(
namedTestData.input, namedTestData.input, FileNameDeterminate.ContentType.UNDEFINED
)
assertThat(fileNameDeterminate.getDeterminedVideoInfo()?.fullName).isEqualTo(namedTestData.expected)
}
companion object {
@JvmStatic
fun serieTestCases(): List<Named<TestData>> {