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 file format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyah Check committed Sep 26, 2017
1 parent 0b253d7 commit d8c0fe1
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions api/apidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"net/url"
"strings"
"unicode"

"github.com/Sirupsen/logrus"
)
Expand All @@ -36,15 +37,15 @@ type RawVideoData struct {
VideoId string
VideoInfo string
Vlength float64
dpercent chan int64
dpercent chan int64
}

func (v *RawVideoData) Write(b []byte) (n int, err error) {
n = len(b)
totalbytes , dlevel := 0.0, 0.0
totalbytes, dlevel := 0.0, 0.0
v.Vlength = totalbytes + float64(n)
curPercent := ((totalbytes / v.Vlength) * 100)
if (dlevel <= curPercent) && (dlevel < 100) {
if (dlevel <= curPercent) && (dlevel < 100) {
dlevel++
v.dpercent <- int64(dlevel)
}
Expand Down Expand Up @@ -146,27 +147,39 @@ func APIGetVideoStream(format, id, path string, bitrate uint) (err error) {
}

video.URLEncodedFmtStreamMap = streams

//create output file name and set path properly.
file := video.Title + video.Author

//Download Video stream to file
if format == "" {
format = ".flv"
} else {
format = ".mp3"
}
//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" {
file = file + ".mp3"
if format == ".mp3" {
err = ApiConvertVideo(file, id, format, bitrate, decodedVideo)
if err != nil {
logrus.Errorf("Error downloading audio: %v", err)
}

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

return nil
}

//remove whitespaces in filename
func SpaceMap(str string) string {
return strings.Map(func(r rune) rune {
if unicode.IsSpace(r) {
return -1
}
return r
}, str)
}

0 comments on commit d8c0fe1

Please sign in to comment.