@ -44,10 +44,12 @@ try: # Try importing Python 3 modules
import urllib . request as urllib2
import urllib . request as urllib2
# noinspection PyUnresolvedReferences,PyCompatibility
# noinspection PyUnresolvedReferences,PyCompatibility
from urllib . parse import urlencode
from urllib . parse import urlencode
except ImportError : # On error import Python 2 modules using new nam es
except ImportError : # On error, import Python 2 modules
# noinspection PyPep8Naming
# noinspection PyPep8Naming,PyUnresolvedReferences
import ConfigParser as configparser
import ConfigParser as configparser
# noinspection PyUnresolvedReferences
import urllib2
import urllib2
# noinspection PyUnresolvedReferences
from urllib import urlencode
from urllib import urlencode
@ -56,32 +58,25 @@ def process_files(dir_to_process, org_nzb_name=None, status=None):
# Default values
# Default values
host = ' localhost '
host = ' localhost '
port = ' 8081 '
port = ' 8081 '
username = ' '
default_url = ' http:// %s : %s / ' % ( host , port )
password = ' '
ssl = username = password = ' '
ssl = 0
web_root = ' / '
web_root = ' / '
default_url = host + ' : ' + port + web_root
if ssl :
default_url = ' https:// ' + default_url
else :
default_url = ' http:// ' + default_url
# Get values from config_file
# Get values from config_file
config = configparser . RawConfigParser ( )
config = configparser . RawConfigParser ( )
config_filename = os . path . join ( os . path . dirname ( sys . argv [ 0 ] ) , ' autoProcessTV.cfg ' )
config_filename = os . path . join ( os . path . dirname ( sys . argv [ 0 ] ) , ' autoProcessTV.cfg ' )
if not os . path . isfile ( config_filename ) :
if not os . path . isfile ( config_filename ) :
print ( ' ERROR: ' + config_filename + " doesn ' t exist " )
print ( ' ERROR: %s doesn \' t exist ' % config_filename )
print ( ' copy /rename ' + config_filename + ' .sample and edit \n ' )
print ( ' copy /rename %s .sample and edit \n ' % config_filename )
print ( ' Trying default url: ' + default_url + ' \n ' )
print ( ' Trying default url: %s \n ' % default_url )
else :
else :
try :
try :
print ( ' Loading config from ' + config_filename + ' \n ' )
print ( ' Loading config from %s \n ' % config_filename )
with open ( config_filename , ' r ' ) as fp :
with open ( config_filename , ' r ' ) as fp :
config . readfp ( fp )
config . read_file ( fp )
# Replace default values with config_file values
# Replace default values with config_file values
host = config . get ( ' SickBeard ' , ' host ' )
host = config . get ( ' SickBeard ' , ' host ' )
@ -90,18 +85,14 @@ def process_files(dir_to_process, org_nzb_name=None, status=None):
password = config . get ( ' SickBeard ' , ' password ' )
password = config . get ( ' SickBeard ' , ' password ' )
try :
try :
ssl = int ( config . get ( ' SickBeard ' , ' ssl ' ) )
ssl = int ( config . get ( ' SickBeard ' , ' ssl ' ) ) and ' s ' or ' '
except ( configparser . NoOptionError , ValueError ) :
except ( configparser . NoOptionError , ValueError ) :
pass
pass
try :
try :
web_root = config . get ( ' SickBeard ' , ' web_root ' )
web_root = config . get ( ' SickBeard ' , ' web_root ' )
if not web_root . startswith ( ' / ' ) :
web_root = ( ' / %s / ' % web_root . strip ( ' / ' ) ) . replace ( ' // ' , ' / ' )
web_root = ' / ' + web_root
if not web_root . endswith ( ' / ' ) :
web_root = web_root + ' / '
except configparser . NoOptionError :
except configparser . NoOptionError :
pass
pass
@ -120,13 +111,9 @@ def process_files(dir_to_process, org_nzb_name=None, status=None):
if None is not status :
if None is not status :
params [ ' failed ' ] = status
params [ ' failed ' ] = status
if ssl :
url = ' http %s :// %s : %s %s ' % ( ssl , host , port , web_root )
protocol = ' https:// '
login_url = url + ' login '
else :
url = url + ' home/process-media/files '
protocol = ' http:// '
url = protocol + host + ' : ' + port + web_root + ' home/process-media/files '
login_url = protocol + host + ' : ' + port + web_root + ' login '
print ( ' Opening URL: ' + url )
print ( ' Opening URL: ' + url )
@ -142,7 +129,7 @@ def process_files(dir_to_process, org_nzb_name=None, status=None):
if 401 == result . status_code :
if 401 == result . status_code :
print ( ' Verify and use correct username and password in autoProcessTV.cfg ' )
print ( ' Verify and use correct username and password in autoProcessTV.cfg ' )
else :
else :
for line in result . iter_lines ( ) :
for line in result . iter_lines ( decode_unicode = True ) :
if line :
if line :
print ( line . strip ( ) )
print ( line . strip ( ) )