some debugs on Chisu playlist

This commit is contained in:
dalbodeule
2024-08-04 15:30:00 +09:00
parent f7953778e1
commit 590c1203bd
11 changed files with 248 additions and 36 deletions

View File

@@ -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?,

View File

@@ -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
}

View File

@@ -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
}
}
}

View File

@@ -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