-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.go
48 lines (38 loc) · 880 Bytes
/
converter.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
package main
import (
"os"
"os/exec"
"math/rand"
"time"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func convert(name string) string{
var outDirectory, outputFile,inputDirectory string
outputFile = RandStringBytesRmndr(7) + ".mp3"
outDirectory = "downloads/"
inputDirectory = "uploads/"
_,error := exec.Command("ffmpeg",
"-i",
inputDirectory + name ,
"-filter:a",
"atempo=1.0",
"-filter:a",
"asetrate=60000",
outDirectory + outputFile).CombinedOutput()
if error != nil{
return ""
}
os.Remove(inputDirectory + name )
return outputFile
}
func init() {
rand.Seed(time.Now().UnixNano())
}
//RandStringBytesRmndr generates random string
func RandStringBytesRmndr(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Int63()%int64(len(letterBytes))]
}
return string(b)
}