Checking output of youtube-dl when downloading
This commit is contained in:
parent
b3b1d9c3f4
commit
99b6abdd2c
|
@ -44,7 +44,7 @@ func (sc SoundCloud) NewRequest(user *gumble.User, url string) (string, error) {
|
|||
// PLAYLIST
|
||||
if dj.HasPermission(user.Name, dj.conf.Permissions.AdminAddPlaylists) {
|
||||
// Check duration of playlist
|
||||
// duration, _ := apiResponse.Int("duration")
|
||||
duration, _ := apiResponse.Int("duration")
|
||||
|
||||
// Create playlist
|
||||
title, _ := apiResponse.String("title")
|
||||
|
@ -56,7 +56,7 @@ func (sc SoundCloud) NewRequest(user *gumble.User, url string) (string, error) {
|
|||
|
||||
// Add all tracks
|
||||
for _, t := range tracks {
|
||||
sc.NewSong(user.Name, jsonq.NewQuery(t), playlist)
|
||||
sc.NewSong(user, jsonq.NewQuery(t), playlist)
|
||||
}
|
||||
if err == nil {
|
||||
return playlist.Title(), nil
|
||||
|
@ -69,12 +69,12 @@ func (sc SoundCloud) NewRequest(user *gumble.User, url string) (string, error) {
|
|||
}
|
||||
} else {
|
||||
// SONG
|
||||
return sc.NewSong(user.Name, apiResponse, nil)
|
||||
return sc.NewSong(user, apiResponse, nil)
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a track and adds to the queue
|
||||
func (sc SoundCloud) NewSong(user string, trackData *jsonq.JsonQuery, playlist Playlist) (string, error) {
|
||||
func (sc SoundCloud) NewSong(user *gumble.User, trackData *jsonq.JsonQuery, playlist Playlist) (string, error) {
|
||||
title, err := trackData.String("title")
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -83,7 +83,7 @@ func (sc SoundCloud) NewSong(user string, trackData *jsonq.JsonQuery, playlist P
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
duration, err := trackData.String("duration")
|
||||
duration, err := trackData.Int("duration")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -91,10 +91,15 @@ func (sc SoundCloud) NewSong(user string, trackData *jsonq.JsonQuery, playlist P
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
url, err := trackData.String("permalink_url")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
song := &YouTubeDLSong{
|
||||
id: id,
|
||||
title: title,
|
||||
url: url,
|
||||
thumbnail: thumbnail,
|
||||
submitter: user,
|
||||
duration: duration,
|
||||
|
|
|
@ -60,7 +60,7 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) (string, error) {
|
|||
if re.MatchString(url) {
|
||||
if dj.HasPermission(user.Name, dj.conf.Permissions.AdminAddPlaylists) {
|
||||
shortURL = re.FindStringSubmatch(url)[1]
|
||||
playlist, err := yt.NewPlaylist(user.Name, shortURL)
|
||||
playlist, err := yt.NewPlaylist(user, shortURL)
|
||||
return playlist.Title(), err
|
||||
} else {
|
||||
return "", errors.New("NO_PLAYLIST_PERMISSION")
|
||||
|
@ -72,7 +72,7 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) (string, error) {
|
|||
if len(matches[0]) == 3 {
|
||||
startOffset = matches[0][2]
|
||||
}
|
||||
song, err := yt.NewSong(user.Name, shortURL, startOffset, nil)
|
||||
song, err := yt.NewSong(user, shortURL, startOffset, nil)
|
||||
if err == nil {
|
||||
return song.Title(), nil
|
||||
} else {
|
||||
|
@ -87,7 +87,7 @@ func (yt YouTube) NewRequest(user *gumble.User, url string) (string, error) {
|
|||
|
||||
// NewSong gathers the metadata for a song extracted from a YouTube video, and returns
|
||||
// the song.
|
||||
func (yt YouTube) NewSong(user, id, offset string, playlist Playlist) (Song, error) {
|
||||
func (yt YouTube) NewSong(user *gumble.User, id, offset string, playlist Playlist) (Song, error) {
|
||||
var apiResponse *jsonq.JsonQuery
|
||||
var err error
|
||||
url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=%s&key=%s",
|
||||
|
@ -181,12 +181,11 @@ func (yt YouTube) NewSong(user, id, offset string, playlist Playlist) (Song, err
|
|||
}
|
||||
|
||||
// NewPlaylist gathers the metadata for a YouTube playlist and returns it.
|
||||
func (yt YouTube) NewPlaylist(user, id string) (Playlist, error) {
|
||||
func (yt YouTube) NewPlaylist(user *gumble.User, id string) (Playlist, error) {
|
||||
var apiResponse *jsonq.JsonQuery
|
||||
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"))
|
||||
url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=%s&key=%s", id, os.Getenv("YOUTUBE_API_KEY"))
|
||||
if apiResponse, err = PerformGetRequest(url); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ type YouTubeDLSong struct {
|
|||
id string
|
||||
title string
|
||||
thumbnail string
|
||||
submitter string
|
||||
duration string
|
||||
submitter *gumble.User
|
||||
duration int
|
||||
url string
|
||||
offset int
|
||||
playlist Playlist
|
||||
|
@ -39,7 +39,7 @@ func (dl *YouTubeDLSong) Download() error {
|
|||
|
||||
// Checks to see if song is already downloaded
|
||||
if _, err := os.Stat(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, dl.Filename())); os.IsNotExist(err) {
|
||||
cmd := exec.Command("youtube-dl", "--output", fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, dl.Filename()), "--format m4a", "--prefer-ffmpeg", "--", dl.ID())
|
||||
cmd := exec.Command("youtube-dl", "--output", fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, dl.Filename()), "--format m4a", "--prefer-ffmpeg", "--", dl.url)
|
||||
err = cmd.Run()
|
||||
if err == nil {
|
||||
if dj.conf.Cache.Enabled {
|
||||
|
@ -51,6 +51,8 @@ func (dl *YouTubeDLSong) Download() error {
|
|||
for s := range cmd.Args {
|
||||
Verbose("youtube-dl args: " + cmd.Args[s])
|
||||
}
|
||||
b, _ := ioutil.ReadAll(cmd.Stdout)
|
||||
Verbose(string(b))
|
||||
return errors.New("Song download failed.")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue