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 3 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" {
SpedNSFW marked this conversation as resolved.
Show resolved Hide resolved
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
}
2 changes: 1 addition & 1 deletion ui/v2.5/src/docs/en/Scraping.md
Expand Up @@ -85,7 +85,7 @@ 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

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