diff --git a/config-example.yml b/config-example.yml index 42ea5bb..52bffd1 100644 --- a/config-example.yml +++ b/config-example.yml @@ -80,6 +80,8 @@ openlist: ignore-containers: jpg,jpeg,png,txt,nfo,md # 同步线程数 threads: 8 + # ffmpeg 网络请求代理地址,格式如:http://127.0.0.1:7890 或 socks5://127.0.0.1:1080,留空则不启用 + proxy-addr: '' # 该配置项目前只对阿里云盘生效, 如果你使用的是其他网盘, 请直接将 enable 设置为 false video-preview: diff --git a/internal/config/openlist.go b/internal/config/openlist.go index 64d03d2..cf2e777 100644 --- a/internal/config/openlist.go +++ b/internal/config/openlist.go @@ -3,8 +3,6 @@ package config import ( "fmt" "strings" - - "github.com/AmbitiousJun/go-emby2openlist/v2/internal/service/lib/ffmpeg" ) type Openlist struct { @@ -60,6 +58,9 @@ type LocalTreeGen struct { // Threads 同步线程数 Threads int `yaml:"threads"` + // ProxyAddr ffmpeg 网络请求代理地址,格式如:http://127.0.0.1:7890 或 socks5://127.0.0.1:1080,留空则不启用 + ProxyAddr string `yaml:"proxy-addr"` + // virtualContainers 虚拟媒体容器集合 便于快速查询 virtualContainers map[string]struct{} @@ -79,12 +80,6 @@ func (ltg *LocalTreeGen) Init() error { return nil } - if ltg.FFmpegEnable { - if err := ffmpeg.AutoDownloadExec(BasePath); err != nil { - return fmt.Errorf("ffmpeg 初始化失败: %w", err) - } - } - if ltg.AutoRemoveMaxCount < 0 { ltg.AutoRemoveMaxCount = 0 } diff --git a/internal/service/lib/ffmpeg/ffmpeg.go b/internal/service/lib/ffmpeg/ffmpeg.go index 641fd1a..66e44e6 100644 --- a/internal/service/lib/ffmpeg/ffmpeg.go +++ b/internal/service/lib/ffmpeg/ffmpeg.go @@ -7,6 +7,7 @@ import ( "os/exec" "sync" + "github.com/AmbitiousJun/go-emby2openlist/v2/internal/config" "github.com/AmbitiousJun/go-emby2openlist/v2/internal/constant" ) @@ -24,7 +25,15 @@ func InspectInfo(path string) (Info, error) { mu.Lock() defer mu.Unlock() - cmd := exec.Command(execPath, "-user_agent", constant.CommonDlUserAgent, "-threads", "1", "-i", path) + args := []string{"-user_agent", constant.CommonDlUserAgent, "-threads", "1", "-i", path} + proxy := "" + if config.C != nil && config.C.Openlist != nil && config.C.Openlist.LocalTreeGen != nil { + proxy = config.C.Openlist.LocalTreeGen.ProxyAddr + } + if proxy != "" { + args = append([]string{"-http_proxy", proxy}, args...) + } + cmd := exec.Command(execPath, args...) outputBytes, _ := cmd.CombinedOutput() if bytes.Contains(outputBytes, []byte(OpenError)) { @@ -47,7 +56,15 @@ func InspectMusic(path string) (Music, error) { mu.Lock() defer mu.Unlock() - cmd := exec.Command(execPath, "-user_agent", constant.CommonDlUserAgent, "-threads", "1", "-i", path) + args := []string{"-user_agent", constant.CommonDlUserAgent, "-threads", "1", "-i", path} + proxy := "" + if config.C != nil && config.C.Openlist != nil && config.C.Openlist.LocalTreeGen != nil { + proxy = config.C.Openlist.LocalTreeGen.ProxyAddr + } + if proxy != "" { + args = append([]string{"-http_proxy", proxy}, args...) + } + cmd := exec.Command(execPath, args...) outputBytes, _ := cmd.CombinedOutput() if bytes.Contains(outputBytes, []byte(OpenError)) { @@ -138,7 +155,15 @@ func ExtractMusicCover(path string) ([]byte, error) { mu.Lock() defer mu.Unlock() - cmd := exec.Command(execPath, "-user_agent", constant.CommonDlUserAgent, "-threads", "1", "-i", path, "-an", "-vframes", "1", "-f", "image2", "-vcodec", "mjpeg", "pipe:1") + args := []string{"-user_agent", constant.CommonDlUserAgent, "-threads", "1", "-i", path, "-an", "-vframes", "1", "-f", "image2", "-vcodec", "mjpeg", "pipe:1"} + proxy := "" + if config.C != nil && config.C.Openlist != nil && config.C.Openlist.LocalTreeGen != nil { + proxy = config.C.Openlist.LocalTreeGen.ProxyAddr + } + if proxy != "" { + args = append([]string{"-http_proxy", proxy}, args...) + } + cmd := exec.Command(execPath, args...) outputBytes, err := cmd.Output() if err != nil { diff --git a/main.go b/main.go index 431d001..01f742a 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "github.com/AmbitiousJun/go-emby2openlist/v2/internal/config" "github.com/AmbitiousJun/go-emby2openlist/v2/internal/constant" + "github.com/AmbitiousJun/go-emby2openlist/v2/internal/service/lib/ffmpeg" "github.com/AmbitiousJun/go-emby2openlist/v2/internal/service/openlist/localtree" "github.com/AmbitiousJun/go-emby2openlist/v2/internal/util/logs" "github.com/AmbitiousJun/go-emby2openlist/v2/internal/util/logs/colors" @@ -30,6 +31,14 @@ func main() { if err := config.ReadFromFile(filepath.Join(dataRoot, "config.yml")); err != nil { log.Fatal(err) } + // 初始化阶段检查并自动下载 ffmpeg(只做一次) + if config.C.Openlist != nil && config.C.Openlist.LocalTreeGen != nil && config.C.Openlist.LocalTreeGen.FFmpegEnable { + if err := ffmpeg.AutoDownloadExec(dataRoot); err != nil { + logs.Error("ffmpeg 初始化失败: %v", err) + } else { + logs.Info("ffmpeg 环境检测通过 ✓") + } + } printBanner()