feat: complete generate
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package task
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"backend/modules/medias"
|
||||||
"backend/modules/tasks"
|
"backend/modules/tasks"
|
||||||
"backend/providers/app"
|
"backend/providers/app"
|
||||||
|
"backend/providers/postgres"
|
||||||
|
|
||||||
"git.ipao.vip/rogeecn/atom"
|
"git.ipao.vip/rogeecn/atom"
|
||||||
"git.ipao.vip/rogeecn/atom/container"
|
"git.ipao.vip/rogeecn/atom/container"
|
||||||
@@ -12,6 +14,7 @@ import (
|
|||||||
func defaultProviders(providers ...container.ProviderContainer) container.Providers {
|
func defaultProviders(providers ...container.ProviderContainer) container.Providers {
|
||||||
return append(container.Providers{
|
return append(container.Providers{
|
||||||
app.DefaultProvider(),
|
app.DefaultProvider(),
|
||||||
|
postgres.DefaultProvider(),
|
||||||
}, providers...)
|
}, providers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,15 +22,16 @@ func Command() atom.Option {
|
|||||||
return atom.Command(
|
return atom.Command(
|
||||||
atom.Name("tasks"),
|
atom.Name("tasks"),
|
||||||
atom.Short("run tasks"),
|
atom.Short("run tasks"),
|
||||||
atom.Providers(defaultProviders().With(
|
|
||||||
tasks.Provide,
|
|
||||||
)),
|
|
||||||
atom.Command(
|
atom.Command(
|
||||||
atom.Name("discover"),
|
atom.Name("discover"),
|
||||||
atom.Arguments(func(cmd *cobra.Command) {
|
atom.Arguments(func(cmd *cobra.Command) {
|
||||||
cmd.Flags().String("from", "", "from path")
|
cmd.Flags().String("from", "", "from path")
|
||||||
cmd.Flags().String("to", "", "to path")
|
cmd.Flags().String("to", "", "to path")
|
||||||
}),
|
}),
|
||||||
|
atom.Providers(defaultProviders().With(
|
||||||
|
tasks.Provide,
|
||||||
|
medias.Provide,
|
||||||
|
)),
|
||||||
atom.RunE(func(cmd *cobra.Command, args []string) error {
|
atom.RunE(func(cmd *cobra.Command, args []string) error {
|
||||||
return container.Container.Invoke(func(task *tasks.DiscoverMedias) error {
|
return container.Container.Invoke(func(task *tasks.DiscoverMedias) error {
|
||||||
from, to := cmd.Flag("from").Value.String(), cmd.Flag("to").Value.String()
|
from, to := cmd.Flag("from").Value.String(), cmd.Flag("to").Value.String()
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"backend/common/service/http"
|
"backend/common/service/http"
|
||||||
"backend/common/service/migrate"
|
"backend/common/service/migrate"
|
||||||
"backend/common/service/model"
|
"backend/common/service/model"
|
||||||
|
"backend/common/service/tasks"
|
||||||
|
|
||||||
"git.ipao.vip/rogeecn/atom"
|
"git.ipao.vip/rogeecn/atom"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -18,6 +19,7 @@ func main() {
|
|||||||
http.Command(),
|
http.Command(),
|
||||||
migrate.Command(),
|
migrate.Command(),
|
||||||
model.Command(),
|
model.Command(),
|
||||||
|
tasks.Command(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := atom.Serve(opts...); err != nil {
|
if err := atom.Serve(opts...); err != nil {
|
||||||
|
|||||||
@@ -28,9 +28,19 @@ func (d *DiscoverMedias) Prepare() error {
|
|||||||
|
|
||||||
func (d *DiscoverMedias) RunE(from, to string) error {
|
func (d *DiscoverMedias) RunE(from, to string) error {
|
||||||
d.log.Infof("Discover medias from: %s to: %s", from, to)
|
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")
|
mapFile := filepath.Join(to, "map.json")
|
||||||
d.log.Infof("read in from: %s", mapFile)
|
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)
|
b, err := os.ReadFile(mapFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -74,6 +84,7 @@ func (d *DiscoverMedias) RunE(from, to string) error {
|
|||||||
videos := d.globVideo(dirPath)
|
videos := d.globVideo(dirPath)
|
||||||
if len(videos) > 0 {
|
if len(videos) > 0 {
|
||||||
video := videos[0]
|
video := videos[0]
|
||||||
|
d.log.Infof("video: %s", video)
|
||||||
if err := d.ffmpegVideoToM3U8(video, to); err != nil {
|
if err := d.ffmpegVideoToM3U8(video, to); err != nil {
|
||||||
return errors.Wrapf(err, "ffmpeg video to m3u8: %s", video)
|
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)
|
audios := d.globAudio(dirPath)
|
||||||
if len(audios) > 0 {
|
if len(audios) > 0 {
|
||||||
audio := audios[0]
|
audio := audios[0]
|
||||||
|
d.log.Infof("audio: %s", audio)
|
||||||
if err := d.ffmpegAudioToM3U8(audio, to); err != nil {
|
if err := d.ffmpegAudioToM3U8(audio, to); err != nil {
|
||||||
return errors.Wrapf(err, "ffmpeg audio to m3u8: %s", audio)
|
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, " "))
|
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 {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "ffmpeg video to m3u8: %s", input)
|
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, " "))
|
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 {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "ffmpeg audio to m3u8: %s", input)
|
return errors.Wrapf(err, "ffmpeg audio to m3u8: %s", input)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user