Fixing build issues

This commit is contained in:
MichaelOultram 2015-09-26 16:04:39 +01:00
parent df35d03ebe
commit a7f1055ab5
3 changed files with 17 additions and 9 deletions

View file

@ -37,6 +37,7 @@ type Song interface {
Title() string Title() string
ID() string ID() string
Filename() string Filename() string
DurationInt() int
DurationString() string DurationString() string
Thumbnail() string Thumbnail() string
Playlist() Playlist Playlist() Playlist
@ -91,7 +92,7 @@ func FindServiceAndAdd(user *gumble.User, url string) error {
oldLength := dj.queue.Len() oldLength := dj.queue.Len()
for _, song := range songArray { for _, song := range songArray {
// Check song is not too long // Check song is not too long
time, _ := time.ParseDuration(song.Duration) time, _ := time.ParseDuration(song.DurationInt())
if dj.conf.General.MaxSongDuration == 0 || int(time.Seconds()) <= dj.conf.General.MaxSongDuration { if dj.conf.General.MaxSongDuration == 0 || int(time.Seconds()) <= dj.conf.General.MaxSongDuration {
if !isNil(song.Playlist()) { if !isNil(song.Playlist()) {
title = song.Playlist().Title() title = song.Playlist().Title()

View file

@ -55,8 +55,7 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) ([]Song, error) {
if re, err := regexp.Compile(youtubePlaylistPattern); err == nil { if re, err := regexp.Compile(youtubePlaylistPattern); err == nil {
if re.MatchString(url) { if re.MatchString(url) {
shortURL = re.FindStringSubmatch(url)[1] shortURL = re.FindStringSubmatch(url)[1]
playlist, err := yt.NewPlaylist(user, shortURL) return yt.NewPlaylist(user, shortURL)
return playlist.Title(), err
} else { } else {
re = RegexpFromURL(url, youtubeVideoPatterns) re = RegexpFromURL(url, youtubeVideoPatterns)
matches := re.FindAllStringSubmatch(url, -1) matches := re.FindAllStringSubmatch(url, -1)
@ -136,7 +135,8 @@ func (yt YouTube) parseTime(duration string) time.Duration {
} else { } else {
totalSeconds = 0 totalSeconds = 0
} }
return time.ParseDuration(strconv.Itoa(totalSeconds) + "s") output, _ := time.ParseDuration(strconv.Itoa(int(totalSeconds)) + "s")
return output
} }
// NewPlaylist gathers the metadata for a YouTube playlist and returns it. // NewPlaylist gathers the metadata for a YouTube playlist and returns it.

View file

@ -15,6 +15,8 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"strconv"
"strings"
"time" "time"
"github.com/jmoiron/jsonq" "github.com/jmoiron/jsonq"
@ -28,7 +30,7 @@ type YouTubeSong struct {
title string title string
thumbnail string thumbnail string
submitter *gumble.User submitter *gumble.User
Duration int duration int
url string url string
offset int offset int
format string format string
@ -74,7 +76,7 @@ func (dl *YouTubeSong) Download() error {
} }
// Play plays the song. Once the song is playing, a notification is displayed in a text message that features the song // Play plays the song. Once the song is playing, a notification is displayed in a text message that features the song
// thumbnail, URL, title, Duration, and submitter. // thumbnail, URL, title, duration, and submitter.
func (dl *YouTubeSong) Play() { func (dl *YouTubeSong) Play() {
if dl.offset != 0 { if dl.offset != 0 {
offsetDuration, _ := time.ParseDuration(fmt.Sprintf("%ds", dl.offset)) offsetDuration, _ := time.ParseDuration(fmt.Sprintf("%ds", dl.offset))
@ -85,7 +87,7 @@ func (dl *YouTubeSong) Play() {
panic(err) panic(err)
} else { } else {
message := `<table><tr><td align="center"><img src="%s" width=150 /></td></tr><tr><td align="center"><b><a href="%s">%s</a> (%s)</b></td></tr><tr><td align="center">Added by %s</td></tr>` message := `<table><tr><td align="center"><img src="%s" width=150 /></td></tr><tr><td align="center"><b><a href="%s">%s</a> (%s)</b></td></tr><tr><td align="center">Added by %s</td></tr>`
message = fmt.Sprintf(message, dl.thumbnail, dl.url, dl.title, dl.Duration, dl.submitter.Name) message = fmt.Sprintf(message, dl.thumbnail, dl.url, dl.title, dl.duration, dl.submitter.Name)
if !isNil(dl.playlist) { if !isNil(dl.playlist) {
message = fmt.Sprintf(message+`<tr><td align="center">From playlist "%s"</td></tr>`, dl.playlist.Title()) message = fmt.Sprintf(message+`<tr><td align="center">From playlist "%s"</td></tr>`, dl.playlist.Title())
} }
@ -167,9 +169,14 @@ func (dl *YouTubeSong) Filename() string {
return dl.id + "." + dl.format return dl.id + "." + dl.format
} }
// Duration returns the Duration of the Song. // DurationInt returns number of seconds for the Song.
func (dl *YouTubeSong) DurationInt() string {
return duration
}
// DurationString returns the pretty version of duration for the Song.
func (dl *YouTubeSong) DurationString() string { func (dl *YouTubeSong) DurationString() string {
timeDuration, _ := time.ParseDuration(stvconv.Iota(dl.Duration) + "s") timeDuration, _ := time.ParseDuration(strconv.Iota(dl.duration) + "s")
return timeDuration.String() return timeDuration.String()
} }