@@ -191,16 +191,19 @@ func (s Service) GetTaskStatus(req dto.GetVideoSubtitleTaskReq) (*dto.GetVideoSu
191
191
// 新版流程:链接->本地音频文件->扣费->视频信息获取(若有)->本地字幕文件->cos上的字幕信息
192
192
193
193
func (s Service ) linkToAudioFile (ctx context.Context , stepParam * types.SubtitleTaskStepParam ) error {
194
- var err error
194
+ var (
195
+ err error
196
+ output []byte
197
+ )
195
198
link := stepParam .Link
196
199
audioPath := fmt .Sprintf ("%s/%s" , stepParam .TaskBasePath , types .SubtitleTaskAudioFileName )
197
200
if strings .Contains (link , "local:" ) {
198
201
// 本地文件
199
202
videoPath := strings .ReplaceAll (link , "local:" , "" )
200
203
cmd := exec .Command (storage .FfmpegPath , "-i" , videoPath , "-vn" , "-ar" , "44100" , "-ac" , "2" , "-ab" , "192k" , "-f" , "mp3" , audioPath )
201
- err = cmd .Run ()
204
+ output , err = cmd .CombinedOutput ()
202
205
if err != nil {
203
- log .GetLogger ().Error ("generateAudioSubtitles.Step1LinkToAudio ffmpeg err" , zap .Any ("step param" , stepParam ), zap .Error (err ))
206
+ log .GetLogger ().Error ("generateAudioSubtitles.Step1LinkToAudio ffmpeg err" , zap .Any ("step param" , stepParam ), zap .String ( "output" , string ( output )), zap . Error (err ))
204
207
return err
205
208
}
206
209
} else if strings .Contains (link , "youtube.com" ) {
@@ -215,10 +218,13 @@ func (s Service) linkToAudioFile(ctx context.Context, stepParam *types.SubtitleT
215
218
cmdArgs := []string {"-f" , "bestaudio" , "--extract-audio" , "--audio-format" , "mp3" , "--audio-quality" , "192K" , "-o" , audioPath , stepParam .Link }
216
219
217
220
cmdArgs = append (cmdArgs , "--cookies" , "./cookies.txt" )
221
+ if storage .FfmpegPath != "ffmpeg" {
222
+ cmdArgs = append (cmdArgs , "--ffmpeg-location" , storage .FfmpegPath )
223
+ }
218
224
cmd := exec .Command (storage .YtdlpPath , cmdArgs ... )
219
- err = cmd .Run ()
225
+ output , err = cmd .CombinedOutput ()
220
226
if err != nil {
221
- log .GetLogger ().Error ("generateAudioSubtitles.Step2DownloadAudio yt-dlp err" , zap .Any ("step param" , stepParam ), zap .Error (err ))
227
+ log .GetLogger ().Error ("generateAudioSubtitles.Step2DownloadAudio yt-dlp err" , zap .Any ("step param" , stepParam ), zap .String ( "output" , string ( output )), zap . Error (err ))
222
228
return err
223
229
}
224
230
} else if strings .Contains (link , "bilibili.com" ) {
@@ -228,14 +234,17 @@ func (s Service) linkToAudioFile(ctx context.Context, stepParam *types.SubtitleT
228
234
}
229
235
stepParam .Link = "https://www.bilibili.com/video/" + videoId
230
236
cmdArgs := []string {"-f" , "bestaudio[ext=m4a]" , "-x" , "--audio-format" , "mp3" , "-o" , audioPath , stepParam .Link }
237
+ if storage .FfmpegPath != "ffmpeg" {
238
+ cmdArgs = append (cmdArgs , "--ffmpeg-location" , storage .FfmpegPath )
239
+ }
231
240
//proxy := conf.GetString("subtitle.proxy")
232
241
//if proxy != "" {
233
242
// cmdArgs = append(cmdArgs, "--proxy", proxy)
234
243
//}
235
244
cmd := exec .Command (storage .YtdlpPath , cmdArgs ... )
236
- err = cmd .Run ()
245
+ output , err = cmd .CombinedOutput ()
237
246
if err != nil {
238
- log .GetLogger ().Error ("generateAudioSubtitles.Step2DownloadAudio yt-dlp err" , zap .Any ("step param" , stepParam ), zap .Error (err ))
247
+ log .GetLogger ().Error ("generateAudioSubtitles.Step2DownloadAudio yt-dlp err" , zap .Any ("step param" , stepParam ), zap .String ( "output" , string ( output )), zap . Error (err ))
239
248
return err
240
249
}
241
250
} else {
@@ -267,18 +276,24 @@ func (s Service) getVideoInfo(ctx context.Context, stepParam *types.SubtitleTask
267
276
//}
268
277
titleCmdArgs = append (titleCmdArgs , "--cookies" , "./cookies.txt" )
269
278
descriptionCmdArgs = append (descriptionCmdArgs , "--cookies" , "./cookies.txt" )
279
+ if storage .FfmpegPath != "ffmpeg" {
280
+ titleCmdArgs = append (titleCmdArgs , "--ffmpeg-location" , storage .FfmpegPath )
281
+ descriptionCmdArgs = append (descriptionCmdArgs , "--ffmpeg-location" , storage .FfmpegPath )
282
+ }
270
283
cmd := exec .Command (storage .YtdlpPath , titleCmdArgs ... )
271
284
var output []byte
272
- output , err = cmd .Output ()
285
+ output , err = cmd .CombinedOutput ()
273
286
if err != nil {
274
- log .GetLogger ().Error ("getVideoInfo yt-dlp error" , zap .Any ("stepParam" , stepParam ), zap .Error (err ))
287
+ log .GetLogger ().Error ("getVideoInfo yt-dlp error" , zap .Any ("stepParam" , stepParam ), zap .String ("output" , string (output )), zap .Error (err ))
288
+ output = []byte {}
275
289
// 不需要整个流程退出
276
290
}
277
291
title = string (output )
278
292
cmd = exec .Command (storage .YtdlpPath , descriptionCmdArgs ... )
279
- output , err = cmd .Output ()
293
+ output , err = cmd .CombinedOutput ()
280
294
if err != nil {
281
- log .GetLogger ().Error ("getVideoInfo yt-dlp error" , zap .Any ("stepParam" , stepParam ), zap .Error (err ))
295
+ log .GetLogger ().Error ("getVideoInfo yt-dlp error" , zap .Any ("stepParam" , stepParam ), zap .String ("output" , string (output )), zap .Error (err ))
296
+ output = []byte {}
282
297
}
283
298
description = string (output )
284
299
log .GetLogger ().Debug ("getVideoInfo title and description" , zap .String ("title" , title ), zap .String ("description" , description ))
0 commit comments