Custom Scripts Error on Win 7

Hi,

I’m running Win 7 with the deveop branch of Sonarr.

I’m having a issue getting the custom script notification working. I’m trying to get it to call Sickbeard_MP4_converter when the episode file changes.

Heres the error I’m getting no matter what I do:

[code]Details

        Message
        Unable to send OnRename notification to: Post Conversion and tagging: The specified executable is not a valid application for this OS platform.

            

            Exception
            System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.

at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at NzbDrone.Common.Processes.ProcessProvider.Start(String path, String args, StringDictionary environmentVariables, Action1 onOutputDataReceived, Action1 onErrorDataReceived) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Common\Processes\ProcessProvider.cs:line 167
at NzbDrone.Common.Processes.ProcessProvider.StartAndCapture(String path, String args, StringDictionary environmentVariables) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Common\Processes\ProcessProvider.cs:line 199
at NzbDrone.Core.Notifications.CustomScript.CustomScriptService.ExecuteScript(StringDictionary environmentVariables, CustomScriptSettings settings) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScriptService.cs:line 86
at NzbDrone.Core.Notifications.CustomScript.CustomScriptService.OnRename(Series series, CustomScriptSettings settings) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScriptService.cs:line 69
at NzbDrone.Core.Notifications.CustomScript.CustomScript.OnRename(Series series) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScript.cs:line 32
at NzbDrone.Core.Notifications.NotificationService.Handle(SeriesRenamedEvent message) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\NotificationService.cs:line 149[/code]

this is the Custom Script settings in Sonarr:

and this is the current Sample script I’m trying to use:

[code]#!/usr/bin/env php

<?php // Do some echoing, why? why not.. echo "Starting the Sonarr.php postprocessing script\n"; // for some reason, environment variables from the cli is hiding in $_SERVER, don't ask me, php is silly sometimes $envVars = $_SERVER; // All the env variables attached to variables $title = isset($envVars["sonarr_series_title"]) ? $envVars["sonarr_series_title"] : null; // Not Safe for Work (2015) $filePath = isset($envVars["sonarr_episodefile_path"]) ? $envVars["sonarr_episodefile_path"] : null; // /storage/TV Shows/Not Safe for Work (2015)/Season 1/Not Safe for Work (2015) - S01E01 - Episode 1.mkv $sceneName = isset($envVars["sonarr_episodefile_scenename"]) ? $envVars["sonarr_episodefile_scenename"] : null; // "Not.Safe.For.Work.UK.S01E01.720p.HDTV.x264-TLA $airDate = isset($envVars["sonarr_episodefile_episodeairdatesutc"]) ? $envVars["sonarr_episodefile_episodeairdatesutc"] : null; // 6/30/2015 8:00:00 PM $seasonNumber = isset($envVars["sonarr_episodefile_seasonnumber"]) ? $envVars["sonarr_episodefile_seasonnumber"] : null; // 1 $relativePath = isset($envVars["sonarr_episodefile_relativepath"]) ? $envVars["sonarr_episodefile_relativepath"] : null; // Season 1/Not Safe for Work (2015) - S01E01 - Episode 1.mkv $eventType = isset($envVars["sonarr_eventtype"]) ? $envVars["sonarr_eventtype"] : null; // Download $episodeAirDates = isset($envVars["sonarr_episodefile_episodeairdates"]) ? $envVars["sonarr_episodefile_episodeairdates"] : null; // 2015-06-30 $seriesID = isset($envVars["sonarr_series_id"]) ? $envVars["sonarr_series_id"] : null; // 339 $seriesPath = isset($envVars["sonarr_series_path"]) ? $envVars["sonarr_series_path"] : null; // /storage/TV Shows/Not Safe for Work (2015) $tvdbID = isset($envVars["sonarr_series_tvdbid"]) ? $envVars["sonarr_series_tvdbid"] : null; // 297084 $episodeNumbers = isset($envVars["sonarr_episodefile_episodenumbers"]) ? $envVars["sonarr_episodefile_episodenumbers"] : null; // 1 $fileID = isset($envVars["sonarr_episodefile_id"]) ? $envVars["sonarr_episodefile_id"] : null; // 27224 $releaseGroup = isset($envVars["sonarr_episodefile_releasegroup"]) ? $envVars["sonarr_episodefile_releasegroup"] : null; // tla $quality = isset($envVars["sonarr_episodefile_quality"]) ? $envVars["sonarr_episodefile_quality"] : null; // HDTV-720p $qualityVersion = isset($envVars["sonarr_episodefile_qualityversion"]) ? $envVars["sonarr_episodefile_qualityversion"] : null; // 1 // If the event isn't download, just die here // if($eventType != "Download") // die(); // Make sure the filepath is set if($filePath != null) { // make sure the file path is actually real if(file_exists($filePath)) { // Dump some stuff into the log file_put_contents("C:\Scripts\convert.log", "Converting {$filePath}", FILE_APPEND); // Now execute the sickbeard mp4 converter so we can convert the file to an mp4 with the settings we've set exec('C:\Python27\python C:\Scripts\manual.py -a -i "'.$filePath.'"'); } }[/code]

