2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/photoprism"
|
2019-05-02 14:10:05 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2018-11-17 13:57:19 +01:00
|
|
|
// Re-indexes all photos in originals directory (photo library)
|
2018-09-24 09:53:16 +02:00
|
|
|
var IndexCommand = cli.Command{
|
|
|
|
Name: "index",
|
|
|
|
Usage: "Re-indexes all originals",
|
|
|
|
Action: indexAction,
|
|
|
|
}
|
|
|
|
|
2018-11-17 06:21:39 +01:00
|
|
|
func indexAction(ctx *cli.Context) error {
|
2019-05-06 23:18:10 +02:00
|
|
|
conf := config.NewConfig(ctx)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
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-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("indexing photos in %s", conf.OriginalsPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
tensorFlow := photoprism.NewTensorFlow(conf.TensorFlowModelPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-13 18:01:50 +02:00
|
|
|
indexer := photoprism.NewIndexer(conf, tensorFlow)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-02 14:10:05 +02:00
|
|
|
files := indexer.IndexAll()
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-02 14:10:05 +02:00
|
|
|
log.Infof("indexed %d files", len(files))
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
conf.Shutdown()
|
2019-05-04 17:34:51 +02:00
|
|
|
|
2018-09-24 09:53:16 +02:00
|
|
|
return nil
|
|
|
|
}
|