Skip to content

Commit

Permalink
Disallow playlists in music plugin | Fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Breuer committed Jan 22, 2017
1 parent 9a73ba8 commit d57ff5d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion plugins/music.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ func (m *Music) Action(command string, content string, msg *discordgo.Message, s
content = string(contentRune[1:len(contentRune) - 1])
}

// Check if the url is a playlist
if strings.Contains(content, "list") ||
strings.Contains(content, "/set") ||
strings.Contains(content, "/mix") {
session.ChannelMessageSend(channel.ID, "Sorry but playlists are not supported :neutral_face:")
return
}

// Check if the link has been cached
cursor, err := rethink.Table("music").Filter(map[string]interface{}{"url": content}).Run(helpers.GetDB())
helpers.Relax(err)
Expand All @@ -375,7 +383,7 @@ func (m *Music) Action(command string, content string, msg *discordgo.Message, s
// Link was not downloaded yet

// Resolve the url through YTDL.
ytdl := exec.Command("youtube-dl", "-J", content)
ytdl := exec.Command("youtube-dl", "-J", "--flat-playlist", content)
yout, yerr := ytdl.Output()

// If youtube-dl exits with 0 the link is valid
Expand All @@ -388,11 +396,22 @@ func (m *Music) Action(command string, content string, msg *discordgo.Message, s
json, err := gabs.ParseJSON(yout)
helpers.Relax(err)

// Exit if the link is a live stream
// (archived live streams are allowed though)
if json.ExistsP("is_live") && json.Path("is_live").Data().(bool) {
session.ChannelMessageSend(channel.ID, "Livestreams are not supported :neutral_face:")
return
}

// Exit if the link is a playlist
if json.ExistsP("_type") && json.Path("_type").Data() != nil {
switch json.Path("_type").Data().(string) {
case "playlist":
session.ChannelMessageSend(channel.ID, "Sorry but playlists are not supported :neutral_face:")
return
}
}

match = Song{
AddedBy: msg.Author.ID,
Processed: false,
Expand Down

0 comments on commit d57ff5d

Please sign in to comment.