fix: fix wrong avatar and image scale
This commit is contained in:
2 files changed
+32
-33
No files matched your search
@@ -10,6 +10,7 @@ package cn.rtast.fancybot.commands.parse
|
||||
import cn.rtast.fancybot.commands.misc.ShortLinkCommand.Companion.makeShortLink
|
||||
import cn.rtast.fancybot.entity.douyin.DouyinVideo
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.fancybot.util.misc.drawCustomImage
|
||||
import cn.rtast.fancybot.util.misc.toBufferedImage
|
||||
import cn.rtast.fancybot.util.misc.toByteArray
|
||||
import cn.rtast.fancybot.util.misc.toURL
|
||||
@@ -44,31 +45,30 @@ object DouyinVideoParseCommand {
|
||||
g2d.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)
|
||||
g2d.color = Color(230, 230, 230)
|
||||
g2d.fill(
|
||||
RoundRectangle2D.Float(
|
||||
20f,
|
||||
20f,
|
||||
(IMAGE_WIDTH - 40).toFloat(),
|
||||
(IMAGE_HEIGHT - 40).toFloat(),
|
||||
50f,
|
||||
50f
|
||||
)
|
||||
RoundRectangle2D.Float(20f, 20f, (IMAGE_WIDTH - 40).toFloat(), (IMAGE_HEIGHT - 40).toFloat(), 50f, 50f)
|
||||
)
|
||||
g2d.color = Color.BLACK
|
||||
g2d.font = Font("Serif", Font.BOLD, 48)
|
||||
g2d.drawString(video.data.awemeDetail.author.nickname, 60, 100)
|
||||
g2d.font = Font("Serif", Font.PLAIN, 32)
|
||||
g2d.drawString(video.data.awemeDetail.desc, 60, 160)
|
||||
val avatarImage = video.data.awemeDetail.music.avatarLarge.urlList.first().toURL().readBytes().toBufferedImage()
|
||||
g2d.drawImage(avatarImage, 60, 200, 160, 160, null)
|
||||
val coverImage = video.data.awemeDetail.video.cover.urlList.first().toURL().readBytes().toBufferedImage()
|
||||
g2d.drawImage(coverImage, 300, 200, 600, 360, null)
|
||||
val avatarImage = video.data.awemeDetail.author.avatarThumb.urlList
|
||||
.first().toURL().readBytes().toBufferedImage()
|
||||
g2d.drawImage(avatarImage, 60, 180, 160, 160, null)
|
||||
val cover = video.data.awemeDetail.video.coverOriginalScale
|
||||
|
||||
g2d.drawCustomImage(
|
||||
cover.urlList.first().toURL().readBytes().toBufferedImage(),
|
||||
450, 170, cover.width.toDouble(), cover.height.toDouble()
|
||||
)
|
||||
g2d.color = Color.DARK_GRAY
|
||||
g2d.font = Font("Serif", Font.PLAIN, 28)
|
||||
g2d.drawString("点赞: ${video.data.awemeDetail.statistics.diggCount.formatNumber()}", 60, 600)
|
||||
g2d.drawString("播放: ${video.data.awemeDetail.statistics.playCount.formatNumber()}", 60, 640)
|
||||
g2d.drawString("评论: ${video.data.awemeDetail.statistics.commentCount.formatNumber()}", 60, 680)
|
||||
g2d.drawString("收藏: ${video.data.awemeDetail.statistics.collectCount.formatNumber()}", 60, 720)
|
||||
g2d.drawString("分享: ${video.data.awemeDetail.statistics.shareCount.formatNumber()}", 60, 760)
|
||||
g2d.drawString("粉丝: ${video.data.awemeDetail.author.followerCount.formatNumber()}", 60, 400)
|
||||
g2d.drawString("点赞: ${video.data.awemeDetail.statistics.diggCount.formatNumber()}", 60, 440)
|
||||
g2d.drawString("播放: ${video.data.awemeDetail.statistics.playCount.formatNumber()}", 60, 480)
|
||||
g2d.drawString("评论: ${video.data.awemeDetail.statistics.commentCount.formatNumber()}", 60, 520)
|
||||
g2d.drawString("收藏: ${video.data.awemeDetail.statistics.collectCount.formatNumber()}", 60, 560)
|
||||
g2d.drawString("分享: ${video.data.awemeDetail.statistics.shareCount.formatNumber()}", 60, 600)
|
||||
g2d.dispose()
|
||||
return card.toByteArray().encodeToBase64()
|
||||
}
|
||||
@@ -77,8 +77,8 @@ object DouyinVideoParseCommand {
|
||||
val id = if (shortLinkRegex.find(message.rawMessage) != null) {
|
||||
val shortUrl = shortLinkRegex.find(message.rawMessage)?.value ?: ""
|
||||
val request = Request.Builder().url(shortUrl).build()
|
||||
val finalUrl = tempHttpClient.newCall(request).execute().request.url.toString()
|
||||
extractVideoId(finalUrl)
|
||||
val finalUrl = tempHttpClient.newCall(request).execute().also { it.close() }
|
||||
extractVideoId(finalUrl.request.url.toString())
|
||||
} else if (singleVideoRegex.find(message.rawMessage) != null) extractVideoId(message.rawMessage) else ""
|
||||
if (id.isNotBlank()) {
|
||||
val response = Http.get<DouyinVideo>(
|
||||
@@ -86,7 +86,7 @@ object DouyinVideoParseCommand {
|
||||
mapOf("aweme_id" to id)
|
||||
)
|
||||
val videoPlayUrlShortUrl = response.data.awemeDetail.video.bitRate
|
||||
.random().playAddr.urlList.random().makeShortLink()
|
||||
.first().playAddr.urlList.first().makeShortLink()
|
||||
val shareUrlShortUrl = response.data.awemeDetail.shareUrl.makeShortLink()
|
||||
val image = this.createDouyinVideoCard(response)
|
||||
val msg = MessageChain.Builder()
|
||||
|
||||
@@ -20,7 +20,6 @@ data class DouyinVideo(
|
||||
data class AwemeDetail(
|
||||
val author: Author,
|
||||
val desc: String,
|
||||
val music: Music,
|
||||
val statistics: Statistics,
|
||||
val video: Video,
|
||||
@SerializedName("share_url")
|
||||
@@ -32,14 +31,11 @@ data class DouyinVideo(
|
||||
@SerializedName("follower_count")
|
||||
val followerCount: Int,
|
||||
val signature: String,
|
||||
@SerializedName("avatar_thumb")
|
||||
val avatarThumb: AvatarThumb,
|
||||
)
|
||||
|
||||
data class Music(
|
||||
@SerializedName("avatar_large")
|
||||
val avatarLarge: AvatarLarge,
|
||||
)
|
||||
|
||||
data class AvatarLarge(
|
||||
data class AvatarThumb(
|
||||
@SerializedName("url_list")
|
||||
val urlList: List<String>,
|
||||
)
|
||||
@@ -63,7 +59,8 @@ data class DouyinVideo(
|
||||
)
|
||||
|
||||
data class Video(
|
||||
val cover: Cover,
|
||||
@SerializedName("cover_original_scale")
|
||||
val coverOriginalScale: CoverOriginalScale,
|
||||
@SerializedName("bit_rate")
|
||||
val bitRate: List<BitRate>
|
||||
)
|
||||
@@ -74,12 +71,14 @@ data class DouyinVideo(
|
||||
)
|
||||
|
||||
data class PlayAddr(
|
||||
@SerializedName("url_list")
|
||||
val urlList: List<String>
|
||||
)
|
||||
|
||||
data class Cover(
|
||||
@SerializedName("url_list")
|
||||
val urlList: List<String>,
|
||||
)
|
||||
|
||||
data class CoverOriginalScale(
|
||||
@SerializedName("url_list")
|
||||
val urlList: List<String>,
|
||||
val height: Int,
|
||||
val width: Int
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user