From 06a3c924a3460368ac6e8689e79c2b0e70520d68 Mon Sep 17 00:00:00 2001 From: Nyah Check Date: Tue, 26 Sep 2017 20:22:49 -0600 Subject: [PATCH] api: Bug fixes. --- api/apiconv.go | 7 +++---- api/apidata.go | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/api/apiconv.go b/api/apiconv.go index 0c4d9e0..937d1c4 100644 --- a/api/apiconv.go +++ b/api/apiconv.go @@ -20,7 +20,7 @@ import ( ) //Downloads decoded audio stream -func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) error { +func ApiConvertVideo(file, id, format string, bitrate uint, decStream []stream) error { cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), file) if err := os.MkdirAll(filepath.Dir(file), 666); err != nil { return err @@ -36,7 +36,7 @@ func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) e } buf := &bytes.Buffer{} - gob.NewEncoder(buf).Encode(decVideo) + gob.NewEncoder(buf).Encode(decStream) _, err = exec.LookPath("ffmpeg") if err != nil { return errors.New("ffmpeg not found on system") @@ -48,14 +48,13 @@ func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) e } //Downloads decoded video stream. -func ApiDownloadVideo(path, file, url string, video *RawVideoData) error { +func ApiDownloadVideo(path, file, url string) error { resp, err := http.Get(url) if err != nil { log.Printf("Http.Get\nerror: %s\nURL: %s\n", err, url) return err } defer resp.Body.Close() - video.Vlength = float64(resp.ContentLength) if resp.StatusCode != 200 { log.Printf("Reading Output: status code: '%v'", resp.StatusCode) diff --git a/api/apidata.go b/api/apidata.go index ea6c20f..331cb0c 100644 --- a/api/apidata.go +++ b/api/apidata.go @@ -56,7 +56,7 @@ func GetVideoId(url string) (string, error) { func APIGetVideoStream(format, id, path string, bitrate uint) (err error) { video := new(RawVideoData) //raw video data - var decodedVideo []string //decoded video data + var streams []stream //decoded video data //Get Video Data stream video.VideoId = id @@ -109,7 +109,6 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) { // read and decode streams. streamsList := strings.Split(string(StreamMap[0]), ",") - var streams []stream for streamPos, streamRaw := range streamsList { streamQry, err := url.ParseQuery(streamRaw) if err != nil { @@ -139,7 +138,7 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) { } else { format = ".flv" } - + //create output file name and set path properly. file := video.Title + format file = SpaceMap(file) @@ -147,13 +146,13 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) { url := vstream["url"] + "&signature" + vstream["sig"] logrus.Infof("Downloading file to %s", file) if format == ".mp3" { - err = ApiConvertVideo(file, id, format, bitrate, decodedVideo) + err = ApiConvertVideo(file, id, format, bitrate, streams) if err != nil { logrus.Errorf("Error downloading audio: %v", err) } } else { - if err := ApiDownloadVideo(path, file, url, video); err != nil { + if err := ApiDownloadVideo(path, file, url); err != nil { logrus.Errorf("Error downloading video: %v", err) } }