2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-06-03 22:58:15 +02:00
|
|
|
"context"
|
2019-05-14 16:04:17 +02:00
|
|
|
"time"
|
|
|
|
|
2020-01-09 01:21:09 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/classify"
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2019-12-14 20:35:14 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/nsfw"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/photoprism"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2018-11-17 13:57:19 +01:00
|
|
|
// Imports photos from path defined in command-line args
|
2018-09-24 09:53:16 +02:00
|
|
|
var ImportCommand = cli.Command{
|
|
|
|
Name: "import",
|
|
|
|
Usage: "Imports photos",
|
|
|
|
Action: importAction,
|
|
|
|
}
|
|
|
|
|
2018-11-17 06:21:39 +01:00
|
|
|
func importAction(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)
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2019-07-02 22:03:23 +02:00
|
|
|
if conf.ReadOnly() {
|
|
|
|
return config.ErrReadOnly
|
|
|
|
}
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
if err := conf.CreateDirectories(); err != nil {
|
2019-01-15 14:00:42 +01:00
|
|
|
return err
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 22:58:15 +02:00
|
|
|
cctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
if err := conf.Init(cctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
conf.MigrateDb()
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
log.Infof("importing photos from %s", conf.ImportPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-01-09 01:21:09 +01:00
|
|
|
tensorFlow := classify.New(conf.ResourcesPath(), conf.TensorFlowDisabled())
|
|
|
|
nsfwDetector := nsfw.New(conf.NSFWModelPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-01-02 05:03:47 +01:00
|
|
|
ind := photoprism.NewIndex(conf, tensorFlow, nsfwDetector)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-01-02 05:03:47 +01:00
|
|
|
convert := photoprism.NewConvert(conf)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-01-02 05:03:47 +01:00
|
|
|
imp := photoprism.NewImport(conf, ind, convert)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-01-02 05:03:47 +01:00
|
|
|
imp.Start(conf.ImportPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-14 16:04:17 +02:00
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
log.Infof("photo import completed in %s", elapsed)
|
2019-06-03 22:58:15 +02:00
|
|
|
conf.Shutdown()
|
2018-09-24 09:53:16 +02:00
|
|
|
return nil
|
|
|
|
}
|