Skip to content

ytdlpにしようの会 - #57

Open
kuroneko6423 wants to merge 2 commits into
mainfrom
to-ytdl
Open

ytdlpにしようの会#57
kuroneko6423 wants to merge 2 commits into
mainfrom
to-ytdl

Conversation

@kuroneko6423

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 26, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an optional yt-dlp based resolution path for YouTube URLs, allowing the bot to extract direct stream URLs (and preserve page metadata) while continuing to play audio through the existing Lavalink pipeline.

Changes:

  • Add ytdlp configuration (command/cookies/extra args) to BotConfig and the default config.yml.
  • Introduce YtDlpAudioResolver and wire it into slash/message/websocket play flows as a first-pass resolver for YouTube URLs.
  • Extend TrackData with auxiliary metadata and update embeds/API responses to use TrackData’s derived properties (title/url/author/duration).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/main/resources/config.yml Adds ytdlp configuration block (enabled/command/cookies/args).
src/main/kotlin/jp/lunaproject/bot/configurations/BotConfig.kt Adds ytdlp config model and includes it in equality/hash/toString.
src/main/kotlin/jp/lunaproject/bot/audio/media/YtDlpAudioResolver.kt New resolver that shells out to yt-dlp to inspect URLs and extract stream URLs/metadata.
src/main/kotlin/jp/lunaproject/bot/audio/media/TrackData.kt Adds metadata container + derived getters for UI/API consistency.
src/main/kotlin/jp/lunaproject/bot/commands/slash/media/Play.kt Attempts yt-dlp resolution before Lavalink loadItem.
src/main/kotlin/jp/lunaproject/bot/commands/message/media/Play.kt Attempts yt-dlp resolution before Lavalink loadItem.
src/main/kotlin/jp/lunaproject/bot/api/restful/controllers/websocket/MediaController.kt Attempts yt-dlp resolution for websocket play requests and returns enriched track data.
src/main/kotlin/jp/lunaproject/bot/components/constants/MediaComponent.kt Uses TrackData derived properties in “next media” embed.
src/main/kotlin/jp/lunaproject/bot/components/commands/media/Play.kt Uses TrackData derived properties in “loaded track/playlist” embeds.
src/main/kotlin/jp/lunaproject/bot/components/commands/media/PlayList.kt Uses TrackData derived properties in queue/history embeds.
src/main/kotlin/jp/lunaproject/bot/audio/media/ResponseMediaData.kt Returns derived TrackData fields in websocket payloads; adds helper of(TrackData).
src/main/kotlin/jp/lunaproject/bot/audio/media/PlayListHelper.kt Uses derived TrackData fields in select menu options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +25 to +27
if (info.entryUrls.isNotEmpty()) {
val tracks = info.entryUrls.mapNotNull { entryUrl -> resolveTrack(entryUrl, controller, member) }
if (tracks.isEmpty()) return null

@Serializable
data class YtDlp(
val enabled: Boolean = true,
Comment on lines 51 to +53
if (redis != other.redis) return false
if (lavalink != other.lavalink) return false
if (ytdlp != other.ytdlp) return false
Comment on lines +32 to +33
val url
get() = metadata.url ?: track.uri ?: ""
@@ -194,15 +193,15 @@ sealed class ResponseMediaData {
val (track, member) = data
Comment thread src/main/resources/config.yml Outdated
Comment on lines +69 to +74
ytdlp:
enabled: true
# PATH に通っていない場合は yt-dlp.exe の絶対パスを指定
# command: 'C:/tools/yt-dlp.exe'
command: 'yt-dlp'
# cookies_file を設定すると cookies_from_browser より優先
Comment on lines +184 to +195
val completed = process.waitFor(PROCESS_TIMEOUT_SECONDS, TimeUnit.SECONDS)
if (!completed) {
process.destroyForcibly()
Main.LOGGER.warn("yt-dlp process timed out after {} seconds", PROCESS_TIMEOUT_SECONDS)
return@withContext null
}

CommandResult(
process.exitValue(),
process.inputStream.readBytes().toString(Charsets.UTF_8).trim(),
process.errorStream.readBytes().toString(Charsets.UTF_8).trim()
)
Comment on lines +22 to +37
return runCatching {
val info = inspect(query) ?: return null

if (info.entryUrls.isNotEmpty()) {
val tracks = info.entryUrls.mapNotNull { entryUrl -> resolveTrack(entryUrl, controller, member) }
if (tracks.isEmpty()) return null

LoadResult.Playlist(info.title.ifBlank { tracks.first().title }, tracks)
} else {
val url = info.pageUrl ?: query
resolveTrack(url, controller, member)?.let { LoadResult.Track(it) }
}
}.getOrElse {
Main.LOGGER.warn("yt-dlp resolution failed for {}: {}", query, it.message)
null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants