Skip to content

Commit

Permalink
Merge branch 'master' of github.com:midgetspy/Sick-Beard into windows…
Browse files Browse the repository at this point in the history
…_binaries
  • Loading branch information
midgetspy committed Apr 15, 2014
2 parents caacadf + a211e87 commit 1914550
Show file tree
Hide file tree
Showing 64 changed files with 2,277 additions and 1,804 deletions.
21 changes: 19 additions & 2 deletions autoProcessTV/autoProcessTV.cfg.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# Sick Beard autoProcessTV configuration file
# Used in combination with scripts like sabToSickBeard that call autoProcessTV
#
# Rename (or copy) autoProcessTV.cfg.sample to autoProcessTV.cfg
# Change the host, port, username, and password values
# to the appropriate settings for your Sick Beard server.
#
# Example: Sick Beard can be accessed on http://localhost:8081
# without username/password
#
# host=localhost # Sick Beard host (localhost or IP address)
# port=8081 # Sick Beard port
# username= # Credentials for logging into Sick Beard
# password= # Credentials for logging into Sick Beard (don't use special characters)
# web_root= # Sick Beard web_root
# ssl=0 # http (ssl=0) (for https use ssl=1)

[SickBeard]
host=localhost
port=8081
username=
password=
web_root=
ssl=0
web_root=/
ssl=0
256 changes: 152 additions & 104 deletions autoProcessTV/autoProcessTV.py
Original file line number Diff line number Diff line change
@@ -1,104 +1,152 @@
# Author: Nic Wolfe <[email protected]>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of Sick Beard.
#
# Sick Beard 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 3 of the License, or
# (at your option) any later version.
#
# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>.


import sys
import urllib
import os.path
import ConfigParser

class AuthURLOpener(urllib.FancyURLopener):
def __init__(self, user, pw):
self.username = user
self.password = pw
self.numTries = 0
urllib.FancyURLopener.__init__(self)

def prompt_user_passwd(self, host, realm):
if self.numTries == 0:
self.numTries = 1
return (self.username, self.password)
else:
return ('', '')

def openit(self, url):
self.numTries = 0
return urllib.FancyURLopener.open(self, url)


def processEpisode(dirName, nzbName=None):

config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
print "Loading config from", configFilename

if not os.path.isfile(configFilename):
print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?"
sys.exit(-1)

try:
fp = open(configFilename, "r")
config.readfp(fp)
fp.close()
except IOError, e:
print "Could not read configuration file: ", str(e)
sys.exit(1)

host = config.get("SickBeard", "host")
port = config.get("SickBeard", "port")
username = config.get("SickBeard", "username")
password = config.get("SickBeard", "password")
try:
ssl = int(config.get("SickBeard", "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = 0

try:
web_root = config.get("SickBeard", "web_root")
except ConfigParser.NoOptionError:
web_root = ""

params = {}

params['quiet'] = 1

params['dir'] = dirName
if nzbName != None:
params['nzbName'] = nzbName

myOpener = AuthURLOpener(username, password)

if ssl:
protocol = "https://"
else:
protocol = "http://"

url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params)

print "Opening URL:", url

try:
urlObj = myOpener.openit(url)
except IOError, e:
print "Unable to open URL: ", str(e)
sys.exit(1)

result = urlObj.readlines()
for line in result:
print line

#!/usr/bin/env python

# Author: Nic Wolfe <[email protected]>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of Sick Beard.
#
# Sick Beard 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 3 of the License, or
# (at your option) any later version.
#
# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import with_statement

import os.path
import sys

# Try importing Python 2 modules using new names
try:
import ConfigParser as configparser
import urllib2
from urllib import urlencode

# On error import Python 3 modules
except ImportError:
import configparser
import urllib.request as urllib2
from urllib.parse import urlencode

# workaround for broken urllib2 in python 2.6.5: wrong credentials lead to an infinite recursion
if sys.version_info >= (2, 6, 5) and sys.version_info < (2, 6, 6):
class HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
def retry_http_basic_auth(self, host, req, realm):
# don't retry if auth failed
if req.get_header(self.auth_header, None) is not None:
return None

return urllib2.HTTPBasicAuthHandler.retry_http_basic_auth(self, host, req, realm)

else:
HTTPBasicAuthHandler = urllib2.HTTPBasicAuthHandler


def processEpisode(dir_to_process, org_NZB_name=None):

# Default values
host = "localhost"
port = "8081"
username = ""
password = ""
ssl = 0
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
config = configparser.RawConfigParser()
config_filename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")

if not os.path.isfile(config_filename):
print ("ERROR: " + config_filename + " doesn\'t exist")
print ("copy /rename " + config_filename + ".sample and edit\n")
print ("Trying default url: " + default_url + "\n")

else:
try:
print ("Loading config from " + config_filename + "\n")

with open(config_filename, "r") as fp:
config.readfp(fp)

# Replace default values with config_file values
host = config.get("SickBeard", "host")
port = config.get("SickBeard", "port")
username = config.get("SickBeard", "username")
password = config.get("SickBeard", "password")

try:
ssl = int(config.get("SickBeard", "ssl"))

except (configparser.NoOptionError, ValueError):
pass

try:
web_root = config.get("SickBeard", "web_root")
if not web_root.startswith("/"):
web_root = "/" + web_root

if not web_root.endswith("/"):
web_root = web_root + "/"

except configparser.NoOptionError:
pass

except EnvironmentError:
e = sys.exc_info()[1]
print ("Could not read configuration file: " + str(e))
# There was a config_file, don't use default values but exit
sys.exit(1)

params = {}

params['quiet'] = 1

params['dir'] = dir_to_process
if org_NZB_name != None:
params['nzbName'] = org_NZB_name

if ssl:
protocol = "https://"
else:
protocol = "http://"

url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode?" + urlencode(params)

print ("Opening URL: " + url)

try:
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, url, username, password)
handler = HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)

