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 title string
var songsAdded = 0 var songsAdded = 0
var songArray []Song var songArray []Song
var err error
// Get service to create songs // 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 return err
} }

View file

@ -89,10 +89,10 @@ func (sc SoundCloud) NewRequest(user *gumble.User, url string) ([]Song, error) {
} }
// Add the track // Add the track
if song, err := sc.NewSong(user, apiResponse, offset, nil); err != nil { if song, err := sc.NewSong(user, apiResponse, offset, nil); err == nil {
return nil, err return append(songArray, song), err
} }
return append(songArray, song), err return nil, err
} }
} }
@ -109,16 +109,13 @@ func (sc SoundCloud) NewSong(user *gumble.User, trackData *jsonq.JsonQuery, offs
thumbnail, _ = jsonq.NewQuery(userObj).String("avatar_url") 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{ song := &YouTubeSong{
id: strconv.Itoa(id), id: strconv.Itoa(id),
title: title, title: title,
url: url, url: url,
thumbnail: thumbnail, thumbnail: thumbnail,
submitter: user, submitter: user,
duration: duration, duration: durationMS / 1000,
offset: offset, offset: offset,
format: "mp3", format: "mp3",
playlist: playlist, playlist: playlist,

View file

@ -73,7 +73,7 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) ([]Song, error) {
} }
} }
} else { } else {
return "", err return nil, err
} }
} }
@ -90,8 +90,8 @@ func (yt YouTube) NewSong(user *gumble.User, id, offset string, playlist Playlis
title: title, title: title,
id: id, id: id,
url: "https://youtu.be/" + id, url: "https://youtu.be/" + id,
offset: yt.parseTime(offset).Seconds(), offset: int(yt.parseTime(offset).Seconds()),
duration: yt.parseTime(duration).Seconds(), duration: int(yt.parseTime(duration).Seconds()),
thumbnail: thumbnail, thumbnail: thumbnail,
format: "m4a", format: "m4a",
skippers: make([]string, 0), 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. // 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 apiResponse *jsonq.JsonQuery
var songArray []Song
var err error var err error
// Retrieve title of playlist // 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")) 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++ { for i := 0; i < numVideos; i++ {
index := strconv.Itoa(i) index := strconv.Itoa(i)
videoID, _ := apiResponse.String("items", index, "snippet", "resourceId", "videoId") 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" "net/http"
"os" "os"
"os/exec" "os/exec"
"strconv"
"time" "time"
"github.com/layeh/gumble/gumble" "github.com/layeh/gumble/gumble"
@ -27,7 +28,7 @@ type YouTubeSong struct {
title string title string
thumbnail string thumbnail string
submitter *gumble.User submitter *gumble.User
duration string duration int
url string url string
offset int offset int
format string format string
@ -168,7 +169,8 @@ func (dl *YouTubeSong) Filename() string {
// Duration returns the duration of the Song. // Duration returns the duration of the Song.
func (dl *YouTubeSong) Duration() string { 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. // Thumbnail returns the thumbnail URL for the Song.