-
-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add sub-scraper functionality * Add scraping of performer image * Add scene cover image scraping * Port UI changes to v2.5 * Fix v2.5 dialog suggest color * Don't convert eol of UI to support pretty
- Loading branch information
1 parent
5fb8bbf
commit 34d8293
Showing
21 changed files
with
665 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
go.mod text eol=lf | ||
go.sum text eol=lf | ||
go.sum text eol=lf | ||
ui/v2.5/** -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package scraper | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/stashapp/stash/pkg/models" | ||
"github.com/stashapp/stash/pkg/utils" | ||
) | ||
|
||
// Timeout to get the image. Includes transfer time. May want to make this | ||
// configurable at some point. | ||
const imageGetTimeout = time.Second * 30 | ||
|
||
func setPerformerImage(p *models.ScrapedPerformer) error { | ||
if p == nil || p.Image == nil || !strings.HasPrefix(*p.Image, "http") { | ||
// nothing to do | ||
return nil | ||
} | ||
|
||
img, err := getImage(*p.Image) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
p.Image = img | ||
|
||
return nil | ||
} | ||
|
||
func setSceneImage(s *models.ScrapedScene) error { | ||
// don't try to get the image if it doesn't appear to be a URL | ||
if s == nil || s.Image == nil || !strings.HasPrefix(*s.Image, "http") { | ||
// nothing to do | ||
return nil | ||
} | ||
|
||
img, err := getImage(*s.Image) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s.Image = img | ||
|
||
return nil | ||
} | ||
|
||
func getImage(url string) (*string, error) { | ||
client := &http.Client{ | ||
Timeout: imageGetTimeout, | ||
} | ||
|
||
// assume is a URL for now | ||
resp, err := client.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// determine the image type and set the base64 type | ||
contentType := resp.Header.Get("Content-Type") | ||
if contentType == "" { | ||
contentType = http.DetectContentType(body) | ||
} | ||
|
||
img := "data:" + contentType + ";base64," + utils.GetBase64StringFromData(body) | ||
return &img, nil | ||
} | ||
|
||
func getStashPerformerImage(stashURL string, performerID string) (*string, error) { | ||
return getImage(stashURL + "/performer/" + performerID + "/image") | ||
} | ||
|
||
func getStashSceneImage(stashURL string, sceneID string) (*string, error) { | ||
return getImage(stashURL + "/scene/" + sceneID + "/screenshot") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.