result = opener.open(url).readlines()

for line in result:
if line:
print (line.strip())

except IOError:
e = sys.exc_info()[1]
print ("Unable to open URL: " + str(e))
sys.exit(1)


if __name__ == "__main__":
print ("This module is supposed to be used as import in other scripts and not run standalone.")
print ("Use sabToSickBeard instead.")
sys.exit(1)
10 changes: 7 additions & 3 deletions autoProcessTV/hellaToSickBeard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@

import sys

import autoProcessTV
try:
import autoProcessTV
except:
print ("Can't import autoProcessTV.py, make sure it's in the same folder as " + sys.argv[0])
sys.exit(1)

if len(sys.argv) < 4:
print "No folder supplied - is this being called from HellaVCR?"
sys.exit()
print ("No folder supplied - is this being called from HellaVCR?")
sys.exit(1)
else:
autoProcessTV.processEpisode(sys.argv[3], sys.argv[2])
43 changes: 36 additions & 7 deletions autoProcessTV/sabToSickBeard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,47 @@
# 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>.


import sys
import autoProcessTV

try:
import autoProcessTV
except:
print ("Can't import autoProcessTV.py, make sure it's in the same folder as " + sys.argv[0])
sys.exit(1)

# SABnzbd user script parameters - see: http://wiki.sabnzbd.org/user-scripts

# 0 sys.argv[0] is the name of this script

# 1 The final directory of the job (full path)
if len(sys.argv) < 2:
print "No folder supplied - is this being called from SABnzbd?"
sys.exit()
elif len(sys.argv) >= 3:
autoProcessTV.processEpisode(sys.argv[1], sys.argv[2])
print ("No folder supplied - is this being called from SABnzbd?")
sys.exit(1)
else:
autoProcessTV.processEpisode(sys.argv[1])
download_final_dir = sys.argv[1]

# 2 The original name of the NZB file
org_NZB_name = sys.argv[2] if len(sys.argv) > 3 else None

# 3 Clean version of the job name (no path info and ".nzb" removed)
clean_NZB_file = sys.argv[3] if len(sys.argv) > 4 else None

# 4 Indexer's report number (if supported)
indexer_report = sys.argv[4] if len(sys.argv) > 5 else None

# 5 User-defined category
sab_user_category = sys.argv[5] if len(sys.argv) > 6 else None

# 6 Group that the NZB was posted in e.g. alt.binaries.x
group_NZB = sys.argv[6] if len(sys.argv) > 7 else None

# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
sab_post_processing_status = sys.argv[7] if len(sys.argv) > 8 else None

# Only final_dir and org_NZB_name are being used to process episodes
autoProcessTV.processEpisode(download_final_dir, org_NZB_name)
Loading

0 comments on commit 1914550

Please sign in to comment.