-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_stream.go
More file actions
39 lines (37 loc) · 1.04 KB
/
request_stream.go
File metadata and controls
39 lines (37 loc) · 1.04 KB
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
package main
import (
"os/exec"
"database/sql"
"path"
"strconv"
_ "github.com/mxk/go-sqlite/sqlite3"
)
func (connection *ClientConnection) stream() {
id,error := strconv.Atoi( connection.parameters["id"] )
if error != nil {
connection.responseError( 10 )
return
}
db,error := sql.Open( "sqlite3", settings.Database )
if error != nil {
println( "Error opening database", error )
connection.responseError( 0 )
return
}
defer db.Close()
songRow := db.QueryRow( "SELECT songPath,folderRoot FROM songs,folders WHERE songKey=? AND folderKey=songParent;", id )
var songPath string
var folderRoot string
error = songRow.Scan( &songPath, &folderRoot )
if error != nil {
println( "Error reading song path from database", error.Error() )
connection.responseError( 70 )
return
}
songPath = path.Join( folderRoot, songPath )
println( "Song path", songPath )
command := exec.Command( "ffmpeg", "-i", songPath, "-vn", "-ab", "128k", "-v", "0", "-f", "mp3", "-" )
//command.Stderr = os.Stderr
command.Stdout = connection.output
command.Run()
}