Merge pull request #406 from sirenum/master

Fixes Issue #334 and improves a few things, this fixes #334
This commit is contained in:
Stephan Raue 2012-04-10 04:57:16 -07:00
commit 7696d7c099
8 changed files with 467 additions and 482 deletions

View File

@ -2,4 +2,5 @@
<setting id="SABNZBD_IP" value="0.0.0.0" />
<setting id="SABNZBD_PWD" value="" />
<setting id="SABNZBD_USER" value="" />
<setting id="SABNZBD_KEEP_AWAKE" value="false" />
</settings>

View File

@ -0,0 +1,401 @@
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2012 Lukas Heiniger
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
# Initializes and launches SABnzbd, Couchpotato, Sickbeard and Headphones
import os
import shutil
import xbmc
import signal
import subprocess
import urllib2
from configobj import ConfigObj
from xml.dom.minidom import parseString
import logging
logging.basicConfig(filename='/var/log/sabnzbd-suite.log',
filemode='w',
format='%(asctime)s SABnzbd-Suite: %(message)s',
level=logging.WARNING)
# helper functions
# ----------------
def createDir(dir):
if not os.path.isdir(dir):
os.makedirs(dir)
def getAddonSetting(doc,id):
for element in doc.getElementsByTagName('setting'):
if element.getAttribute('id')==id:
return element.getAttribute('value')
def loadWebInterface(url,user,pwd):
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, pwd)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
pagehandle = urllib2.urlopen(url)
return pagehandle.read()
# define some things that we're gonna need, mainly paths
# ------------------------------------------------------
# addon
pAddon = os.path.expanduser('~/.xbmc/addons/service.downloadmanager.SABnzbd-Suite')
pAddonHome = os.path.expanduser('~/.xbmc/userdata/addon_data/service.downloadmanager.SABnzbd-Suite')
# settings
pDefaultSuiteSettings = os.path.join(pAddon, 'settings-default.xml')
pSuiteSettings = os.path.join(pAddonHome, 'settings.xml')
pXbmcSettings = '/storage/.xbmc/userdata/guisettings.xml'
pSabNzbdSettings = os.path.join(pAddonHome, 'sabnzbd.ini')
pSickBeardSettings = os.path.join(pAddonHome, 'config.ini')
pCouchPotatoSettings = os.path.join(pAddonHome, 'couchpotato.ini')
pHeadphonesSettings = os.path.join(pAddonHome, 'headphones.ini')
# directories
pSabNzbdComplete = '/storage/downloads'
pSabNzbdCompleteMov = '/storage/downloads/movies'
pSabNzbdCompleteMusic = '/storage/downloads/music'
pSabNzbdIncomplete = '/storage/downloads/incomplete'
pSickBeardTvScripts = os.path.join(pAddon, 'SickBeard/autoProcessTV')
pSabNzbdScripts = os.path.join(pAddonHome, 'scripts')
# pylib
pPylib = os.path.join(pAddon, 'pylib')
# service commands
sabnzbd = ['python', os.path.join(pAddon, 'SABnzbd/SABnzbd.py'),
'-d', '-f', pSabNzbdSettings, '-l 0']
sickBeard = ['python', os.path.join(pAddon, 'SickBeard/SickBeard.py'),
'--daemon', '--datadir', pAddonHome]
couchPotato = ['python', os.path.join(pAddon, 'CouchPotato/CouchPotato.py'),
'-d', '--datadir', pAddonHome, '--config', pCouchPotatoSettings]
headphones = ['python', os.path.join(pAddon, 'Headphones/Headphones.py'),
'-d', '--datadir', pAddonHome, '--config', pHeadphonesSettings]
# Other stuff
sabNzbdHost = '127.0.0.1:8081'
addonId = 'service.downloadmanager.SABnzbd-Suite'
# create directories and settings on first launch
# -----------------------------------------------
firstLaunch = not os.path.exists(pSabNzbdSettings)
if firstLaunch:
logging.debug('First launch, creating directories')
createDir(pAddonHome)
createDir(pSabNzbdComplete)
createDir(pSabNzbdCompleteMov)
createDir(pSabNzbdCompleteMusic)
createDir(pSabNzbdIncomplete)
createDir(pSabNzbdScripts)
shutil.copy(os.path.join(pSickBeardTvScripts,'sabToSickBeard.py'), pSabNzbdScripts)
shutil.copy(os.path.join(pSickBeardTvScripts,'autoProcessTV.py'), pSabNzbdScripts)
os.chmod(os.path.join(pSabNzbdScripts,'sabToSickBeard.py'), 0755)
# the settings file already exists if the user set settings before the first launch
if not os.path.exists(pSuiteSettings):
shutil.copy(pDefaultSuiteSettings, pSuiteSettings)
# make utilities executable
for utility in {'par2','unrar','unzip'}:
os.chmod(os.path.join(pAddon, 'bin', utility), 0755)
# read addon and xbmc settings
# ----------------------------
# SABnzbd-Suite
fSuiteSettings = open(pSuiteSettings, 'r')
data = fSuiteSettings.read()
fSuiteSettings.close
suiteSettings = parseString(data)
user = getAddonSetting(suiteSettings, 'SABNZBD_USER')
pwd = getAddonSetting(suiteSettings, 'SABNZBD_PWD')
host = getAddonSetting(suiteSettings, 'SABNZBD_IP')
sabNzbdKeepAwake = getAddonSetting(suiteSettings, 'SABNZBD_KEEP_AWAKE')
# XBMC
fXbmcSettings = open(pXbmcSettings, 'r')
data = fXbmcSettings.read()
fXbmcSettings.close
xbmcSettings = parseString(data)
xbmcServices = xbmcSettings.getElementsByTagName('services')[0]
xbmcPort = xbmcServices.getElementsByTagName('webserverport')[0].firstChild.data
try:
xbmcUser = xbmcServices.getElementsByTagName('webserverusername')[0].firstChild.data
except:
xbmcUser = ''
try:
xbmcPwd = xbmcServices.getElementsByTagName('webserverpassword')[0].firstChild.data
except:
xbmcPwd = ''
# prepare execution environment
# -----------------------------
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
os.environ['PYTHONPATH'] = str(os.environ.get('PYTHONPATH')) + ':' + pPylib
# write SABnzbd settings
# ----------------------
sabNzbdConfig = ConfigObj(pSabNzbdSettings,create_empty=True)
defaultConfig = ConfigObj()
defaultConfig['misc'] = {}
defaultConfig['misc']['disable_api_key'] = '0'
defaultConfig['misc']['check_new_rel'] = '0'
defaultConfig['misc']['auto_browser'] = '0'
defaultConfig['misc']['username'] = user
defaultConfig['misc']['password'] = pwd
defaultConfig['misc']['port'] = '8081'
defaultConfig['misc']['https_port'] = '9081'
defaultConfig['misc']['https_cert'] = 'server.cert'
defaultConfig['misc']['https_key'] = 'server.key'
defaultConfig['misc']['host'] = host
defaultConfig['misc']['web_dir'] = 'Plush'
defaultConfig['misc']['web_dir2'] = 'Plush'
defaultConfig['misc']['web_color'] = 'gold'
defaultConfig['misc']['web_color2'] = 'gold'
defaultConfig['misc']['log_dir'] = 'logs'
defaultConfig['misc']['admin_dir'] = 'admin'
defaultConfig['misc']['nzb_backup_dir'] = 'backup'
defaultConfig['misc']['script_dir'] = 'scripts'
if firstLaunch:
defaultConfig['misc']['download_dir'] = pSabNzbdIncomplete
defaultConfig['misc']['complete_dir'] = pSabNzbdComplete
servers = {}
servers['localhost'] = {}
servers['localhost']['host'] = 'localhost'
servers['localhost']['port'] = '119'
servers['localhost']['enable'] = '0'
categories = {}
categories['tv'] = {}
categories['tv']['name'] = 'tv'
categories['tv']['script'] = 'sabToSickBeard.py'
categories['tv']['priority'] = '-100'
categories['movies'] = {}
categories['movies']['name'] = 'movies'
categories['movies']['dir'] = 'movies'
categories['movies']['priority'] = '-100'
categories['music'] = {}
categories['music']['name'] = 'music'
categories['music']['dir'] = 'music'
categories['music']['priority'] = '-100'
defaultConfig['servers'] = servers
defaultConfig['categories'] = categories
sabNzbdConfig.merge(defaultConfig)
sabNzbdConfig.write()
# also keep the autoProcessTV config up to date
autoProcessConfig = ConfigObj(os.path.join(pSabNzbdScripts, 'autoProcessTV.cfg'), create_empty=True)
defaultConfig = ConfigObj()
defaultConfig['SickBeard'] = {}
defaultConfig['SickBeard']['host'] = 'localhost'
defaultConfig['SickBeard']['port'] = '8082'
defaultConfig['SickBeard']['username'] = user
defaultConfig['SickBeard']['password'] = pwd
autoProcessConfig.merge(defaultConfig)
autoProcessConfig.write()
# launch SABnzbd and get the API key
# ----------------------------------
logging.debug('Launching SABnzbd...')
subprocess.call(sabnzbd)
logging.debug('...done')
# SABnzbd will only complete the .ini file when we first access the web interface
if firstLaunch:
loadWebInterface('http://' + sabNzbdHost,user,pwd)
sabNzbdConfig.reload()
sabNzbdApiKey = sabNzbdConfig['misc']['api_key']
logging.debug('SABnzbd api key: ' + sabNzbdApiKey)
# write SickBeard settings
# ------------------------
sickBeardConfig = ConfigObj(pSickBeardSettings,create_empty=True)
defaultConfig = ConfigObj()
defaultConfig['General'] = {}
defaultConfig['General']['launch_browser'] = '0'
defaultConfig['General']['version_notify'] = '0'
defaultConfig['General']['log_dir'] = 'logs'
defaultConfig['General']['web_port'] = '8082'
defaultConfig['General']['web_host'] = host
defaultConfig['General']['web_username'] = user
defaultConfig['General']['web_password'] = pwd
defaultConfig['SABnzbd'] = {}
defaultConfig['SABnzbd']['sab_username'] = user
defaultConfig['SABnzbd']['sab_password'] = pwd
defaultConfig['SABnzbd']['sab_apikey'] = sabNzbdApiKey
defaultConfig['SABnzbd']['sab_host'] = 'http://' + sabNzbdHost + '/'
defaultConfig['XBMC'] = {}
defaultConfig['XBMC']['use_xbmc'] = '1'
defaultConfig['XBMC']['xbmc_host'] = '127.0.0.1:' + xbmcPort
defaultConfig['XBMC']['xbmc_username'] = xbmcUser
defaultConfig['XBMC']['xbmc_password'] = xbmcPwd
if firstLaunch:
defaultConfig['General']['metadata_xbmc'] = '1|1|1|1|1|1'
defaultConfig['General']['nzb_method'] = 'sabnzbd'
defaultConfig['General']['keep_processed_dir'] = '0'
defaultConfig['General']['use_banner'] = '1'
defaultConfig['General']['rename_episodes'] = '1'
defaultConfig['General']['naming_ep_name'] = '0'
defaultConfig['General']['naming_use_periods'] = '1'
defaultConfig['General']['naming_sep_type'] = '1'
defaultConfig['General']['naming_ep_type'] = '1'
defaultConfig['General']['root_dirs'] = '0|/storage/tvshows'
defaultConfig['SABnzbd']['sab_category'] = 'tv'
# workaround: on first launch, sick beard will always add
# 'http://' and trailing '/' on its own
defaultConfig['SABnzbd']['sab_host'] = sabNzbdHost
defaultConfig['XBMC']['xbmc_notify_ondownload'] = '1'
defaultConfig['XBMC']['xbmc_update_library'] = '1'
sickBeardConfig.merge(defaultConfig)
sickBeardConfig.write()
# launch SickBeard
# ----------------
logging.debug('Launching SickBeard...')
subprocess.call(sickBeard)
logging.debug('...done')
# write CouchPotato settings
# --------------------------
couchPotatoConfig = ConfigObj(pCouchPotatoSettings,create_empty=True)
defaultConfig = ConfigObj()
defaultConfig['global'] = {}
defaultConfig['global']['launchbrowser'] = 'False'
defaultConfig['global']['updater'] = 'False'
defaultConfig['global']['password'] = pwd
defaultConfig['global']['username'] = user
defaultConfig['global']['port'] = '8083'
defaultConfig['global']['host'] = host
defaultConfig['Sabnzbd'] = {}
defaultConfig['Sabnzbd']['username'] = user
defaultConfig['Sabnzbd']['password'] = pwd
defaultConfig['Sabnzbd']['apikey'] = sabNzbdApiKey
defaultConfig['Sabnzbd']['host'] = sabNzbdHost
defaultConfig['XBMC'] = {}
defaultConfig['XBMC']['enabled'] = 'True'
defaultConfig['XBMC']['host'] = '127.0.0.1:' + xbmcPort
defaultConfig['XBMC']['username'] = xbmcUser
defaultConfig['XBMC']['password'] = xbmcPwd
if firstLaunch:
defaultConfig['Sabnzbd']['category'] = 'movies'
defaultConfig['Sabnzbd']['ppdir'] = pSabNzbdCompleteMov
defaultConfig['Renamer'] = {}
defaultConfig['Renamer']['enabled'] = 'True'
defaultConfig['Renamer']['download'] = pSabNzbdCompleteMov
defaultConfig['Renamer']['destination'] = '/storage/videos'
defaultConfig['Renamer']['separator'] = '.'
defaultConfig['Renamer']['cleanup'] = 'True'
couchPotatoConfig.merge(defaultConfig)
couchPotatoConfig.write()
# launch CouchPotato
# ------------------
logging.debug('Launching CouchPotato...')
subprocess.call(couchPotato)
logging.debug('...done')
# write Headphones settings
# -------------------------
headphonesConfig = ConfigObj(pHeadphonesSettings,create_empty=True)
defaultConfig = ConfigObj()
defaultConfig['General'] = {}
defaultConfig['General']['launch_browser'] = '0'
defaultConfig['General']['http_port'] = '8084'
defaultConfig['General']['http_host'] = host
defaultConfig['General']['http_username'] = user
defaultConfig['General']['http_password'] = pwd
defaultConfig['SABnzbd'] = {}
defaultConfig['SABnzbd']['sab_apikey'] = sabNzbdApiKey
defaultConfig['SABnzbd']['sab_host'] = sabNzbdHost
defaultConfig['SABnzbd']['sab_username'] = user
defaultConfig['SABnzbd']['sab_password'] = pwd
if firstLaunch:
defaultConfig['SABnzbd']['sab_category'] = 'music'
defaultConfig['General']['music_dir'] = '/storage/music'
defaultConfig['General']['destination_dir'] = '/storage/music'
defaultConfig['General']['download_dir'] = '/storage/downloads/music'
defaultConfig['General']['move_files'] = '1'
defaultConfig['General']['rename_files'] = '1'
headphonesConfig.merge(defaultConfig)
headphonesConfig.write()
# launch Headphones
# -----------------
logging.debug('Launching Headphones...')
subprocess.call(headphones)
logging.debug('...done')

