Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scene metadata from file metadata optional #259

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphql/schema/types/metadata.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ input GenerateMetadataInput {
}

input ScanMetadataInput {
nameFromMetadata: Boolean!
useFileMetadata: Boolean!
}

input AutoTagMetadataInput {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/resolver_query_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/manager/manager_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/manager/task_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

type ScanTask struct {
FilePath string
NameFromMetadata bool
FilePath string
UseFileMetadata bool
}

func (t *ScanTask) Start(wg *sync.WaitGroup) {
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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},
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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>
Expand Down