Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MyDealz sanitizer as per #358 #491

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_parameters_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-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<string name="sanitizer_aol_search_name">AOL Suche</string>
<string name="sanitizer_empty_parameters_name">Leere Parameter</string>
<string name="sanitizer_google_search_name">Google Suche</string>
<string name="sanitizer_mydealz_parameters_name">MyDealz Parameter</string>
<string name="sanitizer_mydealz_redirects_name">MyDealz Weiterleitungen</string>
<string name="sanitizer_yahoo_search_name">Yahoo Suche</string>
<string name="sanitizer_youtube_redirect_name">YouTube Weiterleitung</string>
</resources>
4 changes: 3 additions & 1 deletion core-domain/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<string name="sanitizer_aol_search_name">AOL Search</string> <!-- TODO: translate -->
<string name="sanitizer_empty_parameters_name">Пустые параметры</string>
<string name="sanitizer_google_search_name">Google Search</string> <!-- TODO: translate -->
<string name="sanitizer_mydealz_parameters_name">MyDealz Parameters</string>
<string name="sanitizer_mydealz_redirects_name">MyDealz Redirects</string> <!-- TODO: translate -->
<string name="sanitizer_yahoo_search_name">Yahoo Search</string> <!-- TODO: translate -->
<string name="sanitizer_youtube_redirect_name">YouTube Redirect</string> <!-- TODO: translate -->
<string name="sanitizer_youtube_redirect_name">YouTube Redirect</string>
</resources>
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_parameters_name">MyDealz Parameters</string>
<string name="sanitizer_mydealz_redirects_name">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"
}
}
},
)