Skip to content

Commit

Permalink
feat: Add Jodel support (svenjacobs#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyrolaith committed Sep 17, 2024
1 parent 3ba1901 commit 0aafbff
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
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
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 kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
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 org.json.JSONObject

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 jsonObject = JSONObject(jsonString.decodeToString())
val url = jsonObject.getString("\$android_url")
return url
}

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

0 comments on commit 0aafbff

Please sign in to comment.