Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
1a04de439c | |||
42cd0865a5 |
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -18,8 +18,11 @@ 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,
|
||||||
|
AudioFormats: "best",
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
return
|
return
|
||||||
@ -113,6 +116,7 @@ func convertToMp3(data ConvertOptions, ch chan error) {
|
|||||||
input := []*ffmpeg.Stream{ffmpeg.Input(data.Video).Audio()}
|
input := []*ffmpeg.Stream{ffmpeg.Input(data.Video).Audio()}
|
||||||
args := ffmpeg.KwArgs{
|
args := ffmpeg.KwArgs{
|
||||||
"format": "mp3",
|
"format": "mp3",
|
||||||
|
"ab": "320k",
|
||||||
"id3v2_version": "3",
|
"id3v2_version": "3",
|
||||||
"write_id3v1": "1",
|
"write_id3v1": "1",
|
||||||
"metadata": []string{
|
"metadata": []string{
|
||||||
@ -167,7 +171,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 +182,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 +200,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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user