Path and Arguments should never be the same.

You can either make .py executable (tell them to open with python) and clear the Arguments field or set the Path to run python.exe and leave the Arguments the path to the python file.

Looks like your script is mixing in php, but its supposed to be python, you’ll want to clean that up as well.

Sonarr auto fills the Arguments field from Path. Every change I make in Paths is auto added to Arguments, and vice versa.

I tried a Python file first and got the same error, so the PHP file I’m trying to use now is a edited version of the sample Sonarr.php file from the wiki FAQ page.

Here is the Python file I was initially trying that I got from mdhiggins (sickbeard_mp4_convertor creator). I get the same error with it.


#!/usr/bin/env python
import os
import sys
import logging
from readSettings import ReadSettings
from autoprocess import plex
from tvdb_mp4 import Tvdb_mp4
from mkvtomp4 import MkvtoMp4
from post_processor import PostProcessor
from logging.config import fileConfig

fileConfig(os.path.join(os.path.dirname(sys.argv[0]), 'logging.ini'), defaults={'logfilename': os.path.join(os.path.dirname(sys.argv[0]), 'info.log')})
log = logging.getLogger("SonarrPostConversion")

log.info("Sonarr extra script post processing started.")

settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini")

inputfile = os.environ.get('Sonarr.EpisodeFile.Path')
original = os.environ.get('Sonarr.EpisodeFile.SceneName')
tvdb_id = int(os.environ.get('Sonarr.Series.TvdbId'))
season = int(os.environ.get('Sonarr.EpisodeFile.SeasonNumber'))
try:
    episode = int(os.environ.get('Sonarr.EpisodeFile.EpisodeNumbers'))
except:
    episode = int(os.environ.get('Sonarr.EpisodeFile.EpisodeNumbers').split(",")[0])

converter = MkvtoMp4(settings)

log.debug("Input file: %s." % inputfile)
log.debug("Original name: %s." % original)
log.debug("TVDB ID: %s." % tvdb_id)
log.debug("Season: %s episode: %s." % (season, episode))

if MkvtoMp4(settings).validSource(inputfile):
    log.info("Processing %s." % inputfile)

    output = converter.process(inputfile, original=original)

    # Tag with metadata
    if settings.tagfile:
        log.info("Tagging %s with ID %s season %s episode %s." % (inputfile, tvdb_id, season, episode))
        tagmp4 = Tvdb_mp4(tvdb_id, season, episode, original, language=settings.taglanguage)
        tagmp4.setHD(output['x'], output['y'])
        tagmp4.writeTags(output['output'], settings.artwork)

    #QTFS
    if settings.relocate_moov:
        converter.QTFS(output['output'])

    # Copy to additional locations
    output_files = converter.replicate(output['output'])

    # run any post process scripts
    if settings.postprocess:
        post_processor = PostProcessor(output_files, log)
        post_processor.setTV(tvdb_id, season, episode)
        post_processor.run_scripts()

    plex.refreshPlex(settings, 'show', log)

This seems to be a bug, we’ll have to look into it.

If you double click on the php or py file does it execute it? If not you’ll need to setup your system to do so.

.py files are set to run with python automatically so yes they run on from the system fine.

looking in the nzbdrone.db under notifications there is no Arguments field just one for the Path. maybe both fields are linked to same entry and causing the issue?

Yeah, that was the issue, they were both linked to path. The next release will have that fixed. The execution issue isn’t as easily fixed, we’ll have to do some testing, but at least you’ll be able to use Path + Arguments.

Just a heads up, we realized that . in Environment variable names is unsupported so we’ll be switching over to _ instead in a future version (before we release this to master).

Hey Markus,

Just updated to the new dev version with the fixed paths/arguments fields and that seems to be working correctly as paths and arguments can be different now. That’s the good news… the bad news is its still not Running correctly. I’m getting a access denied error now. I’ve checked my path and opened up the rights on The folder and file so Sonarr should have 100% access to the script. I found if you put the full path plus the script in the Paths field you get a OS unrecognized format error. That’s why I have it set with the script in the Arguments field. Anything you see that I maybe missed would be greatly appreciated or if you have a sample custom scripts that you know works that i can look at.

Here’s a SS of the Custom connection settings in Sonarr:

This is the error I’m getting when I try and run the script:

Details

        
        
            Message
            Unable to send OnDownload notification to: Post Conversion and tagging: Access is denied

                

                Exception
                System.ComponentModel.Win32Exception (0x80004005): Access is denied
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at NzbDrone.Common.Processes.ProcessProvider.Start(String path, String args, StringDictionary environmentVariables, Action`1 onOutputDataReceived, Action`1 onErrorDataReceived) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Common\Processes\ProcessProvider.cs:line 167
   at NzbDrone.Common.Processes.ProcessProvider.StartAndCapture(String path, String args, StringDictionary environmentVariables) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Common\Processes\ProcessProvider.cs:line 199
   at NzbDrone.Core.Notifications.CustomScript.CustomScriptService.ExecuteScript(StringDictionary environmentVariables, CustomScriptSettings settings) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScriptService.cs:line 88
   at NzbDrone.Core.Notifications.CustomScript.CustomScriptService.OnDownload(Series series, EpisodeFile episodeFile, String sourcePath, CustomScriptSettings settings) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScriptService.cs:line 58
   at NzbDrone.Core.Notifications.CustomScript.CustomScript.OnDownload(DownloadMessage message) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScript.cs:line 27
   at NzbDrone.Core.Notifications.NotificationService.Handle(EpisodeDownloadedEvent message) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\NotificationService.cs:line 132
        

