-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (39 loc) · 949 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"io/ioutil"
"log"
"net/http"
"os"
"github.com/Metalscreame/Youtube-to-mp3-converter/usecases/audio"
"github.com/Metalscreame/Youtube-to-mp3-converter/usecases/youtuber"
)
func main() {
log.SetOutput(os.Stdout)
log.Println("Started")
u := youtuber.YouTuberUC{}
fileName, err := u.Download("https://www.youtube.com/watch?v=IY_4M7crOp4")
if err != nil {
log.Fatal(err)
}
mp3 := audio.FFmpegConverter{}
audioFile, err := mp3.ConvertToMp3(fileName)
if err != nil {
log.Fatal(err)
}
log.Printf("Finished %v", audioFile)
port, ok := os.LookupEnv("PORT")
if !ok {
log.Fatal("PORT is required\nFor localhosts setup sys env \"PORT\" as 8080 ")
}
http.HandleFunc("/", Handler)
http.ListenAndServe(":"+port, nil)
}
func Handler(rw http.ResponseWriter, r *http.Request) {
files, err := ioutil.ReadDir("./")
if err != nil {
log.Fatal(err)
}
for _, f := range files {
log.Println(f.Name())
}
}