From 02b9778cc272d8aeba35fbe0b744e53ba3815461 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Sat, 26 Sep 2015 15:09:07 +0100 Subject: [PATCH] Fixing build errors --- service.go | 3 ++- service_soundcloud.go | 11 ++++------- service_youtube.go | 15 +++++++++------ youtube_dl.go | 6 ++++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/service.go b/service.go index 347d79d..32a36c1 100644 --- a/service.go +++ b/service.go @@ -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 } diff --git a/service_soundcloud.go b/service_soundcloud.go index aaac378..2ed1570 100644 --- a/service_soundcloud.go +++ b/service_soundcloud.go @@ -89,10 +89,10 @@ 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 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") } - 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, diff --git a/service_youtube.go b/service_youtube.go index 71622c0..e354d9d 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -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 } diff --git a/youtube_dl.go b/youtube_dl.go index 983874a..64d60b1 100644 --- a/youtube_dl.go +++ b/youtube_dl.go @@ -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.