This is the Script Code:

#!/usr/bin/env python
import os
import sys
import logging
from readSettings import ReadSettings
from autoprocess import plex
from tvdb_mp4 import Tvdb_mp4
from mkvtomp4 import MkvtoMp4
from post_processor import PostProcessor
from logging.config import fileConfig

fileConfig(os.path.join(os.path.dirname(sys.argv[0]), 'logging.ini'), defaults={'logfilename': os.path.join(os.path.dirname(sys.argv[0]), 'info.log')})
log = logging.getLogger("SonarrPostConversion")

log.info("Sonarr extra script post processing started.")

settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini")

inputfile = os.environ.get('Sonarr_EpisodeFile_Path')
original = os.environ.get('Sonarr_EpisodeFile_SceneName')
tvdb_id = int(os.environ.get('Sonarr_Series_TvdbId'))
season = int(os.environ.get('Sonarr_EpisodeFile_SeasonNumber'))
try:
    episode = int(os.environ.get('Sonarr_EpisodeFile_EpisodeNumbers'))
except:
    episode = int(os.environ.get('Sonarr_EpisodeFile_EpisodeNumbers').split(",")[0])

converter = MkvtoMp4(settings)

log.debug("Input file: %s." % inputfile)
log.debug("Original name: %s." % original)
log.debug("TVDB ID: %s." % tvdb_id)
log.debug("Season: %s episode: %s." % (season, episode))

if MkvtoMp4(settings).validSource(inputfile):
    log.info("Processing %s." % inputfile)

    output = converter.process(inputfile, original=original)

    # Tag with metadata
    if settings.tagfile:
        log.info("Tagging %s with ID %s season %s episode %s." % (inputfile, tvdb_id, season, episode))
        tagmp4 = Tvdb_mp4(tvdb_id, season, episode, original, language=settings.taglanguage)
        tagmp4.setHD(output['x'], output['y'])
        tagmp4.writeTags(output['output'], settings.artwork, settings.thumbnail)

    #QTFS
    if settings.relocate_moov:
        converter.QTFS(output['output'])

    # Copy to additional locations
    output_files = converter.replicate(output['output'])

    # run any post process scripts
    if settings.postprocess:
        post_processor = PostProcessor(output_files, log)
        post_processor.setTV(tvdb_id, season, episode)
        post_processor.run_scripts()

    plex.refreshPlex(settings, 'show', log)

Where do you get that error?

You can’t put a folder in the path with the script name in the arguments, that won’t work.

This is the error I get when I put the full path + script into paths

Details

        
        
            Message
            Unable to send OnDownload notification to: Post Conversion: The specified executable is not a valid application for this OS platform.

                

                Exception
                System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at NzbDrone.Common.Processes.ProcessProvider.Start(String path, String args, StringDictionary environmentVariables, Action`1 onOutputDataReceived, Action`1 onErrorDataReceived) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Common\Processes\ProcessProvider.cs:line 167
   at NzbDrone.Common.Processes.ProcessProvider.StartAndCapture(String path, String args, StringDictionary environmentVariables) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Common\Processes\ProcessProvider.cs:line 199
   at NzbDrone.Core.Notifications.CustomScript.CustomScriptService.ExecuteScript(StringDictionary environmentVariables, CustomScriptSettings settings) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScriptService.cs:line 88
   at NzbDrone.Core.Notifications.CustomScript.CustomScriptService.OnDownload(Series series, EpisodeFile episodeFile, String sourcePath, CustomScriptSettings settings) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScriptService.cs:line 58
   at NzbDrone.Core.Notifications.CustomScript.CustomScript.OnDownload(DownloadMessage message) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\CustomScript\CustomScript.cs:line 27
   at NzbDrone.Core.Notifications.NotificationService.Handle(EpisodeDownloadedEvent message) in m:\BuildAgent\work\6c3239faf2b92630\src\NzbDrone.Core\Notifications\NotificationService.cs:line 132
        

this is what the Custom script settings look like when i get that error. it doesn’t matter if the file is py, php, or a vbs file they all get the same error when its setup like this.

Sorry for the double post but just got it to work with this setup:

not sure why sonarr needs the path to python.exe to be declared even tho its already in the system paths on the machine but it works when you do.

Are you running Sonarr as a Windows service? I wonder if thats the issue here.

no I don’t have it running as a service, I’ve found it tends to hang on startup when its a service and a I’d have to force kill the service to get it started correctly.

Hmm, that would have been too easy I guess, I’m going to go ahead and blame Windows for this one, though I’m not sure why it would care.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.