Use new ytdl method for ambiance
parent
cd264e0fc9
commit
6124ed3dbf
37
ambiance.go
37
ambiance.go
|
@ -5,10 +5,13 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/davecheney/xattr"
|
||||
"github.com/google/uuid"
|
||||
|
@ -23,7 +26,7 @@ type Ambiance struct {
|
|||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -42,13 +45,13 @@ func GetAmbiance(id string) (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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
|
||||
|
@ -56,7 +59,7 @@ func GetAmbiances() (amb []Ambiance, err error) {
|
|||
amb = append(amb, Ambiance{
|
||||
Id: file.Name()[:len(file.Name())-len(filepath.Ext(file.Name()))],
|
||||
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
|
||||
}
|
||||
|
||||
log.Printf("Start download with YTdl for %s", uri)
|
||||
ytfile, err := NewYTdl(vid)
|
||||
vinfo, err := app.youtube.GetVideoFromID(vid)
|
||||
if err != nil {
|
||||
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(
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-i", string(ytfile),
|
||||
"-i", vinfo.GetHLSPlaylist("234"),
|
||||
"-vn",
|
||||
"-acodec", "copy",
|
||||
//"-acodec", "copy",
|
||||
"-movflags", "+faststart",
|
||||
"-t", "01:00:00",
|
||||
"-v", "error",
|
||||
"-ar", "48000",
|
||||
"-v", "quiet",
|
||||
// "-stats",
|
||||
"-progress", "pipe:1",
|
||||
// "-af", "loudnorm=I=-16:LRA=11:TP=-1.5",
|
||||
|
@ -152,6 +155,13 @@ func AddAmbiance(uri, title string) (Ambiance, error) {
|
|||
}
|
||||
|
||||
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
|
||||
ws_msg <- msg
|
||||
})
|
||||
|
@ -174,7 +184,7 @@ func AddAmbiance(uri, title string) (Ambiance, error) {
|
|||
ws_msg <- msg
|
||||
|
||||
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)
|
||||
|
||||
|
@ -208,11 +218,6 @@ func AddAmbiance(uri, title string) (Ambiance, error) {
|
|||
return amb, err
|
||||
}
|
||||
|
||||
err = os.Remove(string(ytfile))
|
||||
if err != nil {
|
||||
return amb, err
|
||||
}
|
||||
|
||||
err = os.Remove(string(tmpfile))
|
||||
if err != nil {
|
||||
return amb, err
|
||||
|
|
Loading…
Reference in New Issue