feat: complete generate

This commit is contained in:
Rogee
2024-12-04 20:02:30 +08:00
parent d4981f99c2
commit 975eba4183
3 changed files with 24 additions and 6 deletions

View File

@@ -28,9 +28,19 @@ func (d *DiscoverMedias) Prepare() error {
func (d *DiscoverMedias) RunE(from, to string) error {
d.log.Infof("Discover medias from: %s to: %s", from, to)
if from == "" || to == "" {
return errors.New("from or to is empty")
}
mapFile := filepath.Join(to, "map.json")
d.log.Infof("read in from: %s", mapFile)
if _, err := os.Stat(mapFile); err != nil {
if os.IsNotExist(err) {
if err := os.WriteFile(mapFile, []byte("[]"), os.ModePerm); err != nil {
return errors.Wrapf(err, "write file: %s", mapFile)
}
}
}
b, err := os.ReadFile(mapFile)
if err != nil {
@@ -74,6 +84,7 @@ func (d *DiscoverMedias) RunE(from, to string) error {
videos := d.globVideo(dirPath)
if len(videos) > 0 {
video := videos[0]
d.log.Infof("video: %s", video)
if err := d.ffmpegVideoToM3U8(video, to); err != nil {
return errors.Wrapf(err, "ffmpeg video to m3u8: %s", video)
}
@@ -82,6 +93,7 @@ func (d *DiscoverMedias) RunE(from, to string) error {
audios := d.globAudio(dirPath)
if len(audios) > 0 {
audio := audios[0]
d.log.Infof("audio: %s", audio)
if err := d.ffmpegAudioToM3U8(audio, to); err != nil {
return errors.Wrapf(err, "ffmpeg audio to m3u8: %s", audio)
}
@@ -194,7 +206,7 @@ func (d *DiscoverMedias) ffmpegVideoToM3U8(input string, output string) error {
}
log.Infof("cmd: ffmpeg %s", strings.Join(args, " "))
logs, err := exec.Command("ffmpeg", args...).Output()
logs, err := exec.Command("ffmpeg", args...).CombinedOutput()
if err != nil {
return errors.Wrapf(err, "ffmpeg video to m3u8: %s", input)
}
@@ -222,7 +234,7 @@ func (d *DiscoverMedias) ffmpegAudioToM3U8(input string, output string) error {
}
log.Infof("cmd: ffmpeg %s", strings.Join(args, " "))
logs, err := exec.Command("ffmpeg", args...).Output()
logs, err := exec.Command("ffmpeg", args...).CombinedOutput()
if err != nil {
return errors.Wrapf(err, "ffmpeg audio to m3u8: %s", input)
}