Custom script + Windows 7 (Can't execute file?)

I’m new to python… Pretty much only know the basics.

Anyways… I’m trying to get plex to update just the series, when a show finishes downloading. I played with it for 5 hours…trying different ways… Only to realize Sonarr wouldn’t execute “subprocess.call()”, or os.system.

Here is the script I’m currently trying -

import os
import sys
import logging
import subprocess

program="C:\PROGRA~2\Plex\PLEXME~1\PLEXME~2.EXE"
arguments=" --scan --refresh --section 02 --directory "
episode = os.environ.get('Sonarr_EpisodeFile_Path')
folderz = os.environ.get('Sonarr_Series_Path')
folder = '"' + str(folderz) + '"'
subprocess.call([program, arguments, folder])




#Testing section
#folderztest="X:\TV\TV\Supernatural"
#foldertest = '"' + str(folderztest) + '"'


#print "%s %s %s" % (program, arguments, foldertest)

file = open("d:\\Newsgroups\\scripts\\newfile.txt", "w")
file.write(program)
file.write(arguments)
file.write(folder)
file.close()

No errors show up in sonarrs log, the file gets created, with the command that looks right (If I run it in a dos prompt, it’ll scan). But it won’t scan by itself.

I’ve also tried to dumb it down… I made a .bat file with the command “C:\PROGRA~2\Plex\PLEXME~1\PLEXME~2.EXE --scan --refresh --section 02 --directory c:\blahblahtvshow” It runs in dos… However if I make a very simple:

import os
import sys
import logging
import subprocess

test="d:\\Newsgroups\\scripts\\newfile.bat"
subprocess.call([test])

Sonarr still will not execute the .bat file… However if I open it with python, again it works perfectly.

Am I going about it the wrong way? Or is it a bug / limitation, etc? Banging my head against the wall… I don’t think I have the patience for programming ;p

Sonarr will update just the changed series if partial scans are enabled in Plex, no need to do it via a custom script.

Doesn’t work for me. I use a pooling software…(15 HD’s, 50+ TB), And anytime a new show is added, even with partial scans… Plex will update the whole library… which as you can imagine, takes a long time.

Narrowed it down… the error is from plex media scanner… “[“Error: Section doesn’t exist.\r\n”, ‘\r\n’” Even though it does. It’ll run in a bat… but when trying to do it automatically through sonar, it wont work for some reason.

It definitely works with pooling software (using it with Drive Bender myself), requires PMS 0.9.13.0+ and:

Hmm… Drivebender is what I’m using, but it scans it all.

Are you sure on the PMS version #? I have 0.9.12… Cant find 0.9.13 posted anywhere.

I do have partial scan selected… also had library automatically though. I’ll try with just run partial.

I also found out why plex was having issues. It seems when Sonarr is running as a windows service… it won’t execute files. I disabled the service, opened the exe, and now it works with plex. Though, if partial scan works… of course I’d prefer that, so I’ll give it a try.

[Edit] I was mistaken… I did only have partial scan checked. And no, everytime sonarr tells it I have a new episode, it begins to scan my whole library.

Sorry, not 0.9.13.0, I meant 0.9.12.13 - the latest is currently: 0.9.12.13.1464-4ccd2ca, there might be an earlier release that also works, but that one does have it for sure.

OP related - you need '\' in python. ‘\’ is an escape character for python.

LJ

If you turn on trace logs in Sonarr you will see the responses from Plex, which will indicate whether it found the series in a section and if it will be doing a partial or full scan of the section.

lordjynx7h
ikarazu:
C:\PROGRA~2\Plex\PLEXME~1\PLEXME~2.EXE
OP related - you need ‘\’ in python. '' is an escape character for python.

LJ

Surprisingly, it still worked. I fixed it just to be sure, but the problem wasn't executing plex... it was plex not accepting the arguments, or acting like it didn't get them. 

I did manage to get it to work, though. 


import os
import subprocess
import sys

# command to call
cmd = os.path.join(r"C:\Program Files (x86)\Plex\Plex Media Server",
                   "Plex Media Scanner.exe")

# get first argument passed to script
arg = os.environ.get('Sonarr_Series_Path') 

# convert first character of argument to upper case
arg = arg[0].upper() + arg[1:]

# call the new command
subprocess.call([cmd, "--scan", "--section", "02", "--directory", arg])

I was ready to give up, then had a friend re-send me the script I used to use for mp3s and Sabnzbd…noticed it looked mighty familiar, so I changed it around and bit… and what do you know, it worked.

markus101Team Sonarr23h
Sonarr will update just the changed series if partial scans are enabled in Plex, no need to do it via a custom script.

I’m going by this post - Plex Media Server - Refresh TV Series Only vs Full Library Update - #9 by fanboy

I realize it’s almost a year old… but has something changed? I thought if sonarr triggers a scan, it’ll re-scan the whole category (IE: All TV shows).

I’ve tried to have sonarr not integrate with plex at all… had update library automatically, and run partial scan turned on, but it always re-scanned the whole thing again.

It may be something to do with my specific setup… I don’t know. I’m happy with this little script though… And glad custom scripts are being supported now, I’ve been waiting / hoping for this for a long time, So thanks for all the work on adding it!

Yes, a couple months ago we introduced partial scanning for Plex.

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