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

Commit

Permalink
api, cmd: Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyah Check committed Sep 16, 2017
1 parent 383f33e commit 6c86f74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/apiconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

//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 {
func APIConvertVideo(file string, int bitrate, id string, decVideo []byte) error {
cmd := exec.Command("ffmpeg", "-i", "-", "-ab", fmt.Sprintf("%dk", bitrate), path)
stdin, err := cmd.StdinPipe()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/apidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type RawVideoData struct {

//gets the Video ID from youtube url
func getVideoId(url string) (string, error) {
if !strings.Contains( url, "youtube.com") {
if !strings.Contains(url, "youtube.com") {
return nil, errors.New("Invalid Youtube link")
}
s := strings.Split(url, "?v=")
Expand Down
25 changes: 12 additions & 13 deletions cmd/ytd/ytd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ import (
const (

//BANNER for ytd which prints the help info
BANNER = "ytd -id 'videoId' -format mp3 -bitrate 123 -path ~/Downloads/ videoUrl"%s\n"
BANNER = "ytd -id 'videoId' -format mp3 -bitrate 123 -path ~/Downloads/ videoUrl%s\n"
//VERSION which prints the ytd version.
VERSION = "v0.1"
)

var (

id string
id string
version bool
format string
path string
format string
path string
bitrate uint
file string
file string
)

func init() {
Expand All @@ -56,38 +55,38 @@ func init() {
func main() {
var ID string
var rawVideo RawVideoData
if len(os.Args) == 1) {
if len(os.Args) == 1 {
usageAndExit(BANNER, -1)
}

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

//Extract Video data and decode
video, err := api.APIGetVideoStream(ID, rawVideo)
if err != nil {
logrus.Errorf("Error decoding Video stream: %v", err)
}

//Convert and Download video data
//create output file name and set path properly.
file = path + video["title"] + video["author"]
if format == "mp3" {
file = file + ".mp3"

} else { //defaults to flv format for video files.)
file = file + ".flv"
}

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

func usageAndExit(message string, exitCode int) {
Expand Down

0 comments on commit 6c86f74

Please sign in to comment.