Skip to content

Commit

Permalink
fix player exit statuses
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
keshon committed Dec 7, 2024
1 parent 41dda9a commit 32163e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 2 additions & 0 deletions cmd/melodix/melodix.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ func (b *Bot) onPlayback(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSendEmbed(m.ChannelID, embed.NewEmbed().SetColor(embedColor).SetDescription("No song is currently playing.").MessageEmbed)
case player.StatusResuming:
s.ChannelMessageSendEmbed(m.ChannelID, embed.NewEmbed().SetColor(embedColor).SetDescription("Oopsie! There was a network issue.\nTrying to continue playback...").MessageEmbed)
case player.StatusError:
s.ChannelMessageSendEmbed(m.ChannelID, embed.NewEmbed().SetColor(embedColor).SetDescription("Error detected...").MessageEmbed)
case player.StatusAdded:
desc := fmt.Sprintf("Song(s) added to queue\n\nUse `%slist` to see the current queue.", b.prefixCache[m.GuildID])
s.ChannelMessageSendEmbed(m.ChannelID, embed.NewEmbed().SetColor(embedColor).SetDescription(desc).MessageEmbed)
Expand Down
4 changes: 4 additions & 0 deletions player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ PLAYBACK_LOOP:
close(done)
// stop if there is an error
if err != nil && err != io.EOF {
p.StatusSignals <- StatusError
return err
}
// restart if there is an interrupt
duration, position, err := p.getPlaybackDuration(encoding, streaming, p.Song)
if err != nil {
p.StatusSignals <- StatusError
return err
}
if encoding.Stats().Duration.Seconds() > 0 && position.Seconds() > 0 && position < duration {
Expand All @@ -236,6 +238,7 @@ PLAYBACK_LOOP:
fmt.Println("Switching to cached playback")
_, position, err := p.getPlaybackDuration(encoding, streaming, p.Song)
if err != nil {
p.StatusSignals <- StatusError
return err
}
isCached = true
Expand All @@ -256,6 +259,7 @@ PLAYBACK_LOOP:
}
p.ActionSignals <- ActionStop
case ActionStop:
p.StatusSignals <- StatusResting
return p.leaveVoiceChannel(vc)
case ActionSwap:
encoding.Stop()
Expand Down
20 changes: 6 additions & 14 deletions song/song.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,12 @@ const (
)

var platformURLs = map[Platform][]string{
YouTube: {"youtube.com", "youtu.be"},
Soundcloud: {"soundcloud.com"},
Bandcamp: {"bandcamp.com"},
FiftySixCom: {"56.com"},
DailyMotion: {"dailymotion.com"},
Vimeo: {"vimeo.com"},
TikTok: {"tiktok.com"},
Facebook: {"facebook.com"},
Instagram: {"instagram.com"},
Vevo: {"vevo.com"},
AudioMack: {"audiomack.com"},
Chaturbate: {"chaturbate.com"},
Pornhub: {"pornhub.com"},
ReverbNation: {"reverbnation.com"},
YouTube: {"youtube.com", "youtu.be"},
Soundcloud: {"soundcloud.com"},
Bandcamp: {"bandcamp.com"},
FiftySixCom: {"56.com"},
DailyMotion: {"dailymotion.com"},
Vimeo: {"vimeo.com"},
}

var (
Expand Down

0 comments on commit 32163e4

Please sign in to comment.