Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 3 additions & 8 deletions internal/config/openlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package config
import (
"fmt"
"strings"

"github.com/AmbitiousJun/go-emby2openlist/v2/internal/service/lib/ffmpeg"
)

type Openlist struct {
Expand Down Expand Up @@ -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{}

Expand All @@ -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
}
Expand Down
31 changes: 28 additions & 3 deletions internal/service/lib/ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"sync"

"github.com/AmbitiousJun/go-emby2openlist/v2/internal/config"
"github.com/AmbitiousJun/go-emby2openlist/v2/internal/constant"
)

Expand All @@ -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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand Down