Use new ytdl method for ambiance
parent
cd264e0fc9
commit
6124ed3dbf
37
ambiance.go
37
ambiance.go
|
@ -5,10 +5,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/davecheney/xattr"
|
"github.com/davecheney/xattr"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -23,7 +26,7 @@ type Ambiance struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAmbiance(id string) (amb Ambiance, err error) {
|
func GetAmbiance(id string) (amb Ambiance, err error) {
|
||||||
fp := filepath.Join("./ambiance", id+".opus")
|
fp := filepath.Join(config.GetString("ambiance.path"), id+".opus")
|
||||||
_, err = os.Stat(fp)
|
_, err = os.Stat(fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -42,13 +45,13 @@ func GetAmbiance(id string) (amb Ambiance, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAmbiances() (amb []Ambiance, err error) {
|
func GetAmbiances() (amb []Ambiance, err error) {
|
||||||
files, err := os.ReadDir("./ambiance")
|
files, err := os.ReadDir(config.GetString("ambiance.path"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
title, err := xattr.Getxattr(filepath.Join("./ambiance", file.Name()), "title")
|
title, err := xattr.Getxattr(filepath.Join(config.GetString("ambiance.path"), file.Name()), "title")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
|
@ -56,7 +59,7 @@ func GetAmbiances() (amb []Ambiance, err error) {
|
||||||
amb = append(amb, Ambiance{
|
amb = append(amb, Ambiance{
|
||||||
Id: file.Name()[:len(file.Name())-len(filepath.Ext(file.Name()))],
|
Id: file.Name()[:len(file.Name())-len(filepath.Ext(file.Name()))],
|
||||||
Title: string(title),
|
Title: string(title),
|
||||||
Path: filepath.Join("./ambiance", file.Name()),
|
Path: filepath.Join(config.GetString("ambiance.path"), file.Name()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,22 +98,22 @@ func AddAmbiance(uri, title string) (Ambiance, error) {
|
||||||
return amb, err
|
return amb, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Start download with YTdl for %s", uri)
|
vinfo, err := app.youtube.GetVideoFromID(vid)
|
||||||
ytfile, err := NewYTdl(vid)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return amb, err
|
return amb, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Start ffmpeg for %s", string(ytfile))
|
log.Printf("Start ffmpeg for %s (%s)", vid, vinfo.VideoDetails.Title)
|
||||||
ff := exec.Command(
|
ff := exec.Command(
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
"-y",
|
"-y",
|
||||||
"-i", string(ytfile),
|
"-i", vinfo.GetHLSPlaylist("234"),
|
||||||
"-vn",
|
"-vn",
|
||||||
"-acodec", "copy",
|
//"-acodec", "copy",
|
||||||
"-movflags", "+faststart",
|
"-movflags", "+faststart",
|
||||||
"-t", "01:00:00",
|
"-t", "01:00:00",
|
||||||
"-v", "error",
|
"-ar", "48000",
|
||||||
|
"-v", "quiet",
|
||||||
// "-stats",
|
// "-stats",
|
||||||
"-progress", "pipe:1",
|
"-progress", "pipe:1",
|
||||||
// "-af", "loudnorm=I=-16:LRA=11:TP=-1.5",
|
// "-af", "loudnorm=I=-16:LRA=11:TP=-1.5",
|
||||||
|
@ -152,6 +155,13 @@ func AddAmbiance(uri, title string) (Ambiance, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
prate.Do(func() {
|
prate.Do(func() {
|
||||||
|
out_time, ok := data["out_time_ms"]
|
||||||
|
if ok {
|
||||||
|
out_time_ms, _ := strconv.Atoi(out_time)
|
||||||
|
percent := fmt.Sprintf("%.0f", math.Floor((float64(out_time_ms)/float64(time.Hour.Microseconds()))*100))
|
||||||
|
data["percent"] = percent
|
||||||
|
}
|
||||||
|
|
||||||
msg["payload"] = data
|
msg["payload"] = data
|
||||||
ws_msg <- msg
|
ws_msg <- msg
|
||||||
})
|
})
|
||||||
|
@ -174,7 +184,7 @@ func AddAmbiance(uri, title string) (Ambiance, error) {
|
||||||
ws_msg <- msg
|
ws_msg <- msg
|
||||||
|
|
||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
fn := filepath.Join("./ambiance", fmt.Sprintf("%s.opus", id.String()))
|
fn := filepath.Join(config.GetString("ambiance.path"), fmt.Sprintf("%s.opus", id.String()))
|
||||||
|
|
||||||
log.Printf("Moving to %s", fn)
|
log.Printf("Moving to %s", fn)
|
||||||
|
|
||||||
|
@ -208,11 +218,6 @@ func AddAmbiance(uri, title string) (Ambiance, error) {
|
||||||
return amb, err
|
return amb, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Remove(string(ytfile))
|
|
||||||
if err != nil {
|
|
||||||
return amb, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Remove(string(tmpfile))
|
err = os.Remove(string(tmpfile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return amb, err
|
return amb, err
|
||||||
|
|
Loading…
Reference in New Issue