Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
fix: no need to use add command when adding during playing
Browse files Browse the repository at this point in the history
- experimenting with http client
  • Loading branch information
keshon committed Jul 31, 2024
1 parent ff348a9 commit 28f3abd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
19 changes: 15 additions & 4 deletions mods/music/discord/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (d *Discord) handlePlayCommand(param string, enqueueOnly bool) {
}

// Enqueue playlist to the player
if d.Player.GetCurrentSong() != nil {
enqueueOnly = true
}
err = playOrEnqueue(d, songs, s, m, enqueueOnly, pleaseWaitMessage.ID)
if err != nil {
slog.Error(err)
Expand Down Expand Up @@ -286,8 +289,16 @@ func playOrEnqueue(d *Discord, playlist []*player.Song, s *discordgo.Session, m
}

if enqueueOnly {
showStatusMessage(d, s, m.Message.ChannelID, prevMessageID, playlist, previousPlaylistExist, false)
slog.Warn(d.Player.GetCurrentStatus().String())
playlist = d.Player.GetSongQueue()
go func() {
for {
if d.Player.GetCurrentStatus() == player.StatusPlaying || d.Player.GetCurrentStatus() == player.StatusPaused {
showStatusMessage(d, s, m.Message.ChannelID, prevMessageID, playlist, previousPlaylistExist, false)
break
}
time.Sleep(250 * time.Millisecond)
}
}()
} else {
go func() {
for {
Expand All @@ -299,14 +310,14 @@ func playOrEnqueue(d *Discord, playlist []*player.Song, s *discordgo.Session, m
}
}()

slog.Warn("Current status is", d.Player.GetCurrentStatus().String())

err := d.Player.Unpause(vs.ChannelID)
if err != nil {
return err
}
}

slog.Warn("Current status is", d.Player.GetCurrentStatus().String())

return nil
}

Expand Down
17 changes: 17 additions & 0 deletions mods/music/sources/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package sources
import (
"fmt"
"io"
"net"
"time"

"net/http"
"regexp"
Expand Down Expand Up @@ -36,6 +38,21 @@ func NewYoutube() IYoutube {
}

func (y *Youtube) parseSongInfo(url string) (*player.Song, error) {
// Experimental
y.youtubeClient.HTTPClient = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
}).DialContext,
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
Timeout: 30 * time.Second,
}

song, err := y.youtubeClient.GetVideo(url)
if err != nil {
return nil, err
Expand Down

0 comments on commit 28f3abd

Please sign in to comment.