Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Kotlin Based Android library for fetching metadata of URL effortlessly

License

NotificationsYou must be signed in to change notification settings

zeeshanali-k/MetaProbe

Repository files navigation

Maven Central

MetaProbe

A simple Android Kotlin library for fetching link details like Title, Description, Icon and OG Image effortlessly based onKtor for fetching HTML from provided URL andJsoup for parsing Meta Data. The usecase of this library could be seen in Social Media and Messaging Apps.

For Kotlin Multiplatform CheckMetaProbeKMP

Usage

A sample usage is also provided on code along with the design most social media apps use.

Add following dependency to your module level gradle file and make suremavenCentral() is added in repositories in yoursettings.gradle file.

Forbuild.gradle.kts:

implementation("tech.dev-scion:metaprobe:1.0.3")

Forbuild.gradle:

implementation"tech.dev-scion:metaprobe:1.0.3"

You can use this library in Coroutines or via Callback method (without managing any Coroutine or Thread).

With Coroutine Suspend Method:

MetaProbe(url)            .apply {                setClient(HttpClient(Android) {                        engine {                            connectTimeout=100_000                            socketTimeout=100_000                        }                    }                )            }            .probeLink()            .fold(                onSuccess= {                    isLoading.value=false                    probedData.value= it                },                onFailure= {                    isLoading.value=false                },            )

Fold here is just an Convinience Extension Method of KotlinResult Class, so you can also use MetaProbe without it.For Callback Method Use this code:

MetaProbe(url)  .probeLink(object:OnMetaDataProbed {overridefunonMetaDataProbed(pb:Result<ProbedData>) {        isLoading.value=falseLog.d(TAG,"onMetaDataProbed:$pb")Log.d(TAG,"onMetaDataProbed:${pb.getOrNull()?.title}")Log.d(TAG,"onMetaDataProbed:${pb.getOrNull()?.icon}")Log.d(TAG,"onMetaDataProbed:${pb.getOrNull()?.description}")        probedData.value= pb.getOrNull()      }  })

You can removesetClient as it is not necessary and only needed when you want to cutomise your HTTPClient, for example for logging etc.

ProbedData is the class returned in result which contains the actual values of Title, Description, Icon and OGImage.


[8]ページ先頭

©2009-2025 Movatter.jp