mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
some debugs on Chisu playlist
This commit is contained in:
@@ -11,7 +11,8 @@ enum class SongType(var value: Int) {
|
||||
class SongEvent(
|
||||
val uid: String,
|
||||
val type: SongType,
|
||||
val req_uid: String?,
|
||||
val reqUid: String?,
|
||||
val reqName: String?,
|
||||
val name: String?,
|
||||
val author: String?,
|
||||
val time: Int?,
|
||||
|
@@ -5,15 +5,17 @@ import org.jetbrains.exposed.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.javatime.datetime
|
||||
import java.time.LocalDateTime
|
||||
|
||||
object SongLists: IntIdTable("song_list") {
|
||||
val user = reference("user", Users)
|
||||
val uid = varchar("uid", 64)
|
||||
val url = varchar("url", 128)
|
||||
val name = text("name")
|
||||
val reqName = varchar("req_name", 20)
|
||||
val author = text("author")
|
||||
val time = integer("time")
|
||||
val created_at = datetime("created_at")
|
||||
val created_at = datetime("created_at").default(LocalDateTime.now())
|
||||
}
|
||||
|
||||
class SongList(id: EntityID<Int>) : IntEntity(id) {
|
||||
@@ -27,4 +29,5 @@ class SongList(id: EntityID<Int>) : IntEntity(id) {
|
||||
|
||||
var user by User referencedOn SongLists.user
|
||||
var uid by SongLists.uid
|
||||
var reqName by SongLists.reqName
|
||||
}
|
@@ -8,7 +8,7 @@ import space.mori.chzzk_bot.common.models.SongLists
|
||||
import space.mori.chzzk_bot.common.models.User
|
||||
|
||||
object SongListService {
|
||||
fun saveSong(user: User, uid: String, url: String, name: String, author: String, time: Int) {
|
||||
fun saveSong(user: User, uid: String, url: String, name: String, author: String, time: Int, reqName: String) {
|
||||
return transaction {
|
||||
SongList.new {
|
||||
this.user = user
|
||||
@@ -17,6 +17,7 @@ object SongListService {
|
||||
this.name = name
|
||||
this.author = author
|
||||
this.time = time
|
||||
this.reqName = reqName
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +33,7 @@ object SongListService {
|
||||
|
||||
fun getSong(user: User): List<SongList> {
|
||||
return transaction {
|
||||
SongList.find(SongLists.user eq user.id).toList()
|
||||
SongList.find(SongLists.user eq user.id).toList().sortedBy { it.created_at }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +51,13 @@ object SongListService {
|
||||
songRow
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteUser(user: User): Boolean {
|
||||
return transaction {
|
||||
val songRow = SongList.find(SongLists.user eq user.id).toList()
|
||||
|
||||
songRow.forEach { it.delete() }
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,7 +16,7 @@ data class YoutubeVideo(
|
||||
)
|
||||
|
||||
val regex = ".*(?:youtu.be/|v/|u/\\w/|embed/|watch\\?v=|&v=)([^#&?]*).*".toRegex()
|
||||
val durationRegex = """PT(\d+H)?(\d+m)?(\d+S)?""".toRegex()
|
||||
val durationRegex = """PT(\d+H)?(\d+M)?(\d+S)?""".toRegex()
|
||||
|
||||
val client = OkHttpClient()
|
||||
val gson = Gson()
|
||||
@@ -33,6 +33,7 @@ fun getYoutubeVideoId(url: String): String? {
|
||||
}
|
||||
|
||||
fun parseDuration(duration: String): Int {
|
||||
println(duration)
|
||||
val matchResult = durationRegex.find(duration)
|
||||
val (hours, minutes, seconds) = matchResult?.destructured ?: return 0
|
||||
|
||||
@@ -54,7 +55,7 @@ fun getYoutubeVideo(url: String): YoutubeVideo? {
|
||||
.addPathSegment("videos")
|
||||
.addQueryParameter("id", videoId)
|
||||
.addQueryParameter("key", dotenv["YOUTUBE_API_KEY"])
|
||||
.addQueryParameter("part", "snippet")
|
||||
.addQueryParameter("part", "snippet,contentDetails,status")
|
||||
.build()
|
||||
|
||||
|
||||
@@ -71,10 +72,12 @@ fun getYoutubeVideo(url: String): YoutubeVideo? {
|
||||
|
||||
if (items == null || items.size() == 0) return null
|
||||
|
||||
println(json)
|
||||
|
||||
val item = items[0].asJsonObject
|
||||
val snippet = item.getAsJsonObject("snippet")
|
||||
val contentDetail = item.asJsonObject.getAsJsonObject("contentDetail")
|
||||
val status = contentDetail.getAsJsonObject("status")
|
||||
val contentDetail = item.getAsJsonObject("contentDetails")
|
||||
val status = item.getAsJsonObject("status")
|
||||
|
||||
if (!status.get("embeddable").asBoolean) return null
|
||||
|
||||
|
Reference in New Issue
Block a user