ytdlpにしようの会 - #57
Open
kuroneko6423 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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
ytdlpconfiguration (command/cookies/extra args) toBotConfigand the defaultconfig.yml. - Introduce
YtDlpAudioResolverand wire it into slash/message/websocket play flows as a first-pass resolver for YouTube URLs. - Extend
TrackDatawith auxiliary metadata and update embeds/API responses to useTrackData’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 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.