Skip to content

Commit

Permalink
combine format transition
Browse files Browse the repository at this point in the history
  • Loading branch information
StageGuard committed Aug 20, 2023
1 parent 858e2fe commit 929f550
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
23 changes: 7 additions & 16 deletions mirai-core/src/commonMain/kotlin/message/data/shortVideo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import net.mamoe.mirai.internal.asQQAndroidBot
import net.mamoe.mirai.internal.message.RefinableMessage
import net.mamoe.mirai.internal.message.RefineContext
import net.mamoe.mirai.internal.message.RefineContextKey
import net.mamoe.mirai.internal.message.protocol.impl.ShortVideoProtocol
import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody
import net.mamoe.mirai.internal.network.protocol.packet.chat.video.PttCenterSvr
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.utils.ExternalResource
import net.mamoe.mirai.utils.toUHexString

/**
Expand Down Expand Up @@ -78,12 +80,16 @@ internal class OnlineShortVideoMsgInternal(
"queried result: ${shortVideoDownloadReq.fileMd5.toUHexString("")}"
)

val format = ShortVideoProtocol.FORMAT
.firstOrNull { it.second == videoFile.fileFormat }?.first
?: ExternalResource.DEFAULT_FORMAT_NAME

return OnlineShortVideoImpl(
videoFile.fileUuid.decodeToString(),
shortVideoDownloadReq.fileMd5,
videoFile.fileName.decodeToString(),
videoFile.fileSize.toLong(),
videoFile.fileFormat.toVideoFormat(),
format,
shortVideoDownloadReq.urlV4,
ShortVideoThumbnail(
videoFile.thumbFileMd5,
Expand Down Expand Up @@ -236,19 +242,4 @@ internal class OfflineShortVideoImpl(
result = 31 * result + thumbnail.hashCode()
return result
}
}

private fun Int.toVideoFormat() = when (this) {
1 -> "ts"
2 -> "avi"
3 -> "mp4"
4 -> "wmv"
5 -> "mkv"
6 -> "rmvb"
7 -> "rm"
8 -> "afs"
9 -> "mov"
10 -> "mod"
11 -> "mts"
else -> "mirai" // unknown to default
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal class ShortVideoProtocol : MessageProtocol() {
fileUuid = data.videoId.encodeToByteArray(),
fileMd5 = data.fileMd5,
fileName = data.filename.encodeToByteArray(),
fileFormat = data.fileFormat.toVideoFormat(),
fileFormat = FORMAT.firstOrNull { it.first == data.fileFormat }?.second ?: 3,
fileTime = 10,
fileSize = data.fileSize.toInt(),
thumbWidth = thumbWidth,
Expand All @@ -79,19 +79,20 @@ internal class ShortVideoProtocol : MessageProtocol() {
}

}
}

private fun String.toVideoFormat() = when (this) {
"ts" -> 1
"avi" -> 2
"mp4" -> 3
"wmv" -> 4
"mkv" -> 5
"rmvb" -> 6
"rm" -> 7
"afs" -> 8
"mov" -> 9
"mod" -> 10
"mts" -> 11
else -> -1 // unknown to default
internal companion object {
internal val FORMAT: List<Pair<String, Int>> = listOf(
"ts" to 1,
"avi" to 2,
"mp4" to 3,
"wmv" to 4,
"mkv" to 5,
"rmvb" to 6,
"rm" to 7,
"afs" to 8,
"mov" to 9,
"mod" to 10,
"mts" to 11
)
}
}

0 comments on commit 929f550

Please sign in to comment.