diff --git a/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt b/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt index ce09677c..62e0ddca 100644 --- a/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt +++ b/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt @@ -45,6 +45,8 @@ import com.svenjacobs.app.leon.core.domain.sanitizer.jdoqocy.JdoqocySanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.jodel.JodelSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.lazada.LazadaSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.linksynergy.LinkSynergySanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.mydealz.MyDealzParametersSanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.mydealz.MyDealzRedirectsSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.netflix.NetflixSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.newegg.NewEggSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.pearl.PearlSanitizer @@ -102,6 +104,8 @@ class ContainerInitializer : DistinctInitializer { JodelSanitizer(), LazadaSanitizer(), LinkSynergySanitizer(), + MyDealzParametersSanitizer(), + MyDealzRedirectsSanitizer(), NetflixSanitizer(), NewEggSanitizer(), PearlSanitizer(), diff --git a/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzDomains.kt b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzDomains.kt new file mode 100644 index 00000000..df23702c --- /dev/null +++ b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzDomains.kt @@ -0,0 +1,12 @@ +package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz + +internal class MyDealzDomains { + companion object { + internal val DOMAINS_REGEX = Regex( + "www\\.mydealz\\.de|mydealz\\.de|" + + "chollometro\\.com|dealabs\\.com|desidime\\.com|hotukdeals\\.com|nl\\.pepper\\.com|" + + "pepper\\.it|pepper\\.pl|pepper\\.ru|promodescuentos\\.com|pelando\\.com\\.br|" + + "preisjaeger\\.at", + ) + } +} diff --git a/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanitizer.kt b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanitizer.kt new file mode 100644 index 00000000..8692c43f --- /dev/null +++ b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanitizer.kt @@ -0,0 +1,40 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2024 Sven Jacobs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz + +import android.content.Context +import com.svenjacobs.app.leon.core.common.regex.RegexFactory +import com.svenjacobs.app.leon.core.domain.R +import com.svenjacobs.app.leon.core.domain.sanitizer.RegexSanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.Sanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId + +class MyDealzParametersSanitizer : + RegexSanitizer( + RegexFactory.AllParameters, + ) { + + override val id = SanitizerId("mydealz_parameters") + + override fun getMetadata(context: Context) = Sanitizer.Metadata( + name = context.getString(R.string.sanitizer_mydealz_paremeters_name), + ) + + override fun matchesDomain(input: String) = MyDealzDomains.DOMAINS_REGEX.containsMatchIn(input) +} diff --git a/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanitizer.kt b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanitizer.kt new file mode 100644 index 00000000..43565de7 --- /dev/null +++ b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanitizer.kt @@ -0,0 +1,49 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2022 Sven Jacobs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz + +import android.content.Context +import com.svenjacobs.app.leon.core.domain.R +import com.svenjacobs.app.leon.core.domain.sanitizer.Sanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId + +class MyDealzRedirectsSanitizer : Sanitizer { + + override val id = SanitizerId("mydealz_redirects") + + override fun getMetadata(context: Context) = Sanitizer.Metadata( + name = context.getString(R.string.sanitizer_mydealz_redirects_name), + ) + + override fun matchesDomain(input: String) = MyDealzDomains.DOMAINS_REGEX.containsMatchIn(input) + + override fun invoke(input: String): String { + val groupValues = DEAL_REGEX.matchEntire(input)?.groupValues + ?: return input // URL is not in redirect format, pass through + val host = groupValues.getOrNull(1) + ?: throw IllegalArgumentException("Could not extract host from MyDealz URL") + val deal = groupValues.getOrNull(2) + ?: throw IllegalArgumentException("Could not extract deal from MyDealz URL") + return "https://$host/deals/a-$deal" + } + + private companion object { + private val DEAL_REGEX = Regex("https://([^/]+)/share-deal-from-app/(.+)\$") + } +} diff --git a/core-domain/src/main/res/values/strings.xml b/core-domain/src/main/res/values/strings.xml index bda0053b..074e3638 100644 --- a/core-domain/src/main/res/values/strings.xml +++ b/core-domain/src/main/res/values/strings.xml @@ -42,6 +42,8 @@ Jodel Lazada LinkSynergy + MyDealz Parameters + MyDealz Redirects Netflix NewEgg Pearl diff --git a/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanizierTest.kt b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanizierTest.kt new file mode 100644 index 00000000..c27f250d --- /dev/null +++ b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanizierTest.kt @@ -0,0 +1,37 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2023 Sven Jacobs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz + +import io.kotest.core.spec.style.WordSpec +import io.kotest.matchers.shouldBe + +class MyDealzParametersSanizierTest : + WordSpec( + { + + "invoke" should { + + "convert www.mydealz.de app URLs (with ad redirect) into base/direct URLs" { + val sanitizer = MyDealzParametersSanitizer() + val result = sanitizer("https://www.mydealz.de/diskussion/gratis-adidas-fussball-trikot-2383743?pprmrkntfctnsrd=123456789&UATypeId=18") + result shouldBe "https://www.mydealz.de/diskussion/gratis-adidas-fussball-trikot-2383743" + } + } + }, + ) diff --git a/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanizierTest.kt b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanizierTest.kt new file mode 100644 index 00000000..63ae2021 --- /dev/null +++ b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanizierTest.kt @@ -0,0 +1,49 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2023 Sven Jacobs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz + +import io.kotest.core.spec.style.WordSpec +import io.kotest.matchers.shouldBe + +class MyDealzRedirectsSanizierTest : + WordSpec( + { + + "invoke" should { + + "convert www.mydealz.de app URLs (with ad redirect) into base/direct URLs" { + val sanitizer = MyDealzRedirectsSanitizer() + val result = sanitizer("https://www.mydealz.de/share-deal-from-app/2117879") + result shouldBe "https://www.mydealz.de/deals/a-2117879" + } + + "convert mydealz.de app URLs (with ad redirect) into base/direct URLs" { + val sanitizer = MyDealzRedirectsSanitizer() + val result = sanitizer("https://mydealz.de/share-deal-from-app/2117879") + result shouldBe "https://mydealz.de/deals/a-2117879" + } + + "convert preisjaeger.at app URLs (with ad redirect) into base/direct URLs" { + val sanitizer = MyDealzRedirectsSanitizer() + val result = sanitizer("https://preisjaeger.at/share-deal-from-app/2117879") + result shouldBe "https://preisjaeger.at/deals/a-2117879" + } + } + }, + )