2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2020-10-08 08:52:03 +02:00
|
|
|
"context"
|
2019-05-14 16:04:17 +02:00
|
|
|
"time"
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2020-04-05 22:26:53 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2021-01-24 17:46:18 +01:00
|
|
|
// ConvertCommand registers the convert cli command.
|
2018-09-24 09:53:16 +02:00
|
|
|
var ConvertCommand = cli.Command{
|
|
|
|
Name: "convert",
|
2021-02-11 21:37:44 +01:00
|
|
|
Usage: "Converts originals in other formats to JPEG and AVC sidecar files",
|
2018-09-24 09:53:16 +02:00
|
|
|
Action: convertAction,
|
|
|
|
}
|
|
|
|
|
2021-02-11 21:37:44 +01:00
|
|
|
// convertAction converts originals in other formats to JPEG and AVC sidecar files.
|
2018-11-17 06:21:39 +01:00
|
|
|
func convertAction(ctx *cli.Context) error {
|
2019-05-14 16:04:17 +02:00
|
|
|
start := time.Now()
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
conf := config.NewConfig(ctx)
|
2020-04-05 22:26:53 +02:00
|
|
|
service.SetConfig(conf)
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2020-06-07 14:33:07 +02:00
|
|
|
if !conf.SidecarWritable() {
|
2019-07-02 22:03:23 +02:00
|
|
|
return config.ErrReadOnly
|
|
|
|
}
|
|
|
|
|
2020-10-08 08:52:03 +02:00
|
|
|
_, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err := conf.Init(); err != nil {
|
2019-01-15 14:00:42 +01:00
|
|
|
return err
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2021-02-11 21:37:44 +01:00
|
|
|
log.Infof("converting originals in %s", conf.OriginalsPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-04-05 22:26:53 +02:00
|
|
|
convert := service.Convert()
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-04-05 22:26:53 +02:00
|
|
|
if err := convert.Start(conf.OriginalsPath()); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-14 16:04:17 +02:00
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
2021-02-11 21:37:44 +01:00
|
|
|
log.Infof("converting completed in %s", elapsed)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|