diff --git a/graphql/schema/types/metadata.graphql b/graphql/schema/types/metadata.graphql index 6af77486a99..a603b56b55c 100644 --- a/graphql/schema/types/metadata.graphql +++ b/graphql/schema/types/metadata.graphql @@ -6,7 +6,7 @@ input GenerateMetadataInput { } input ScanMetadataInput { - nameFromMetadata: Boolean! + useFileMetadata: Boolean! } input AutoTagMetadataInput { diff --git a/pkg/api/resolver_query_metadata.go b/pkg/api/resolver_query_metadata.go index 3d54ee40f09..ad8dcbf3e5e 100644 --- a/pkg/api/resolver_query_metadata.go +++ b/pkg/api/resolver_query_metadata.go @@ -8,7 +8,7 @@ import ( ) func (r *queryResolver) MetadataScan(ctx context.Context, input models.ScanMetadataInput) (string, error) { - manager.GetInstance().Scan(input.NameFromMetadata) + manager.GetInstance().Scan(input.UseFileMetadata) return "todo", nil } diff --git a/pkg/manager/manager_tasks.go b/pkg/manager/manager_tasks.go index 0b4483518c3..c8e729cdafe 100644 --- a/pkg/manager/manager_tasks.go +++ b/pkg/manager/manager_tasks.go @@ -56,7 +56,7 @@ func (t *TaskStatus) updated() { t.LastUpdate = time.Now() } -func (s *singleton) Scan(nameFromMetadata bool) { +func (s *singleton) Scan(useFileMetadata bool) { if s.Status.Status != Idle { return } @@ -90,7 +90,7 @@ func (s *singleton) Scan(nameFromMetadata bool) { return } wg.Add(1) - task := ScanTask{FilePath: path, NameFromMetadata: nameFromMetadata} + task := ScanTask{FilePath: path, UseFileMetadata: useFileMetadata} go task.Start(&wg) wg.Wait() } diff --git a/pkg/manager/task_scan.go b/pkg/manager/task_scan.go index 71b2511573c..579a3fc00cd 100644 --- a/pkg/manager/task_scan.go +++ b/pkg/manager/task_scan.go @@ -16,8 +16,8 @@ import ( ) type ScanTask struct { - FilePath string - NameFromMetadata bool + FilePath string + UseFileMetadata bool } func (t *ScanTask) Start(wg *sync.WaitGroup) { @@ -92,8 +92,8 @@ func (t *ScanTask) scanScene() { return } - // Override title to be filename if nameFromMetadata is false - if !t.NameFromMetadata { + // Override title to be filename if UseFileMetadata is false + if !t.UseFileMetadata { videoFile.SetTitleFromPath() } @@ -127,8 +127,6 @@ func (t *ScanTask) scanScene() { Checksum: checksum, Path: t.FilePath, Title: sql.NullString{String: videoFile.Title, Valid: true}, - Details: sql.NullString{String: videoFile.Comment, Valid: true}, - Date: models.SQLiteDate{String: videoFile.CreationTime.Format("2006-01-02")}, Duration: sql.NullFloat64{Float64: videoFile.Duration, Valid: true}, VideoCodec: sql.NullString{String: videoFile.VideoCodec, Valid: true}, AudioCodec: sql.NullString{String: videoFile.AudioCodec, Valid: true}, @@ -140,6 +138,11 @@ func (t *ScanTask) scanScene() { CreatedAt: models.SQLiteTimestamp{Timestamp: currentTime}, UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime}, } + + if t.UseFileMetadata { + newScene.Details = sql.NullString{String: videoFile.Comment, Valid: true} + newScene.Date = models.SQLiteDate{String: videoFile.CreationTime.Format("2006-01-02")} + } _, err = qb.Create(newScene, tx) } diff --git a/ui/v2/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx b/ui/v2/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx index c3334331374..cdebb5a71a1 100644 --- a/ui/v2/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx +++ b/ui/v2/src/components/Settings/SettingsTasksPanel/SettingsTasksPanel.tsx @@ -21,7 +21,7 @@ interface IProps {} export const SettingsTasksPanel: FunctionComponent = (props: IProps) => { const [isImportAlertOpen, setIsImportAlertOpen] = useState(false); const [isCleanAlertOpen, setIsCleanAlertOpen] = useState(false); - const [nameFromMetadata, setNameFromMetadata] = useState(true); + const [useFileMetadata, setUseFileMetadata] = useState(false); const [status, setStatus] = useState(""); const [progress, setProgress] = useState(undefined); @@ -128,7 +128,7 @@ export const SettingsTasksPanel: FunctionComponent = (props: IProps) => async function onScan() { try { - await StashService.queryMetadataScan({nameFromMetadata}); + await StashService.queryMetadataScan({useFileMetadata: useFileMetadata}); ToastUtils.success("Started scan"); jobStatus.refetch(); } catch (e) { @@ -199,9 +199,9 @@ export const SettingsTasksPanel: FunctionComponent = (props: IProps) => inline={true} > setNameFromMetadata(!nameFromMetadata)} + checked={useFileMetadata} + label="Set name, date, details from metadata (if present)" + onChange={() => setUseFileMetadata(!useFileMetadata)} />