mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Find correct python executable (#1156)
* find correct python executable For script scrapers using python, both python and python3 are valid depending on the OS and running environment. To save users from having any issues, this change will find the correct executable for them. Co-authored-by: bnkai <bnkai@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user