Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
api: Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyah Check committed Sep 27, 2017
1 parent 54e8a09 commit 06a3c92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 3 additions & 4 deletions api/apiconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions api/apidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -139,21 +138,21 @@ 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)
vstream := streams[0]
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)
}
}
Expand Down

0 comments on commit 06a3c92

Please sign in to comment.