mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-08 08:02:49 +00:00
feat: add yt-dlp
This commit is contained in:
@@ -19,6 +19,8 @@ FROM jrottenberg/ffmpeg:4.1-alpine
|
||||
|
||||
RUN apk update
|
||||
RUN apk add ca-certificates opus-dev opusfile-dev
|
||||
# add python for yt-dlp
|
||||
RUN apk add python3
|
||||
WORKDIR /server
|
||||
COPY --from=0 /home/dist /server/dist
|
||||
COPY --from=1 /build/bot /server/bot
|
||||
|
||||
@@ -14,4 +14,4 @@ services:
|
||||
- ./data.db:/server/data.db
|
||||
- ./logrus.log:/server/logrus.log
|
||||
|
||||
- /usr/local/bin/youtube-dl:/usr/bin/youtube-dl
|
||||
- /usr/local/bin/yt-dlp:/usr/bin/yt-dlp
|
||||
|
||||
@@ -7,7 +7,7 @@ A soundboard bot for discord. Built with Go/React.
|
||||
## How to use
|
||||
|
||||
- [Download latest release here](https://github.com/mgerb/go-discord-bot/releases)
|
||||
- Install [youtube-dl](https://github.com/rg3/youtube-dl/blob/master/README.md#installation)
|
||||
- Install [yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
||||
- Install [ffmpeg](https://www.ffmpeg.org/download.html)
|
||||
- edit your config.json file
|
||||
- `docker-compose up`
|
||||
|
||||
@@ -145,7 +145,10 @@ func (conn *AudioConnection) handleMessage(m *discordgo.MessageCreate) {
|
||||
func (conn *AudioConnection) dismiss() {
|
||||
voiceConnection := conn.getVoiceConnection()
|
||||
if voiceConnection != nil && !conn.SoundPlayingLock && len(conn.SoundQueue) == 0 {
|
||||
voiceConnection.Disconnect()
|
||||
err := voiceConnection.Disconnect()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,8 +277,17 @@ func (conn *AudioConnection) PlayAudio(soundName string, m *discordgo.MessageCre
|
||||
func (conn *AudioConnection) playSoundsInQueue() {
|
||||
conn.toggleSoundPlayingLock(true)
|
||||
voiceConnection := conn.getVoiceConnection()
|
||||
|
||||
if voiceConnection == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Start speaking.
|
||||
voiceConnection.Speaking(true)
|
||||
err := voiceConnection.Speaking(true)
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -295,7 +307,10 @@ func (conn *AudioConnection) playSoundsInQueue() {
|
||||
|
||||
default:
|
||||
// Stop speaking
|
||||
voiceConnection.Speaking(false)
|
||||
err := voiceConnection.Speaking(false)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
conn.toggleSoundPlayingLock(false)
|
||||
return
|
||||
}
|
||||
@@ -334,10 +349,16 @@ func (conn *AudioConnection) loadFile(fileName string) error {
|
||||
|
||||
func (conn *AudioConnection) clipAudio(m *discordgo.MessageCreate) {
|
||||
if len(conn.VoiceClipQueue) < 10 {
|
||||
conn.Session.ChannelMessageSend(m.ChannelID, "Clip failed.")
|
||||
_, err := conn.Session.ChannelMessageSend(m.ChannelID, "Clip failed.")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
} else {
|
||||
writePacketsToFile(m.Author.Username, conn.VoiceClipQueue)
|
||||
conn.Session.ChannelMessageSend(m.ChannelID, "Sound clipped!")
|
||||
_, err := conn.Session.ChannelMessageSend(m.ChannelID, "Sound clipped!")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +366,10 @@ func writePacketsToFile(username string, packets chan *discordgo.Packet) {
|
||||
|
||||
// create clips folder if it does not exist
|
||||
if _, err := os.Stat(config.Config.ClipsPath); os.IsNotExist(err) {
|
||||
os.Mkdir(config.Config.ClipsPath, os.ModePerm)
|
||||
err := os.Mkdir(config.Config.ClipsPath, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
opusData := map[uint32][][]byte{}
|
||||
@@ -411,7 +435,7 @@ func (conn *AudioConnection) startAudioListener() {
|
||||
voiceConnection := conn.getVoiceConnection()
|
||||
if voiceConnection != nil {
|
||||
voiceConnection.RLock()
|
||||
ready := voiceConnection != nil && voiceConnection.Ready
|
||||
ready := voiceConnection.Ready
|
||||
voiceConnection.RUnlock()
|
||||
|
||||
if !ready {
|
||||
@@ -429,7 +453,7 @@ func (conn *AudioConnection) startAudioListener() {
|
||||
continue
|
||||
}
|
||||
voiceConnection.RLock()
|
||||
ready := voiceConnection != nil && voiceConnection.Ready
|
||||
ready := voiceConnection.Ready
|
||||
voiceConnection.RUnlock()
|
||||
|
||||
// if connection lost wait for ready
|
||||
|
||||
@@ -26,7 +26,7 @@ func getDownloaderHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
// get the video title
|
||||
titleCmd := exec.Command("youtube-dl", "--get-title", url)
|
||||
titleCmd := exec.Command("yt-dlp", "--get-title", url)
|
||||
var titleOut bytes.Buffer
|
||||
titleCmd.Stdout = &titleOut
|
||||
|
||||
@@ -46,7 +46,7 @@ func getDownloaderHandler(c *gin.Context) {
|
||||
cleanTitle := cleanseTitle(titleOut.String())
|
||||
log.Debug(cleanTitle)
|
||||
|
||||
cmd := exec.Command("youtube-dl", "-x", "--audio-format", "mp3", "-o", config.Config.YoutubePath+"/"+cleanTitle+".%(ext)s", url)
|
||||
cmd := exec.Command("yt-dlp", "-x", "--audio-format", "mp3", "-o", config.Config.YoutubePath+"/"+cleanTitle+".%(ext)s", url)
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
|
||||
Reference in New Issue
Block a user