Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
api: Debugging fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyah Check committed Sep 27, 2017
1 parent 1ad1ac1 commit 54e8a09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
13 changes: 6 additions & 7 deletions api/apiconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import (
"path/filepath"
)

//Converts Decoded Video file to mp3 by default with 123 bitrate or to
//flv if otherwise specified and downloads to system
//Downloads decoded audio stream
func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) error {
cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), file)
if err := os.MkdirAll(filepath.Dir(file), 666); err != nil {
Expand All @@ -42,10 +41,8 @@ func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) e
if err != nil {
return errors.New("ffmpeg not found on system")
}

cmd.Start()
//logrus.Infof("Downloading mp3 file to disk %s", file)
stdin.Write(buf.Bytes()) //download file.
stdin.Write(buf.Bytes())
out.Write(buf.Bytes())
return nil
}
Expand All @@ -61,8 +58,8 @@ func ApiDownloadVideo(path, file, url string, video *RawVideoData) error {
video.Vlength = float64(resp.ContentLength)

if resp.StatusCode != 200 {
log.Printf("Reading Output: status code : '%v'", resp.StatusCode)
return errors.New("non 200 status code received")
log.Printf("Reading Output: status code: '%v'", resp.StatusCode)
return errors.New("Non 200 status code received")
}
err = os.MkdirAll(filepath.Dir(file), 666)
if err != nil {
Expand All @@ -72,6 +69,8 @@ func ApiDownloadVideo(path, file, url string, video *RawVideoData) error {
if err != nil {
return err
}

//saving downloaded file.
_, err = io.Copy(out, resp.Body)
if err != nil {
log.Println("Download Error: ", err)
Expand Down
23 changes: 5 additions & 18 deletions api/apidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ type RawVideoData struct {
URLEncodedFmtStreamMap []stream `json:"url_encoded_fmt_stream_map"`
VideoId string
VideoInfo string
Vlength float64
dpercent chan int64
}

func (v *RawVideoData) Write(b []byte) (n int, err error) {
n = len(b)
totalbytes, dlevel := 0.0, 0.0
v.Vlength = totalbytes + float64(n)
curPercent := ((totalbytes / v.Vlength) * 100)
if (dlevel <= curPercent) && (dlevel < 100) {
dlevel++
v.dpercent <- int64(dlevel)
}
return
}

//gets the Video ID from youtube url
Expand Down Expand Up @@ -148,11 +134,12 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) {

video.URLEncodedFmtStreamMap = streams
//Download Video stream to file
if format == "" {
format = ".flv"
} else {
if format == "mp3" || format == ".mp3" {
format = ".mp3"
} else {
format = ".flv"
}

//create output file name and set path properly.
file := video.Title + format
file = SpaceMap(file)
Expand All @@ -165,7 +152,7 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) {
logrus.Errorf("Error downloading audio: %v", err)
}

} else { //defaults to flv format for video files.)
} else {
if err := ApiDownloadVideo(path, file, url, video); err != nil {
logrus.Errorf("Error downloading video: %v", err)
}
Expand Down

0 comments on commit 54e8a09

Please sign in to comment.