Include gender in performer scraper results (#448)

* Fix scraper gender
* Set scraped gender in the UI
* Match gender on enum or case insensitive string
This commit is contained in:
WithoutPants
2020-04-11 13:26:53 +10:00
committed by GitHub
parent 6764c1f545
commit 849a5261a3
6 changed files with 57 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
fragment ScrapedPerformerData on ScrapedPerformer {
name
gender
url
twitter
instagram
@@ -20,6 +21,7 @@ fragment ScrapedPerformerData on ScrapedPerformer {
fragment ScrapedScenePerformerData on ScrapedScenePerformer {
id
name
gender
url
twitter
instagram
@@ -45,7 +47,6 @@ fragment ScrapedMovieData on ScrapedMovie {
director
url
synopsis
}
fragment ScrapedSceneMovieData on ScrapedSceneMovie {

View File

@@ -1,6 +1,7 @@
"""A performer from a scraping operation..."""
type ScrapedPerformer {
name: String
gender: String
url: String
twitter: String
instagram: String
@@ -22,6 +23,7 @@ type ScrapedPerformer {
input ScrapedPerformerInput {
name: String
gender: String
url: String
twitter: String
instagram: String

View File

@@ -27,6 +27,7 @@ type ScrapedScenePerformer {
"""Set if performer matched"""
id: ID
name: String!
gender: String
url: String
twitter: String
instagram: String
@@ -54,7 +55,6 @@ type ScrapedSceneMovie {
director: String
synopsis: String
url: String
}
type ScrapedSceneStudio {

View File

@@ -25,6 +25,7 @@ type ScrapedItem struct {
type ScrapedPerformer struct {
Name *string `graphql:"name" json:"name"`
Gender *string `graphql:"gender" json:"gender"`
URL *string `graphql:"url" json:"url"`
Twitter *string `graphql:"twitter" json:"twitter"`
Instagram *string `graphql:"instagram" json:"instagram"`
@@ -45,6 +46,7 @@ type ScrapedPerformer struct {
// this type has no Image field
type ScrapedPerformerStash struct {
Name *string `graphql:"name" json:"name"`
Gender *string `graphql:"gender" json:"gender"`
URL *string `graphql:"url" json:"url"`
Twitter *string `graphql:"twitter" json:"twitter"`
Instagram *string `graphql:"instagram" json:"instagram"`
@@ -91,6 +93,7 @@ type ScrapedScenePerformer struct {
// Set if performer matched
ID *string `graphql:"id" json:"id"`
Name string `graphql:"name" json:"name"`
Gender *string `graphql:"gender" json:"gender"`
URL *string `graphql:"url" json:"url"`
Twitter *string `graphql:"twitter" json:"twitter"`
Instagram *string `graphql:"instagram" json:"instagram"`

View File

@@ -100,11 +100,35 @@ export const PerformerDetailsPanel: React.FC<IPerformerDetails> = ({
);
}
function translateScrapedGender(gender?: string) {
if (!gender) {
return;
}
let retEnum : GQL.GenderEnum | undefined;
// try to translate from enum values first
const upperGender = gender?.toUpperCase();
const asEnum = StashService.genderToString(upperGender as GQL.GenderEnum);
if (asEnum) {
retEnum = StashService.stringToGender(asEnum);
} else {
// try to match against gender strings
const caseInsensitive = true;
retEnum = StashService.stringToGender(gender, caseInsensitive);
}
return StashService.genderToString(retEnum);
}
function updatePerformerEditStateFromScraper(
state: Partial<GQL.ScrapedPerformerDataFragment>
) {
updatePerformerEditState(state);
// gender is a string in the scraper data
setGender(translateScrapedGender(state.gender ?? undefined));
// image is a base64 string
// #404: don't overwrite image if it has been modified by the user
if (image === undefined && (state as GQL.ScrapedPerformerDataFragment).image !== undefined) {

View File

@@ -717,12 +717,26 @@ export class StashService {
}
}
public static stringToGender(value?: string) {
public static stringToGender(value?: string, caseInsensitive?: boolean) {
if (!value) {
return undefined;
}
return StashService.stringGenderMap.get(value);
const ret = StashService.stringGenderMap.get(value);
if (ret || !caseInsensitive) {
return ret;
}
const asUpper = value.toUpperCase();
const foundEntry = Array.from(StashService.stringGenderMap.entries()).find(
(e) => {
return e[0].toUpperCase() === asUpper;
}
);
if (foundEntry) {
return foundEntry[1];
}
}
public static getGenderStrings() {