Skip to content

Commit

Permalink
Add MyDealz sanitizer as per #358
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbreuer committed Oct 25, 2024
1 parent 51074ed commit 2a27cbd
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,6 +104,8 @@ class ContainerInitializer : DistinctInitializer<Unit> {
JodelSanitizer(),
LazadaSanitizer(),
LinkSynergySanitizer(),
MyDealzParametersSanitizer(),
MyDealzRedirectsSanitizer(),
NetflixSanitizer(),
NewEggSanitizer(),
PearlSanitizer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
)
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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)
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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/(.+)\$")
}
}
2 changes: 2 additions & 0 deletions core-domain/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<string name="sanitizer_jodel_name" translatable="false">Jodel</string>
<string name="sanitizer_lazada" translatable="false">Lazada</string>
<string name="sanitizer_linksynergy_name" translatable="false">LinkSynergy</string>
<string name="sanitizer_mydealz_paremeters_name" translatable="false">MyDealz Parameters</string>
<string name="sanitizer_mydealz_redirects_name" translatable="false">MyDealz Redirects</string>
<string name="sanitizer_netflix_name" translatable="false">Netflix</string>
<string name="sanitizer_newegg_name" translatable="false">NewEgg</string>
<string name="sanitizer_pearl" translatable="false">Pearl</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

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"
}
}
},
)
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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"
}
}
},
)

0 comments on commit 2a27cbd

Please sign in to comment.