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

Commit

Permalink
api: Fixes to mp3 converter. Sound is not properly filtered.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyah Check committed Sep 28, 2017
1 parent ef46437 commit f203050
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions api/apiconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@ package api
import (
"bufio"
"bytes"
"encoding/gob"
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"os/user"
"path/filepath"

"github.com/Sirupsen/logrus"
"github.com/viert/lame"
)

//Downloads decoded audio stream
func ApiConvertVideo(file, path string, bitrate uint, decStream []stream) error {
func ApiConvertVideo(file, path string, bitrate uint, 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()

data, e := ioutil.ReadAll(resp.Body)
if e != nil {
logrus.Errorf("Error reading video data: %v", e)
}

curDir, er := user.Current()
if er != nil {
Expand All @@ -41,10 +53,8 @@ func ApiConvertVideo(file, path string, bitrate uint, decStream []stream) error
return err
}
defer out.Close()
buf := &bytes.Buffer{}
gob.NewEncoder(buf).Encode(decStream)
reader := bufio.NewReader(buf)

r := bytes.NewReader(data)
reader := bufio.NewReader(r)
audioWriter := lame.NewWriter(out)
audioWriter.Encoder.SetBitrate(int(bitrate))
audioWriter.Encoder.SetQuality(1)
Expand Down
2 changes: 1 addition & 1 deletion api/apidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ 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, path, bitrate, streams)
err = ApiConvertVideo(file, path, bitrate, url)
if err != nil {
logrus.Errorf("Error downloading audio: %v", err)
}
Expand Down

0 comments on commit f203050

Please sign in to comment.