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

Commit

Permalink
ytd: Compilation fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyah Check committed Sep 16, 2017
1 parent 4848d92 commit 1bf99b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
18 changes: 9 additions & 9 deletions api/apiconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
package api

import (
"errors"
"flag"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/Sirupsen/logrus"
)

//Converts Decoded Video file to mp3 by default with 123 bitrate or to
//flv if otherwise specified and downloads to system
func APIConvertVideo(file string, int bitrate, id string, decVideo []byte) error {
cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), path)
func APIConvertVideo(file string, bitrate int, id string, decVideo []byte) error {
cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), file)
stdin, err := cmd.StdinPipe()
if err != nil {
logrus.Fatalf(err)
return err
}
if filepath.Ext(file) != ".mp3" && filepath.Ext(file) != ".flv" {
file = file[:len(file)-4] + ".mp3"
Expand All @@ -38,11 +38,11 @@ func APIConvertVideo(file string, int bitrate, id string, decVideo []byte) error
}

cmd.Start()
logrus.Infof("Downloading mp3 file to disk %s", path)
logrus.Infof("Downloading mp3 file to disk %s", file)
cmd.Write(decVideo) //download file.

} else {
cmd, err = os.Create(path)
cmd, err = os.Create(file)
if err != nil {
logrus.Error("Unable to download video file.", err)
}
Expand All @@ -54,7 +54,7 @@ func APIConvertVideo(file string, int bitrate, id string, decVideo []byte) error
}

//Downloads decoded video stream.
func APIDownloadVideo(videoUrl, cmd io.Writer) error {
func apiDownloadVideo(videoUrl, cmd io.Writer) error {
logrus.Infof("Downloading file stream")

resp, err := http.Get(url)
Expand Down
10 changes: 3 additions & 7 deletions api/apidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
package api

import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"

"github.com/Sirupsen/logrus"
Expand All @@ -37,7 +33,7 @@ type RawVideoData struct {
}

//gets the Video ID from youtube url
func getVideoId(url string) (string, error) {
func GetVideoId(url string) (string, error) {
if !strings.Contains(url, "youtube.com") {
return nil, errors.New("Invalid Youtube link")
}
Expand All @@ -53,8 +49,8 @@ func getVideoId(url string) (string, error) {
//Gets Video Info, Decode Video Info from a Video ID.
func APIGetVideoStream(id string, video RawVideoData) (videoData []byte, err error) {

video := new(RawVideoData) //raw video data
var decodedVideo []string //decoded video data
video = new(RawVideoData) //raw video data
var decodedVideo []string //decoded video data

//Get Video Data stream
videoUrl := videoExtractor + id
Expand Down
9 changes: 5 additions & 4 deletions cmd/ytd/ytd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"

"github.com/Ch3ck/ytd/api"
"github.com/Sirupsen/logrus"
)

Expand Down Expand Up @@ -54,17 +55,17 @@ func init() {

func main() {
var ID string
var rawVideo RawVideoData
var rawVideo api.RawVideoData
if len(os.Args) == 1 {
usageAndExit(BANNER, -1)
}

//Get Video Id
if id == "" {
url := os.Args[1]
ID, _ = getVideoId(id)
ID, _ = api.GetVideoId(id)
} else {
ID, _ = getVideoId(id)
ID, _ = api.GetVideoId(id)
}

//Extract Video data and decode
Expand All @@ -83,7 +84,7 @@ func main() {
file = file + ".flv"
}

err = APIConvertVideo(file, bitrate, ID, video)
err = api.APIConvertVideo(file, bitrate, ID, video)
if err != nil {
logrus.Errorf("Error downloading video: %v", err)
}
Expand Down

0 comments on commit 1bf99b1

Please sign in to comment.