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

WIP: telegram #130

Merged
merged 1 commit into from
Mar 1, 2021
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Current list of implemented sources:
- [Twitter](https://twitter.com)
- [Youtube](https://youtube.com)
- [TikTok](https://tiktok.com)
- [Telegram](https://t.me)
- [Twitch](https://twitch.tv)
- [Reddit](https://reddit.com)
- [9GAG](https://9gag.com)
Expand Down Expand Up @@ -157,6 +158,7 @@ As mentioned before, the provider implementation list is:
- [TwitterSkraper](skrapers/src/main/kotlin/ru/sokomishalov/skraper/provider/twitter/TwitterSkraper.kt)
- [YoutubeSkraper](skrapers/src/main/kotlin/ru/sokomishalov/skraper/provider/youtube/YoutubeSkraper.kt)
- [TikTokSkraper](skrapers/src/main/kotlin/ru/sokomishalov/skraper/provider/tiktok/TikTokSkraper.kt)
- [TelegramSkraper](skrapers/src/main/kotlin/ru/sokomishalov/skraper/provider/telegram/TelegramSkraper.kt)
- [TwitchSkraper](skrapers/src/main/kotlin/ru/sokomishalov/skraper/provider/twitch/TwitchSkraper.kt)
- [RedditSkraper](skrapers/src/main/kotlin/ru/sokomishalov/skraper/provider/reddit/RedditSkraper.kt)
- [NinegagSkraper](skrapers/src/main/kotlin/ru/sokomishalov/skraper/provider/ninegag/NinegagSkraper.kt)
Expand Down
2 changes: 0 additions & 2 deletions TODO.md

This file was deleted.

2 changes: 2 additions & 0 deletions skrapers/src/main/kotlin/ru/sokomishalov/skraper/Skrapers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ru.sokomishalov.skraper.provider.tumblr.TumblrSkraper
import ru.sokomishalov.skraper.provider.twitch.TwitchSkraper
import ru.sokomishalov.skraper.provider.twitter.TwitterSkraper
import ru.sokomishalov.skraper.provider.vk.VkSkraper
import ru.sokomishalov.skraper.provider.telegram.TelegramSkraper
import ru.sokomishalov.skraper.provider.youtube.YoutubeSkraper
import java.io.File

Expand Down Expand Up @@ -175,6 +176,7 @@ object Skrapers {
TwitterSkraper(client),
YoutubeSkraper(client),
TikTokSkraper(client),
TelegramSkraper(client),
TwitchSkraper(client),
RedditSkraper(client),
NinegagSkraper(client),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ suspend fun SkraperClient.fetchDocument(request: HttpRequest, charset: Charset =
/**
* @see <a href="https://ogp.me/">open graph protocol</a>
*/
suspend fun SkraperClient.fetchMediaWithOpenGraphMeta(
suspend fun SkraperClient.fetchOpenGraphMedia(
media: Media,
request: HttpRequest = HttpRequest(url = media.url)
): Media {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal inline fun Element.getStyle(name: String): String? {
return getStyleMap()[name]
}

internal fun Element.getBackgroundImageStyle(): String {
internal fun Element.getBackgroundImageUrl(): String {
return this
.getStyle("background-image")
.orEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchDocument
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.jsoup.getFirstElementByAttribute
import ru.sokomishalov.skraper.internal.jsoup.getFirstElementByAttributeValue
Expand Down Expand Up @@ -98,7 +98,7 @@ open class FacebookSkraper @JvmOverloads constructor(
}

override suspend fun resolve(media: Media): Media {
return client.fetchMediaWithOpenGraphMeta(media)
return client.fetchOpenGraphMedia(media)
}

private fun JsonNode?.prepareMetaInfoMap(): Map<String, JsonNode> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchDocument
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.jsoup.getBackgroundImageStyle
import ru.sokomishalov.skraper.internal.jsoup.getBackgroundImageUrl
import ru.sokomishalov.skraper.internal.jsoup.getFirstElementByClass
import ru.sokomishalov.skraper.internal.jsoup.getStyle
import ru.sokomishalov.skraper.internal.number.div
Expand Down Expand Up @@ -120,7 +120,7 @@ open class FlickrSkraper @JvmOverloads constructor(

override suspend fun resolve(media: Media): Media {
return when (media) {
is Image -> client.fetchMediaWithOpenGraphMeta(media)
is Image -> client.fetchOpenGraphMedia(media)
else -> media
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ open class FlickrSkraper @JvmOverloads constructor(

private fun Element?.getBackgroundImage(): String? {
return this
?.getBackgroundImageStyle()
?.getBackgroundImageUrl()
?.let { "https:$it" }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchDocument
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.jsoup.getFirstElementByTag
import ru.sokomishalov.skraper.internal.serialization.getByPath
Expand Down Expand Up @@ -78,7 +78,7 @@ open class IFunnySkraper @JvmOverloads constructor(
}

override suspend fun resolve(media: Media): Media {
return client.fetchMediaWithOpenGraphMeta(media)
return client.fetchOpenGraphMedia(media)
}

override suspend fun getPageInfo(path: String): PageInfo? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchDocument
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.iterable.mapThis
import ru.sokomishalov.skraper.internal.number.div
Expand Down Expand Up @@ -83,7 +83,7 @@ open class InstagramSkraper @JvmOverloads constructor(
}

override suspend fun resolve(media: Media): Media {
return client.fetchMediaWithOpenGraphMeta(media)
return client.fetchOpenGraphMedia(media)
}

private fun String.isTagPath() = "explore/tags/" in this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchDocument
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.iterable.mapThis
import ru.sokomishalov.skraper.internal.number.div
Expand Down Expand Up @@ -72,7 +72,7 @@ open class NinegagSkraper @JvmOverloads constructor(
?.find { it is Video }
?: media
}
else -> client.fetchMediaWithOpenGraphMeta(media)
else -> client.fetchOpenGraphMedia(media)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchDocument
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.iterable.mapThis
import ru.sokomishalov.skraper.internal.jsoup.*
Expand Down Expand Up @@ -107,7 +107,7 @@ open class PikabuSkraper @JvmOverloads constructor(
?.extractVideoInfo()
?: media
}
else -> client.fetchMediaWithOpenGraphMeta(media)
else -> client.fetchOpenGraphMedia(media)
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ open class PikabuSkraper @JvmOverloads constructor(
private fun Document?.extractPageCover(): String? {
return this
?.getFirstElementByClass("background__placeholder")
?.getBackgroundImageStyle()
?.getBackgroundImageUrl()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchDocument
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.iterable.mapThis
import ru.sokomishalov.skraper.internal.net.host
Expand Down Expand Up @@ -83,7 +83,7 @@ open class PinterestSkraper @JvmOverloads constructor(

override suspend fun resolve(media: Media): Media {
return when (media) {
is Image -> client.fetchMediaWithOpenGraphMeta(media)
is Image -> client.fetchOpenGraphMedia(media)
else -> media
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ru.sokomishalov.skraper.Skraper
import ru.sokomishalov.skraper.client.HttpRequest
import ru.sokomishalov.skraper.client.SkraperClient
import ru.sokomishalov.skraper.client.fetchJson
import ru.sokomishalov.skraper.client.fetchMediaWithOpenGraphMeta
import ru.sokomishalov.skraper.client.fetchOpenGraphMedia
import ru.sokomishalov.skraper.client.jdk.DefaultBlockingSkraperClient
import ru.sokomishalov.skraper.internal.iterable.mapThis
import ru.sokomishalov.skraper.internal.net.path
Expand Down Expand Up @@ -93,7 +93,7 @@ open class RedditSkraper @JvmOverloads constructor(

override suspend fun resolve(media: Media): Media {
return when (media) {
is Image -> client.fetchMediaWithOpenGraphMeta(media)
is Image -> client.fetchOpenGraphMedia(media)
is Video -> {
val posts = getPosts(path = media.url.path, limit = 1)
posts
Expand Down
Loading