Make scene metadata from file metadata optional (#259)

This commit is contained in:
WithoutPants
2019-12-13 17:18:02 +11:00
committed by Leopere
parent 50784025f2
commit c05496a724
5 changed files with 18 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ input GenerateMetadataInput {
}
input ScanMetadataInput {
nameFromMetadata: Boolean!
useFileMetadata: Boolean!
}
input AutoTagMetadataInput {

View File

@@ -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
}

View File

@@ -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()
}

View File

@@ -17,7 +17,7 @@ import (
type ScanTask struct {
FilePath string
NameFromMetadata bool
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)
}

View File

@@ -21,7 +21,7 @@ interface IProps {}
export const SettingsTasksPanel: FunctionComponent<IProps> = (props: IProps) => {
const [isImportAlertOpen, setIsImportAlertOpen] = useState<boolean>(false);
const [isCleanAlertOpen, setIsCleanAlertOpen] = useState<boolean>(false);
const [nameFromMetadata, setNameFromMetadata] = useState<boolean>(true);
const [useFileMetadata, setUseFileMetadata] = useState<boolean>(false);
const [status, setStatus] = useState<string>("");
const [progress, setProgress] = useState<number | undefined>(undefined);
@@ -128,7 +128,7 @@ export const SettingsTasksPanel: FunctionComponent<IProps> = (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<IProps> = (props: IProps) =>
inline={true}
>
<Checkbox
checked={nameFromMetadata}
label="Set name from metadata (if present)"
onChange={() => setNameFromMetadata(!nameFromMetadata)}
checked={useFileMetadata}
label="Set name, date, details from metadata (if present)"
onChange={() => setUseFileMetadata(!useFileMetadata)}
/>
<Button id="scan" text="Scan" onClick={() => onScan()} />
</FormGroup>