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

Commit

Permalink
api: Fixed directory path issue
Browse files Browse the repository at this point in the history
Fixes #16
  • Loading branch information
Nyah Check committed Sep 27, 2017
1 parent ead90c0 commit 3c1e6bc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY Makefile Makefile
COPY ytd.go .

RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") \
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ytd .
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o youtube-dl .


FROM alpine:latest
Expand All @@ -29,4 +29,4 @@ COPY --from=0 /go/src/github.com/Ch3ck/youtube-dl .
RUN echo "Image build complete."


ENTRYPOINT [ "youtube-dl" ]
CMD [ "./youtube-dl" ]
2 changes: 1 addition & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var vid []string

func TestApi(t *testing.T) {

path := "$HOME/Downloads/"
path := "test"
for i, table := range tables {
ID, _ := GetVideoId(table.url)
if ID != table.id {
Expand Down
31 changes: 26 additions & 5 deletions api/apiconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,28 @@ import (
"net/http"
"os"
"os/exec"
"os/user"
"path/filepath"
)

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

curDir, er := user.Current()
if er != nil {
return er
}

homeDir := curDir.HomeDir
dir := homeDir + "/Downloads/youtube-dl/" + path
fp := filepath.Join(dir, file)
if err := os.MkdirAll(filepath.Dir(fp), 0775); err != nil {
return err
}
out, err := os.Create(file)

os.Remove(fp)//delete if file exists.
out, err := os.Create(fp)
if err != nil {
return err
}
Expand Down Expand Up @@ -60,11 +72,20 @@ func ApiDownloadVideo(path, file, url string) error {
log.Printf("Reading Output: status code: '%v'", resp.StatusCode)
return errors.New("Non 200 status code received")
}
err = os.MkdirAll(filepath.Dir(file), 666)

curDir, er := user.Current()
if er != nil {
return er
}
homeDir := curDir.HomeDir
dir := homeDir + "/Downloads/youtube-dl/" + path
fp := filepath.Join(dir, file)
err = os.MkdirAll(filepath.Dir(fp), 0775)
if err != nil {
return err
}
out, err := os.Create(file)
os.Remove(fp)//delete if file exists
out, err := os.Create(fp)
if err != nil {
return err
}
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, id, format, bitrate, streams)
err = ApiConvertVideo(file, id, path, bitrate, streams)
if err != nil {
logrus.Errorf("Error downloading audio: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion vendor/golang.org/x/crypto/ssh/terminal/util_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c1e6bc

Please sign in to comment.