Skip to content

Commit

Permalink
feat: Add Jodel support (#462) (#463)
Browse files Browse the repository at this point in the history
* feat: Add Jodel support (#462)

* chore: Use alphabetic imports ordering

* chore: use KotlinX Serialization

---------

Co-authored-by: xyrolaith <18216850+xyrolaith@users.noreply.github.com>
Co-authored-by: Sven Jacobs <github@svenjacobs.com>
  • Loading branch information
3 people committed Sep 18, 2024
1 parent 3ba1901 commit 42f2ca2
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .idea/dictionaries/sven.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.svenjacobs.app.leon.core.domain.sanitizer.google.GoogleSearchSanitize
import com.svenjacobs.app.leon.core.domain.sanitizer.heise.HeiseSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.instagram.InstagramSanitizer
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.netflix.NetflixSanitizer
Expand Down Expand Up @@ -95,6 +96,7 @@ class ContainerInitializer : DistinctInitializer<Unit> {
HeiseSanitizer(),
InstagramSanitizer(),
JdoqocySanitizer(),
JodelSanitizer(),
LazadaSanitizer(),
LinkSynergySanitizer(),
NetflixSanitizer(),
Expand Down
1 change: 1 addition & 0 deletions core-domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ android {

dependencies {
api(libs.kotlinx.collections.immutable)
api(libs.kotlinx.serialization.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.svenjacobs.app.leon.core.domain.sanitizer.jodel

import android.content.Context
import com.svenjacobs.app.leon.core.common.url.decodeUrl
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
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlinx.serialization.json.Json

class JodelSanitizer : Sanitizer {
override val id = SanitizerId("jodel")

override fun getMetadata(context: Context) = Sanitizer.Metadata(
name = context.getString(R.string.sanitizer_jodel_name),
)

@OptIn(ExperimentalEncodingApi::class)
override fun invoke(input: String): String {
val encoded = URL_REGEX.find(input)?.groupValues?.getOrNull(1) ?: return input
val base64Data = decodeUrl(encoded)
val jsonString = Base64.Default.decode(base64Data)
val jsonMap = Json.decodeFromString<Map<String, String>>(jsonString.decodeToString())

return jsonMap["\$android_url"] ?: input
}

override fun matchesDomain(input: String) = URL_REGEX.containsMatchIn(input)

private companion object {
private val URL_REGEX = Regex("^https?://shared\\.jodel\\.com/a/key_live_.*&data=([^?&]*)")
}
}
1 change: 1 addition & 0 deletions core-domain/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="sanitizer_heise" translatable="false">heise online</string>
<string name="sanitizer_instagram_name" translatable="false">Instagram</string>
<string name="sanitizer_jdoqocy_name" translatable="false">Jdoqocy</string>
<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_netflix_name" translatable="false">Netflix</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.jodel

import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe

class JodelSanitizerTest :
WordSpec(
{

"invoke" should {

"extract Jodel sharing URL" {
val sanitizer = JodelSanitizer()
val result = sanitizer(
"http://shared.jodel.com/a/key_live_abZZZZgPxyz82xxxxAAAAdefghi4YYY1" +
"?%24identity_id=123456789012345678&feature=shared_post&campaign=image" +
"_DE_FrontPage&type=0&duration=0&source=android&data=eyIkY2Fub25pY2FsX" +
"2lkZW50aWZpZXIiOiJzYWpcL2JhZGMwZmZlZWJhZGMwZmZlZTAxMjM0NSIsIiRwdWJsaW" +
"NseV9pbmRleGFibGUiOiJ0cnVlIiwicG9zdElkIjoiYmFkYzBmZmVlYmFkYzBmZmVlMDE" +
"yMzQ1IiwiJGRlc2t0b3BfdXJsIjoiaHR0cHM6XC9cL3NoYXJlLmpvZGVsLmNvbVwvcG9z" +
"dD9wb3N0SWQ9YmFkYzBmZmVlYmFkYzBmZmVlMDEyMzQ1IiwicmVmZXJyZXJfaWQiOiJhY" +
"mNkZWYwMTIzNDU2Nzg5ZGVhZGMwZGUiLCIkYW5kcm9pZF91cmwiOiJodHRwczpcL1wvc2" +
"hhcmUuam9kZWwuY29tXC9wb3N0P3Bvc3RJZD1iYWRjMGZmZWViYWRjMGZmZWUwMTIzNDU" +
"iLCIkaW9zX3VybCI6Imh0dHBzOlwvXC9zaGFyZS5qb2RlbC5jb21cL3Bvc3Q%2FcG9zdE" +
"lkPWJhZGMwZmZlZWJhZGMwZmZlZTAxMjM0NSJ9?channel=copy",
)

result shouldBe "https://share.jodel.com/post?postId=badc0ffeebadc0ffee012345"
}
}
},
)
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-navigation-compose = "androidx.navigation:navigation-compose:2.8.0"
androidx-startup-runtime = "androidx.startup:startup-runtime:1.1.1"
compose-gradle-plugin = { module = "org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin", version.ref = "kotlin" }
facebook-stetho = "com.facebook.stetho:stetho:1.6.0"
jakewharton-timber = "com.jakewharton.timber:timber:5.0.1"
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
compose-gradle-plugin = { module = "org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin", version.ref = "kotlin" }
kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8" }
kotlinx-collections-immutable = "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.8"
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
kotlinx-serialization-json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2"
mikepenz-aboutlibraries-compose-m3 = { module = "com.mikepenz:aboutlibraries-compose-m3", version.ref = "mikepenz-aboutlibraries" }
mikepenz-aboutlibraries-gradle-plugin = { module = "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin", version.ref = "mikepenz-aboutlibraries" }
mockk = "io.mockk:mockk:1.13.12"
Expand Down

0 comments on commit 42f2ca2

Please sign in to comment.