https://github.com/matthieugrieger/mumbledj/issues/33: Playlist titles in notifications
This commit is contained in:
parent
0bb039b52f
commit
d8b31e60c2
|
@ -7,6 +7,7 @@ MumbleDJ Changelog
|
|||
* Reworked `Makefile` slightly.
|
||||
* Now uses `gumbleutil.PlainText` for removing HTML tags instead of `sanitize`.
|
||||
* Added `!setcomment` which allows admin users to set the comment for the bot.
|
||||
* Made "Now Playing" notification and `!currentsong` show the playlist title of the song if it is included in a playlist.
|
||||
|
||||
### February 3, 2015 -- `v2.4.1`
|
||||
* Made it possible to place MumbleDJ binary in `~/bin` instead of `/usr/local/bin` if the folder exists.
|
||||
|
|
|
@ -361,7 +361,12 @@ func currentSong(user *gumble.User) {
|
|||
} else {
|
||||
currentItem = dj.queue.CurrentItem().(*Song)
|
||||
}
|
||||
dj.SendPrivateMessage(user, fmt.Sprintf(CURRENT_SONG_HTML, currentItem.title, currentItem.submitter))
|
||||
if currentItem.playlistTitle == "" {
|
||||
dj.SendPrivateMessage(user, fmt.Sprintf(CURRENT_SONG_HTML, currentItem.title, currentItem.submitter))
|
||||
} else {
|
||||
dj.SendPrivateMessage(user, fmt.Sprintf(CURRENT_SONG_PLAYLIST_HTML, currentItem.title,
|
||||
currentItem.submitter, currentItem.playlistTitle))
|
||||
}
|
||||
} else {
|
||||
dj.SendPrivateMessage(user, NO_MUSIC_PLAYING_MSG)
|
||||
}
|
||||
|
|
13
playlist.go
13
playlist.go
|
@ -67,12 +67,13 @@ func NewPlaylist(user, id string) (*Playlist, error) {
|
|||
duration, _ := jq.Int("data", "items", index, "video", "duration")
|
||||
songDuration := fmt.Sprintf("%d:%02d", duration/60, duration%60)
|
||||
newSong := &Song{
|
||||
submitter: user,
|
||||
title: songTitle,
|
||||
youtubeId: songId,
|
||||
playlistId: id,
|
||||
duration: songDuration,
|
||||
thumbnailUrl: songThumbnail,
|
||||
submitter: user,
|
||||
title: songTitle,
|
||||
playlistTitle: playlistTitle,
|
||||
youtubeId: songId,
|
||||
playlistId: id,
|
||||
duration: songDuration,
|
||||
thumbnailUrl: songThumbnail,
|
||||
}
|
||||
queue.AddItem(newSong)
|
||||
}
|
||||
|
|
40
song.go
40
song.go
|
@ -21,14 +21,15 @@ import (
|
|||
|
||||
// Song type declaration.
|
||||
type Song struct {
|
||||
submitter string
|
||||
title string
|
||||
youtubeId string
|
||||
playlistId string
|
||||
duration string
|
||||
thumbnailUrl string
|
||||
itemType string
|
||||
skippers []string
|
||||
submitter string
|
||||
title string
|
||||
playlistTitle string
|
||||
youtubeId string
|
||||
playlistId string
|
||||
duration string
|
||||
thumbnailUrl string
|
||||
itemType string
|
||||
skippers []string
|
||||
}
|
||||
|
||||
// Returns a new Song type. Before returning the new type, the song's metadata is collected
|
||||
|
@ -61,13 +62,14 @@ func NewSong(user, id string) (*Song, error) {
|
|||
videoDuration := fmt.Sprintf("%d:%02d", duration/60, duration%60)
|
||||
|
||||
song := &Song{
|
||||
submitter: user,
|
||||
title: videoTitle,
|
||||
youtubeId: id,
|
||||
playlistId: "",
|
||||
duration: videoDuration,
|
||||
thumbnailUrl: videoThumbnail,
|
||||
itemType: "song",
|
||||
submitter: user,
|
||||
title: videoTitle,
|
||||
playlistTitle: "",
|
||||
youtubeId: id,
|
||||
playlistId: "",
|
||||
duration: videoDuration,
|
||||
thumbnailUrl: videoThumbnail,
|
||||
itemType: "song",
|
||||
}
|
||||
return song, nil
|
||||
}
|
||||
|
@ -88,7 +90,13 @@ func (s *Song) Play() {
|
|||
if err := dj.audioStream.Play(fmt.Sprintf("%s/.mumbledj/songs/%s.m4a", dj.homeDir, s.youtubeId), dj.queue.OnItemFinished); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
dj.client.Self().Channel().Send(fmt.Sprintf(NOW_PLAYING_HTML, s.thumbnailUrl, s.youtubeId, s.title, s.duration, s.submitter), false)
|
||||
if s.playlistTitle == "" {
|
||||
dj.client.Self().Channel().Send(fmt.Sprintf(NOW_PLAYING_HTML, s.thumbnailUrl, s.youtubeId, s.title,
|
||||
s.duration, s.submitter), false)
|
||||
} else {
|
||||
dj.client.Self().Channel().Send(fmt.Sprintf(NOW_PLAYING_PLAYLIST_HTML, s.thumbnailUrl, s.youtubeId,
|
||||
s.title, s.duration, s.submitter, s.playlistTitle), false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
24
strings.go
24
strings.go
|
@ -71,6 +71,24 @@ const NOW_PLAYING_HTML = `
|
|||
</table>
|
||||
`
|
||||
|
||||
// Message shown to channel when a new song in a playlist starts playing.
|
||||
const NOW_PLAYING_PLAYLIST_HTML = `
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><img src="%s" width=150 /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><b><a href="http://youtu.be/%s">%s</a> (%s)</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">Added by %s</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">From playlist "%s"</td>
|
||||
</tr>
|
||||
</table>
|
||||
`
|
||||
|
||||
// Message shown to channel when a song is added to the queue by a user.
|
||||
const SONG_ADDED_HTML = `
|
||||
<b>%s</b> has added "%s" to the queue.
|
||||
|
@ -152,3 +170,9 @@ const NEXT_SONG_HTML = `
|
|||
const CURRENT_SONG_HTML = `
|
||||
The song currently playing is "%s", added by <b>%s</b>.
|
||||
`
|
||||
|
||||
// Message shown to users when the currentsong command is issued when a song from a
|
||||
// playlist is playing.
|
||||
const CURRENT_SONG_PLAYLIST_HTML = `
|
||||
The song currently playing is "%s", added <b>%s</b> from the playlist "%s".
|
||||
`
|
||||
|
|
Reference in a new issue