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

Commit 06a3c92

Browse files
author
Nyah Check
committed
api: Bug fixes.
1 parent 54e8a09 commit 06a3c92

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

api/apiconv.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
//Downloads decoded audio stream
23-
func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) error {
23+
func ApiConvertVideo(file, id, format string, bitrate uint, decStream []stream) error {
2424
cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), file)
2525
if err := os.MkdirAll(filepath.Dir(file), 666); err != nil {
2626
return err
@@ -36,7 +36,7 @@ func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) e
3636
}
3737

3838
buf := &bytes.Buffer{}
39-
gob.NewEncoder(buf).Encode(decVideo)
39+
gob.NewEncoder(buf).Encode(decStream)
4040
_, err = exec.LookPath("ffmpeg")
4141
if err != nil {
4242
return errors.New("ffmpeg not found on system")
@@ -48,14 +48,13 @@ func ApiConvertVideo(file, id, format string, bitrate uint, decVideo []string) e
4848
}
4949

5050
//Downloads decoded video stream.
51-
func ApiDownloadVideo(path, file, url string, video *RawVideoData) error {
51+
func ApiDownloadVideo(path, file, url string) error {
5252
resp, err := http.Get(url)
5353
if err != nil {
5454
log.Printf("Http.Get\nerror: %s\nURL: %s\n", err, url)
5555
return err
5656
}
5757
defer resp.Body.Close()
58-
video.Vlength = float64(resp.ContentLength)
5958

6059
if resp.StatusCode != 200 {
6160
log.Printf("Reading Output: status code: '%v'", resp.StatusCode)

api/apidata.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func GetVideoId(url string) (string, error) {
5656
func APIGetVideoStream(format, id, path string, bitrate uint) (err error) {
5757

5858
video := new(RawVideoData) //raw video data
59-
var decodedVideo []string //decoded video data
59+
var streams []stream //decoded video data
6060

6161
//Get Video Data stream
6262
video.VideoId = id
@@ -109,7 +109,6 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) {
109109

110110
// read and decode streams.
111111
streamsList := strings.Split(string(StreamMap[0]), ",")
112-
var streams []stream
113112
for streamPos, streamRaw := range streamsList {
114113
streamQry, err := url.ParseQuery(streamRaw)
115114
if err != nil {
@@ -139,21 +138,21 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) {
139138
} else {
140139
format = ".flv"
141140
}
142-
141+
143142
//create output file name and set path properly.
144143
file := video.Title + format
145144
file = SpaceMap(file)
146145
vstream := streams[0]
147146
url := vstream["url"] + "&signature" + vstream["sig"]
148147
logrus.Infof("Downloading file to %s", file)
149148
if format == ".mp3" {
150-
err = ApiConvertVideo(file, id, format, bitrate, decodedVideo)
149+
err = ApiConvertVideo(file, id, format, bitrate, streams)
151150
if err != nil {
152151
logrus.Errorf("Error downloading audio: %v", err)
153152
}
154153

155154
} else {
156-
if err := ApiDownloadVideo(path, file, url, video); err != nil {
155+
if err := ApiDownloadVideo(path, file, url); err != nil {
157156
logrus.Errorf("Error downloading video: %v", err)
158157
}
159158
}

0 commit comments

Comments
 (0)