Skip to content

Commit 085d1f4

Browse files
authored
Merge pull request #47 from krillinai/feat-aitool
feat: add proxy in ytdlp
2 parents d5d0a8d + b9ba416 commit 085d1f4

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

internal/service/get_video_info.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"go.uber.org/zap"
7+
"krillin-ai/config"
78
"krillin-ai/internal/storage"
89
"krillin-ai/internal/types"
910
"krillin-ai/log"
@@ -23,6 +24,10 @@ func (s Service) getVideoInfo(ctx context.Context, stepParam *types.SubtitleTask
2324
descriptionCmdArgs := []string{"--skip-download", "--encoding", "utf-8", "--get-description", stepParam.Link}
2425
titleCmdArgs = append(titleCmdArgs, "--cookies", "./cookies.txt")
2526
descriptionCmdArgs = append(descriptionCmdArgs, "--cookies", "./cookies.txt")
27+
if config.Conf.App.Proxy != "" {
28+
titleCmdArgs = append(titleCmdArgs, "--proxy", config.Conf.App.Proxy)
29+
descriptionCmdArgs = append(descriptionCmdArgs, "--proxy", config.Conf.App.Proxy)
30+
}
2631
if storage.FfmpegPath != "ffmpeg" {
2732
titleCmdArgs = append(titleCmdArgs, "--ffmpeg-location", storage.FfmpegPath)
2833
descriptionCmdArgs = append(descriptionCmdArgs, "--ffmpeg-location", storage.FfmpegPath)

internal/service/link2file.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"go.uber.org/zap"
8+
"krillin-ai/config"
89
"krillin-ai/internal/storage"
910
"krillin-ai/internal/types"
1011
"krillin-ai/log"
@@ -41,7 +42,9 @@ func (s Service) linkToFile(ctx context.Context, stepParam *types.SubtitleTaskSt
4142
}
4243
stepParam.Link = "https://www.youtube.com/watch?v=" + videoId
4344
cmdArgs := []string{"-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "192K", "-o", audioPath, stepParam.Link}
44-
45+
if config.Conf.App.Proxy != "" {
46+
cmdArgs = append(cmdArgs, "--proxy", config.Conf.App.Proxy)
47+
}
4548
cmdArgs = append(cmdArgs, "--cookies", "./cookies.txt")
4649
if storage.FfmpegPath != "ffmpeg" {
4750
cmdArgs = append(cmdArgs, "--ffmpeg-location", storage.FfmpegPath)
@@ -59,6 +62,9 @@ func (s Service) linkToFile(ctx context.Context, stepParam *types.SubtitleTaskSt
5962
}
6063
stepParam.Link = "https://www.bilibili.com/video/" + videoId
6164
cmdArgs := []string{"-f", "bestaudio[ext=m4a]", "-x", "--audio-format", "mp3", "-o", audioPath, stepParam.Link}
65+
if config.Conf.App.Proxy != "" {
66+
cmdArgs = append(cmdArgs, "--proxy", config.Conf.App.Proxy)
67+
}
6268
if storage.FfmpegPath != "ffmpeg" {
6369
cmdArgs = append(cmdArgs, "--ffmpeg-location", storage.FfmpegPath)
6470
}
@@ -77,7 +83,11 @@ func (s Service) linkToFile(ctx context.Context, stepParam *types.SubtitleTaskSt
7783

7884
if !strings.HasPrefix(link, "local:") && stepParam.EmbedSubtitleVideoType != "none" {
7985
// 需要下载原视频
80-
cmd := exec.Command(storage.YtdlpPath, "-f", "bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]", "-o", videoPath, stepParam.Link)
86+
cmdArgs := []string{"-f", "bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]", "-o", videoPath, stepParam.Link}
87+
if config.Conf.App.Proxy != "" {
88+
cmdArgs = append(cmdArgs, "--proxy", config.Conf.App.Proxy)
89+
}
90+
cmd := exec.Command(storage.YtdlpPath, cmdArgs...)
8191
output, err = cmd.CombinedOutput()
8292
if err != nil {
8393
log.GetLogger().Error("linkToFile download video yt-dlp error", zap.Any("step param", stepParam), zap.String("output", string(output)), zap.Error(err))

static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ <h1>世界帧精彩</h1>
331331
<option value="ja">日文</option>
332332
<option value="tr">土耳其语</option>
333333
<option value="de">德语</option>
334+
<option value="ko">韩语</option>
334335
</select>
335336
</div>
336337

0 commit comments

Comments
 (0)