View File

@ -1,359 +0,0 @@
#!/bin/sh
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
. /etc/profile
# Addon settings
ADDON_DIR="$HOME/.xbmc/addons/service.downloadmanager.SABnzbd-Suite"
ADDON_HOME="$HOME/.xbmc/userdata/addon_data/service.downloadmanager.SABnzbd-Suite"
SABNZBDSUITE_SETTINGS="$ADDON_HOME/settings.xml"
SABNZBD_SETTINGS="$ADDON_HOME/sabnzbd.ini"
SICKBEARD_SETTINGS="$ADDON_HOME/config.ini"
COUCHPOTATO_SETTINGS="$ADDON_HOME/couchpotato.ini"
HEADPHONES_SETTINGS="$ADDON_HOME/headphones.ini"
XBMC_SETTINGS="$HOME/.xbmc/userdata/guisettings.xml"
export PYTHONPATH="$PYTHONPATH:$ADDON_DIR/pylib"
################################################################################
# default sabnzbd values
################################################################################
SABNZBD_HOST="127.0.0.1"
SABNZBD_PORT="8081"
SABNZBD_DISABLEAPIKEY="0"
SABNZBD_CHECKRELEASE="0"
SABNZBD_LAUNCHBROWSER="0"
SABNZBD_HTTPPORT="8081"
SABNZBD_HTTPSPORT="9081"
SABNZBD_HTTPSCERT="server.cert"
SABNZBD_HTTPSKEY="server.key"
SABNZBD_SKIN="Plush"
SABNZBD_SKIN2="Plush"
SABNZBD_WEBCOLOR="gold"
SABNZBD_WEBCOLOR2="gold"
SABNZBD_LOGDIR="logs"
SABNZBD_ADMINDIR="admin"
SABNZBD_BACKUPDIR="backup"
SABNZBD_SCRIPTDIR="scripts"
SABNZBD_INCOMPLETEDIR="/storage/downloads/incomplete"
SABNZBD_COMPLETEDIR="/storage/downloads"
SABNZBD_WATCHDIR="/storage/downloads/watch"
################################################################################
# default sickbeard values
################################################################################
SICKBEARD_LOGDIR="log"
SICKBEARD_CACHEDIR="cache"
SICKBEARD_PORT="8082"
SICKBEARD_LAUNCHBROWSER="0"
SICKBEARD_VERSIONCHECK="0"
SICKBEARD_USEIPV6="0"
SICKBEARD_WEBLOG="0"
SICKBEARD_USEXBMC="1"
SICKBEARD_METADATAXBMC="1|1|1|1|1|1"
################################################################################
# default couchpotato values
################################################################################
COUCHPOTATO_LAUNCHBROWSER="False"
COUCHPOTATO_VERSIONCHECK="False"
COUCHPOTATO_PORT="8083"
COUCHPOTATO_USEXBMC="True"
COUCHPOTATO_UPDATEXBMC="True"
################################################################################
# default headphones values
################################################################################
HEADPHONES_PORT="8084"
HEADPHONES_LAUNCHBROWSER="0"
HEADPHONES_MUSICDIR="/storage/music"
HEADPHONES_DESTDIR="/storage/music"
HEADPHONES_DOWNLOADDIR="/storage/music"
HEADPHONES_SABHOST="$SABNZBD_HOST:$SABNZBD_PORT"
HEADPHONES_SABCATEGORY="music"
################################################################################
# setup functions
################################################################################
write_sabnzbd_ini() {
python $ADDON_DIR/bin/ini_tool --action=write \
--file=$SABNZBD_SETTINGS \
--option="$1:$2" \
--value="$3"
}
write_sickbeard_ini() {
python $ADDON_DIR/bin/ini_tool --action=write \
--file=$SICKBEARD_SETTINGS \
--option="$1:$2" \
--value="$3"
}
write_couchpotato_ini() {
python $ADDON_DIR/bin/ini_tool --action=write \
--file=$COUCHPOTATO_SETTINGS \
--option="$1:$2" \
--value="$3"
}
write_headphones_ini() {
python $ADDON_DIR/bin/ini_tool --action=write \
--file=$HEADPHONES_SETTINGS \
--option="$1:$2" \
--value="$3"
}
read_sabconfig() {
python $ADDON_DIR/bin/ini_tool --action=read \
--file=$SABNZBD_SETTINGS \
--option="$1:$2"
}
read_xbmcconfig() {
grep "<$1>" $XBMC_SETTINGS | sed -e "s,[[:space:]]*<$1>,," -e "s,</$1>,,"
}
write_ini_postprocess() {
python $ADDON_DIR/bin/ini_tool --action=write \
--file=$ADDON_HOME/$SABNZBD_SCRIPTDIR/autoProcessTV.cfg \
--option="$1:$2" \
--value="$3"
}
################################################################################
# read xbmc settings
################################################################################
XBMC_HOST="127.0.0.1"
XBMC_PORT=`read_xbmcconfig webserverport`
XBMC_USER=`read_xbmcconfig webserverusername`
XBMC_PWD=`read_xbmcconfig webserverpassword`
################################################################################
# create default config
################################################################################
mkdir -p $ADDON_HOME
if [ ! -f "$SABNZBDSUITE_SETTINGS" ]; then
cp $ADDON_DIR/settings-default.xml $SABNZBDSUITE_SETTINGS
fi
################################################################################
# read settings from xbmc setup dialog
################################################################################
mkdir -p /var/config
cat "$ADDON_DIR/settings-default.xml" | awk -F\" '{print $2"=\""$4"\""}' | sed '/^=/d' > /var/config/sabnzbd.conf.default
cat "$SABNZBDSUITE_SETTINGS" | awk -F\" '{print $2"=\""$4"\""}' | sed '/^=/d' > /var/config/sabnzbd.conf
. /var/config/sabnzbd.conf.default
. /var/config/sabnzbd.conf
# TODO: add SABNZBD_HOST, SABNZBD_PORT etc to setup ui
SICKBEARD_IP="$SABNZBD_IP"
COUCHPOTATO_IP="$SABNZBD_IP"
HEADPHONES_IP="$SABNZBD_IP"
################################################################################
# setup sabnzbd ini file
################################################################################
if [ -z "$SABNZBD_IP" ]; then
SABNZBD_IP="0.0.0.0"
fi
if [ ! -f "$SABNZBD_SETTINGS" ]; then
SABNZBD_FIRSTRUN="yes"
fi
write_sabnzbd_ini misc disable_api_key $SABNZBD_DISABLEAPIKEY
write_sabnzbd_ini misc check_new_rel $SABNZBD_CHECKRELEASE
write_sabnzbd_ini misc auto_browser $SABNZBD_LAUNCHBROWSER
write_sabnzbd_ini misc username $SABNZBD_USER
write_sabnzbd_ini misc password $SABNZBD_PWD
write_sabnzbd_ini misc port $SABNZBD_HTTPPORT
write_sabnzbd_ini misc https_port $SABNZBD_HTTPSPORT
write_sabnzbd_ini misc https_cert $SABNZBD_HTTPSCERT
write_sabnzbd_ini misc https_key $SABNZBD_HTTPSKEY
write_sabnzbd_ini misc host $SABNZBD_IP
write_sabnzbd_ini misc web_dir $SABNZBD_SKIN
write_sabnzbd_ini misc web_dir2 $SABNZBD_SKIN2
write_sabnzbd_ini misc web_color $SABNZBD_WEBCOLOR
write_sabnzbd_ini misc web_color2 $SABNZBD_WEBCOLOR2
write_sabnzbd_ini misc log_dir $SABNZBD_LOGDIR
write_sabnzbd_ini misc admin_dir $SABNZBD_ADMINDIR
write_sabnzbd_ini misc nzb_backup_dir $SABNZBD_BACKUPDIR
write_sabnzbd_ini misc script_dir $SABNZBD_SCRIPTDIR
if [ "$SABNZBD_FIRSTRUN" = "yes" ]; then
mkdir -p "$SABNZBD_INCOMPLETEDIR"
mkdir -p "$SABNZBD_COMPLETEDIR"
mkdir -p "$SABNZBD_WATCHDIR"
write_sabnzbd_ini misc download_dir $SABNZBD_INCOMPLETEDIR
write_sabnzbd_ini misc complete_dir $SABNZBD_COMPLETEDIR
write_sabnzbd_ini misc dirscan_dir $SABNZBD_WATCHDIR
write_sabnzbd_ini servers:localhost name "localhost"
write_sabnzbd_ini servers:localhost host "localhost"
write_sabnzbd_ini servers:localhost port "119"
write_sabnzbd_ini servers:localhost enable "0"
fi
################################################################################
# setup postprocessing scripts file
################################################################################
mkdir -p $ADDON_HOME/$SABNZBD_SCRIPTDIR
cp -P $ADDON_DIR/SickBeard/autoProcessTV/*.py $ADDON_HOME/$SABNZBD_SCRIPTDIR
chmod +x $ADDON_HOME/$SABNZBD_SCRIPTDIR/*.py
write_ini_postprocess SickBeard host localhost
write_ini_postprocess SickBeard port $SICKBEARD_PORT
write_ini_postprocess SickBeard username $SABNZBD_USER
write_ini_postprocess SickBeard password $SABNZBD_PWD
################################################################################
# start sabnzbd
################################################################################
python $ADDON_DIR/SABnzbd/SABnzbd.py -d -f $SABNZBD_SETTINGS -l 0
################################################################################
# read sabnzbd settings
################################################################################
SABNZBD_APIKEY=`read_sabconfig misc api_key`
################################################################################
# setup sickbeard ini file
################################################################################
if [ -z "$SICKBEARD_IP" ]; then
SICKBEARD_IP="0.0.0.0"
fi
if [ ! -f "$SICKBEARD_SETTINGS" ]; then
SICKBEARD_FIRSTRUN="yes"
fi
write_sickbeard_ini General launch_browser $SICKBEARD_LAUNCHBROWSER
write_sickbeard_ini General version_notify $SICKBEARD_VERSIONCHECK
write_sickbeard_ini General log_dir $SICKBEARD_LOGDIR
write_sickbeard_ini General cache_dir $SICKBEARD_CACHEDIR
write_sickbeard_ini General web_port $SICKBEARD_PORT
write_sickbeard_ini General web_host $SICKBEARD_IP
write_sickbeard_ini General web_ipv6 $SICKBEARD_USEIPV6
write_sickbeard_ini General web_log $SICKBEARD_WEBLOG
write_sickbeard_ini General web_username $SABNZBD_USER
write_sickbeard_ini General web_password $SABNZBD_PWD
write_sickbeard_ini SABnzbd sab_username $SABNZBD_USER
write_sickbeard_ini SABnzbd sab_password $SABNZBD_PWD
write_sickbeard_ini SABnzbd sab_apikey $SABNZBD_APIKEY
write_sickbeard_ini SABnzbd sab_host "http://$SABNZBD_HOST:$SABNZBD_PORT/"
write_sickbeard_ini XBMC use_xbmc $SICKBEARD_USEXBMC
write_sickbeard_ini XBMC xbmc_host "$XBMC_HOST:$XBMC_PORT"
write_sickbeard_ini XBMC xbmc_username $XBMC_USER
write_sickbeard_ini XBMC xbmc_password $XBMC_PWD
if [ "$SICKBEARD_FIRSTRUN" = "yes" ]; then
write_sickbeard_ini General metadata_xbmc $SICKBEARD_METADATAXBMC
fi
################################################################################
# start sickbeard
################################################################################
python $ADDON_DIR/SickBeard/SickBeard.py --daemon --datadir $ADDON_HOME
################################################################################
# setup couchpotato ini file
################################################################################
if [ -z "$COUCHPOTATO_IP" ]; then
COUCHPOTATO_IP="0.0.0.0"
fi
if [ ! -f "$COUCHPOTATO_SETTINGS" ]; then
COUCHPOTATO_FIRSTRUN="yes"
fi
write_couchpotato_ini global host $COUCHPOTATO_IP
write_couchpotato_ini global port $COUCHPOTATO_PORT
write_couchpotato_ini global username $SABNZBD_USER
write_couchpotato_ini global password $SABNZBD_PWD
write_couchpotato_ini global launchbrowser $COUCHPOTATO_LAUNCHBROWSER
write_couchpotato_ini global updater $COUCHPOTATO_VERSIONCHECK
write_couchpotato_ini Sabnzbd username $SABNZBD_USER
write_couchpotato_ini Sabnzbd password $SABNZBD_PWD
write_couchpotato_ini Sabnzbd apikey $SABNZBD_APIKEY
write_couchpotato_ini Sabnzbd host "$SABNZBD_HOST:$SABNZBD_PORT"
write_couchpotato_ini XBMC enabled $COUCHPOTATO_USEXBMC
write_couchpotato_ini XBMC host "$XBMC_HOST:$XBMC_PORT"
write_couchpotato_ini XBMC username $XBMC_USER
write_couchpotato_ini XBMC password $XBMC_PWD
if [ "$COUCHPOTATO_FIRSTRUN" = "yes" ]; then
write_couchpotato_ini XBMC updateoneonly $COUCHPOTATO_UPDATEXBMC
fi
################################################################################
# start couchpotato
################################################################################
python $ADDON_DIR/CouchPotato/CouchPotato.py -d --datadir $ADDON_HOME --config $COUCHPOTATO_SETTINGS
################################################################################
# setup headphones ini file
################################################################################
if [ -z "$HEADPHONES_IP" ]; then
HEADPHONES_IP="0.0.0.0"
fi
if [ ! -f "$HEADPHONES_SETTINGS" ]; then
HEADPHONES_FIRSTRUN="yes"
fi
if [ "$HEADPHONES_FIRSTRUN" = "yes" ]; then
write_headphones_ini General http_port $HEADPHONES_PORT
write_headphones_ini General http_host $HEADPHONES_IP
write_headphones_ini General launch_browser $HEADPHONES_LAUNCHBROWSER
write_headphones_ini General music_dir $HEADPHONES_MUSICDIR
write_headphones_ini General destination_dir $HEADPHONES_DESTDIR
write_headphones_ini General download_dir $HEADPHONES_DOWNLOADDIR
write_headphones_ini SABnzbd sab_host $HEADPHONES_SABHOST
write_headphones_ini SABnzbd sab_apikey $SABNZBD_APIKEY
write_headphones_ini SABnzbd sab_category $HEADPHONES_SABCATEGORY
fi
################################################################################
# start headphones
################################################################################
python $ADDON_DIR/Headphones/Headphones.py -d --datadir $ADDON_HOME --config $HEADPHONES_SETTINGS

View File

@ -1,117 +0,0 @@
#!/usr/bin/env python
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2011 Travis Glenn Hansen (travisghansen@openelec.tv)
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
from configobj import ConfigObj
import sys
import os
import string
python_major = sys.version_info[0]
python_minor = sys.version_info[1]
prog="ini_tool"
description="""Read/Write config files.
Examples:
%(prog)s --file config.ini --action read --option [section:]username
%(prog)s --file config.ini --action write --option [section:]username --value foo""" % {'prog':prog}
def option_required_error(option):
parser.print_usage()
print prog + ": error: " + option + " is required"
exit(2)
if python_major > 2 or (python_major == 2 and python_minor >= 7):
import argparse
parser = argparse.ArgumentParser(
prog=prog,
description=description,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--file', help='file to read/write to/from', required=True)
parser.add_argument('--action', help='read|write', required=True)
parser.add_argument('--option', help='the option key', required=True)
parser.add_argument('--value', help='value to store in the given option (only for write action)')
options = parser.parse_args()
else:
import optparse
parser = optparse.OptionParser(
prog=prog,
description=description,
)
parser.add_option('--file', help='file to read/write to/from')
parser.add_option('--action', help='read|write')
parser.add_option('--option', help='the option key')
parser.add_option('--value', help='value to store in the given option (only for write action)')
(options, args) = parser.parse_args()
if not options.file:
option_required_error("--file")
if not options.action:
option_required_error("--action")
if not options.option:
option_required_error("--option")
if options.action != "read" and options.action != "write":
print "'" + options.action + "' is not a valid action"
parser.print_help()
exit(2)
if options.action == "read" and not os.path.isfile(options.file):
print "'" + options.file + "' is not a file"
exit(2)
config = ConfigObj(options.file)
keys = string.split(options.option, ":")
key_len = len(keys)
current_section = config
if options.action == 'read':
i = 1
for key in keys:
if i == key_len:
print current_section[key]
exit(0)
else:
current_section = current_section[key]
i += 1
elif options.action == 'write':
i = 1
for key in keys:
if i == key_len:
current_section[key] = options.value
elif key not in current_section:
current_section[key] = {}
current_section = current_section[key]
i += 1
config.write()
else:
exit(1)

View File

@ -24,15 +24,66 @@ import xbmcaddon
import time
import subprocess
import xbmc
import urllib2
import socket
from configobj import ConfigObj
__scriptname__ = "SABnzbd Suite"
__author__ = "OpenELEC"
__url__ = "http://www.openelec.tv"
__author__ = "OpenELEC"
__url__ = "http://www.openelec.tv"
__settings__ = xbmcaddon.Addon(id='service.downloadmanager.SABnzbd-Suite')
__cwd__ = __settings__.getAddonInfo('path')
__path__ = xbmc.translatePath( os.path.join( __cwd__, 'bin', "SABnzbd-Suite.service") )
__path__ = xbmc.translatePath( os.path.join( __cwd__, 'bin', "SABnzbd-Suite.py") )
#make binary files executable in adson bin folder
subprocess.Popen("chmod -R +x " + __cwd__ + "/bin/*" , shell=True, close_fds=True)
checkInterval = 120
timeout = 20
subprocess.Popen(__path__, shell=True, close_fds=True)
# Launch Suite
subprocess.call(['python',__path__])
# SABnzbd addresses and api key
sabNzbdAddress = '127.0.0.1:8081'
sabNzbdConfigFile = '/storage/.xbmc/userdata/addon_data/service.downloadmanager.SABnzbd-Suite/sabnzbd.ini'
sabConfiguration = ConfigObj(sabNzbdConfigFile)
sabNzbdApiKey = sabConfiguration['misc']['api_key']
sabNzbdUser = sabConfiguration['misc']['username']
sabNzbdPass = sabConfiguration['misc']['password']
sabNzbdQueue = 'http://' + sabNzbdAddress + '/sabnzbd/api?mode=queue&output=xml&apikey=' + sabNzbdApiKey + '&ma_username=' + sabNzbdUser + '&ma_password=' + sabNzbdUser
# start checking SABnzbd for activity and prevent sleeping if necessary
socket.setdefaulttimeout(timeout)
shouldKeepAwake = __settings__.getSetting('SABNZBD_KEEP_AWAKE')
if shouldKeepAwake:
xbmc.log('SABnzbd-Suite: will prevent idle sleep/shutdown while downloading')
while (not xbmc.abortRequested):
# reread setting in case it has changed
shouldKeepAwake = __settings__.getSetting('SABNZBD_KEEP_AWAKE')
# check if SABnzbd is downloading
sabIsActive = False
req = urllib2.Request(sabNzbdQueue)
try: handle = urllib2.urlopen(req)
except IOError, e:
xbmc.log('SABnzbd-Suite: could not determine SABnzbds status', level=xbmc.LOGERROR)
else:
queue = handle.read()
handle.close()
sabIsActive = (queue.find('<status>Downloading</status>') >= 0)
# reset idle timer when we're close to idle sleep/shutdown
if (shouldKeepAwake and sabIsActive):
response = xbmc.executehttpapi("GetGUISetting(0;powermanagement.shutdowntime)").replace('<li>','')
shutdownTime = int(response) * 60
idleTime = xbmc.getGlobalIdleTime()
timeToShutdown = shutdownTime - idleTime
if (sabIsActive and timeToShutdown <= checkInterval - timeout):
xbmc.log('SABnzbd-Suite: still downloading. Resetting XBMC idle timer.')
xbmc.executehttpapi("SendKey(0xF000)")
xbmc.sleep(checkInterval * 1000)

View File

@ -8,5 +8,7 @@
<string id="1023">Password</string>
<string id="2010">Network Settings</string>
<string id="2021">Allowed IP addresses</string>
<string id="3010">Sleep</string>
<string id="3021">Keep awake while downloading</string>
</strings>

View File

@ -8,5 +8,7 @@
<string id="1023">Passwort</string>
<string id="2010">Netzwerk Einstellungen</string>
<string id="2021">Erlaubte IP Adressen</string>
<string id="3010">Ruhezustand</string>
<string id="3021">Verhindere Ruhezustand wenn aktiv</string>
</strings>

View File

@ -11,5 +11,9 @@
<setting label="2010" type="lsep"/>
<setting type="sep" />
<setting id="SABNZBD_IP" type="text" label="2021" default="0.0.0.0"/>
<setting label="3010" type="lsep"/>
<setting type="sep" />
<setting id="SABNZBD_KEEP_AWAKE" type="bool" label="3021" default="false"/>
</category>
</settings>