Fixing build errors

This commit is contained in:
MichaelOultram 2015-09-26 15:09:07 +01:00
parent 1a8c1ce4d0
commit 02b9778cc2
4 changed files with 19 additions and 16 deletions

View file

@ -75,9 +75,10 @@ func FindServiceAndAdd(user *gumble.User, url string) error {
var title string
var songsAdded = 0
var songArray []Song
var err error
// Get service to create songs
if songArray, err := urlService.NewRequest(user, url); err != nil {
if songArray, err = urlService.NewRequest(user, url); err != nil {
return err
}

View file

@ -89,11 +89,11 @@ func (sc SoundCloud) NewRequest(user *gumble.User, url string) ([]Song, error) {
}
// Add the track
if song, err := sc.NewSong(user, apiResponse, offset, nil); err != nil {
return nil, err
}
if song, err := sc.NewSong(user, apiResponse, offset, nil); err == nil {
return append(songArray, song), err
}
return nil, err
}
}
// NewSong creates a track and adds to the queue
@ -109,16 +109,13 @@ func (sc SoundCloud) NewSong(user *gumble.User, trackData *jsonq.JsonQuery, offs
thumbnail, _ = jsonq.NewQuery(userObj).String("avatar_url")
}
timeDuration, _ := time.ParseDuration(strconv.Itoa(durationMS/1000) + "s")
duration := timeDuration.String() //Lazy way to display time
song := &YouTubeSong{
id: strconv.Itoa(id),
title: title,
url: url,
thumbnail: thumbnail,
submitter: user,
duration: duration,
duration: durationMS / 1000,
offset: offset,
format: "mp3",
playlist: playlist,

View file

@ -73,7 +73,7 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) ([]Song, error) {
}
}
} else {
return "", err
return nil, err
}
}
@ -90,8 +90,8 @@ func (yt YouTube) NewSong(user *gumble.User, id, offset string, playlist Playlis
title: title,
id: id,
url: "https://youtu.be/" + id,
offset: yt.parseTime(offset).Seconds(),
duration: yt.parseTime(duration).Seconds(),
offset: int(yt.parseTime(offset).Seconds()),
duration: int(yt.parseTime(duration).Seconds()),
thumbnail: thumbnail,
format: "m4a",
skippers: make([]string, 0),
@ -140,8 +140,9 @@ func (yt YouTube) parseTime(duration string) time.Duration {
}
// NewPlaylist gathers the metadata for a YouTube playlist and returns it.
func (yt YouTube) NewPlaylist(user *gumble.User, id string) (Playlist, error) {
func (yt YouTube) NewPlaylist(user *gumble.User, id string) ([]Song, error) {
var apiResponse *jsonq.JsonQuery
var songArray []Song
var err error
// Retrieve title of playlist
url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=%s&key=%s", id, os.Getenv("YOUTUBE_API_KEY"))
@ -169,7 +170,9 @@ func (yt YouTube) NewPlaylist(user *gumble.User, id string) (Playlist, error) {
for i := 0; i < numVideos; i++ {
index := strconv.Itoa(i)
videoID, _ := apiResponse.String("items", index, "snippet", "resourceId", "videoId")
yt.NewSong(user, videoID, "", playlist)
if song, err := yt.NewSong(user, videoID, "", playlist); err == nil {
songArray = append(songArray, song)
}
return playlist, nil
}
return songArray, nil
}

View file

@ -15,6 +15,7 @@ import (
"net/http"
"os"
"os/exec"
"strconv"
"time"
"github.com/layeh/gumble/gumble"
@ -27,7 +28,7 @@ type YouTubeSong struct {
title string
thumbnail string
submitter *gumble.User
duration string
duration int
url string
offset int
format string
@ -168,7 +169,8 @@ func (dl *YouTubeSong) Filename() string {
// Duration returns the duration of the Song.
func (dl *YouTubeSong) Duration() string {
return dl.duration
timeDuration, _ := time.ParseDuration(stvconv.Iota(dl.duration) + "s")
return timeDuration.String()
}
// Thumbnail returns the thumbnail URL for the Song.