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

Find correct python executable #1156

Merged
merged 7 commits into from Mar 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/scraper/script.go
Expand Up @@ -30,6 +30,13 @@ func newScriptScraper(scraper scraperTypeConfig, config config, globalConfig Glo
func (s *scriptScraper) runScraperScript(inString string, out interface{}) error {
command := s.scraper.Script

if command[0] == "python" || command[0] == "python3" {
executable, err := findPythonExecutable()
if err == nil {
command[0] = executable
}
}

cmd := exec.Command(command[0], command[1:]...)
cmd.Dir = filepath.Dir(s.config.path)

Expand Down Expand Up @@ -184,3 +191,19 @@ func (s *scriptScraper) scrapeMovieByURL(url string) (*models.ScrapedMovie, erro

return &ret, err
}

func findPythonExecutable() (string, error) {
_, err := exec.LookPath("python3")

if err != nil {
_, err = exec.LookPath("python")

if err != nil {
return "", err
}

return "python", nil
}

return "python3", nil
}
1 change: 1 addition & 0 deletions ui/v2.5/src/components/Changelog/versions/v060.md
@@ -1,4 +1,5 @@
### 🎨 Improvements
* Resolve python executable to `python3` or `python` for python script scrapers.
* Add `url` field to `URLReplace`, and make `queryURLReplace` available when scraping by URL.
* Make logging format consistent across platforms and include full timestamp.
* Remember gallery images view mode.
Expand Down
3 changes: 2 additions & 1 deletion ui/v2.5/src/docs/en/Scraping.md
Expand Up @@ -85,7 +85,8 @@ script:
- query
```

This configuration would execute `python iafdScrape.py query`.
Stash will find the correct python executable for your system, either `python` or `python3`. So for example. this configuration could execute `python iafdScrape.py query` or `python3 iafdScrape.py query`.
SpedNSFW marked this conversation as resolved.
Show resolved Hide resolved
`python3` will be looked for first and if it's not found, we'll check for `python`. In the case neither are found, you will get an error.

Stash sends data to the script process's `stdin` stream and expects the output to be streamed to the `stdout` stream. Any errors and progress messages should be output to `stderr`.

Expand Down