fix: fix error video format not available

This commit is contained in:
Khairul Hidayat 2024-10-12 09:14:36 +00:00
parent dced610d6b
commit 42cd0865a5
3 changed files with 13 additions and 6 deletions

View File

@ -7,7 +7,7 @@ tmp_dir = "tmp"
bin = "./tmp/main" bin = "./tmp/main"
cmd = "go build -o ./tmp/main ." cmd = "go build -o ./tmp/main ."
delay = 1000 delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"] exclude_dir = ["assets", "tmp", "vendor", "testdata", "ui"]
exclude_file = [] exclude_file = []
exclude_regex = ["_test.go"] exclude_regex = ["_test.go"]
exclude_unchanged = false exclude_unchanged = false

View File

@ -1,6 +1,7 @@
package lib package lib
import ( import (
"fmt"
"time" "time"
"rul.sh/go-ytmp3/utils" "rul.sh/go-ytmp3/utils"
@ -75,6 +76,10 @@ func InitTaskScheduler() *TaskScheduler {
Album: task.Album, Album: task.Album,
}) })
if err != nil {
fmt.Println(err)
}
task.IsPending = false task.IsPending = false
task.Error = err task.Error = err
task.Result = result task.Result = result

View File

@ -18,8 +18,10 @@ import (
"rul.sh/go-ytmp3/utils" "rul.sh/go-ytmp3/utils"
) )
func fetchVideo(video *goutubedl.Result, out string, ch chan error) { func fetchAudio(video *goutubedl.Result, out string, ch chan error) {
dl, err := video.Download(context.Background(), "best") dl, err := video.DownloadWithOptions(context.Background(), goutubedl.DownloadOptions{
DownloadAudioOnly: true,
})
if err != nil { if err != nil {
ch <- err ch <- err
return return
@ -167,7 +169,7 @@ func Yt2Mp3(video *goutubedl.Result, options Yt2Mp3Options) (string, error) {
videoSlug = slug.Make(title) videoSlug = slug.Make(title)
} }
videoSrc := fmt.Sprintf("%s/%s.mp4", tmpDir, videoSlug) audioSrc := fmt.Sprintf("%s/%s-src.mp3", tmpDir, videoSlug)
thumbnail := fmt.Sprintf("%s/%s.jpg", tmpDir, videoSlug) thumbnail := fmt.Sprintf("%s/%s.jpg", tmpDir, videoSlug)
out := fmt.Sprintf("%s/%s.mp3", options.OutDir, videoSlug) out := fmt.Sprintf("%s/%s.mp3", options.OutDir, videoSlug)
@ -178,7 +180,7 @@ func Yt2Mp3(video *goutubedl.Result, options Yt2Mp3Options) (string, error) {
videoCh := make(chan error) videoCh := make(chan error)
thumbCh := make(chan error) thumbCh := make(chan error)
go fetchVideo(video, videoSrc, videoCh) go fetchAudio(video, audioSrc, videoCh)
go fetchThumbnail(video, thumbnail, thumbCh) go fetchThumbnail(video, thumbnail, thumbCh)
err := <-videoCh err := <-videoCh
@ -196,7 +198,7 @@ func Yt2Mp3(video *goutubedl.Result, options Yt2Mp3Options) (string, error) {
convertCh := make(chan error) convertCh := make(chan error)
go convertToMp3(ConvertOptions{ go convertToMp3(ConvertOptions{
Video: videoSrc, Video: audioSrc,
Thumbnail: thumbnail, Thumbnail: thumbnail,
Title: title, Title: title,
Artist: artist, Artist: artist,