From 1bf99b1da47a1332bf4094a083925791d70510ae Mon Sep 17 00:00:00 2001 From: Nyah Check Date: Sat, 16 Sep 2017 16:06:11 -0600 Subject: [PATCH] ytd: Compilation fixes. --- api/apiconv.go | 18 +++++++++--------- api/apidata.go | 10 +++------- cmd/ytd/ytd.go | 9 +++++---- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/api/apiconv.go b/api/apiconv.go index 50fabee..7bab3dc 100644 --- a/api/apiconv.go +++ b/api/apiconv.go @@ -7,23 +7,23 @@ package api import ( - "errors" - "flag" "fmt" "io" + "net/http" "os" "os/exec" "path/filepath" - "strings" + + "github.com/Sirupsen/logrus" ) //Converts Decoded Video file to mp3 by default with 123 bitrate or to //flv if otherwise specified and downloads to system -func APIConvertVideo(file string, int bitrate, id string, decVideo []byte) error { - cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), path) +func APIConvertVideo(file string, bitrate int, id string, decVideo []byte) error { + cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), file) stdin, err := cmd.StdinPipe() if err != nil { - logrus.Fatalf(err) + return err } if filepath.Ext(file) != ".mp3" && filepath.Ext(file) != ".flv" { file = file[:len(file)-4] + ".mp3" @@ -38,11 +38,11 @@ func APIConvertVideo(file string, int bitrate, id string, decVideo []byte) error } cmd.Start() - logrus.Infof("Downloading mp3 file to disk %s", path) + logrus.Infof("Downloading mp3 file to disk %s", file) cmd.Write(decVideo) //download file. } else { - cmd, err = os.Create(path) + cmd, err = os.Create(file) if err != nil { logrus.Error("Unable to download video file.", err) } @@ -54,7 +54,7 @@ func APIConvertVideo(file string, int bitrate, id string, decVideo []byte) error } //Downloads decoded video stream. -func APIDownloadVideo(videoUrl, cmd io.Writer) error { +func apiDownloadVideo(videoUrl, cmd io.Writer) error { logrus.Infof("Downloading file stream") resp, err := http.Get(url) diff --git a/api/apidata.go b/api/apidata.go index cfcd67a..849a294 100644 --- a/api/apidata.go +++ b/api/apidata.go @@ -7,14 +7,10 @@ package api import ( - "bytes" "errors" - "fmt" - "io" "io/ioutil" "net/http" "net/url" - "os" "strings" "github.com/Sirupsen/logrus" @@ -37,7 +33,7 @@ type RawVideoData struct { } //gets the Video ID from youtube url -func getVideoId(url string) (string, error) { +func GetVideoId(url string) (string, error) { if !strings.Contains(url, "youtube.com") { return nil, errors.New("Invalid Youtube link") } @@ -53,8 +49,8 @@ func getVideoId(url string) (string, error) { //Gets Video Info, Decode Video Info from a Video ID. func APIGetVideoStream(id string, video RawVideoData) (videoData []byte, err error) { - video := new(RawVideoData) //raw video data - var decodedVideo []string //decoded video data + video = new(RawVideoData) //raw video data + var decodedVideo []string //decoded video data //Get Video Data stream videoUrl := videoExtractor + id diff --git a/cmd/ytd/ytd.go b/cmd/ytd/ytd.go index 1e98b13..8308b96 100644 --- a/cmd/ytd/ytd.go +++ b/cmd/ytd/ytd.go @@ -11,6 +11,7 @@ import ( "fmt" "os" + "github.com/Ch3ck/ytd/api" "github.com/Sirupsen/logrus" ) @@ -54,7 +55,7 @@ func init() { func main() { var ID string - var rawVideo RawVideoData + var rawVideo api.RawVideoData if len(os.Args) == 1 { usageAndExit(BANNER, -1) } @@ -62,9 +63,9 @@ func main() { //Get Video Id if id == "" { url := os.Args[1] - ID, _ = getVideoId(id) + ID, _ = api.GetVideoId(id) } else { - ID, _ = getVideoId(id) + ID, _ = api.GetVideoId(id) } //Extract Video data and decode @@ -83,7 +84,7 @@ func main() { file = file + ".flv" } - err = APIConvertVideo(file, bitrate, ID, video) + err = api.APIConvertVideo(file, bitrate, ID, video) if err != nil { logrus.Errorf("Error downloading video: %v", err) }