Skip to content

Commit 1914550

Browse files
committed
Merge branch 'master' of github.com:midgetspy/Sick-Beard into windows_binaries
2 parents caacadf + a211e87 commit 1914550

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2277
-1804
lines changed
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
# Sick Beard autoProcessTV configuration file
2+
# Used in combination with scripts like sabToSickBeard that call autoProcessTV
3+
#
4+
# Rename (or copy) autoProcessTV.cfg.sample to autoProcessTV.cfg
5+
# Change the host, port, username, and password values
6+
# to the appropriate settings for your Sick Beard server.
7+
#
8+
# Example: Sick Beard can be accessed on http://localhost:8081
9+
# without username/password
10+
#
11+
# host=localhost # Sick Beard host (localhost or IP address)
12+
# port=8081 # Sick Beard port
13+
# username= # Credentials for logging into Sick Beard
14+
# password= # Credentials for logging into Sick Beard (don't use special characters)
15+
# web_root= # Sick Beard web_root
16+
# ssl=0 # http (ssl=0) (for https use ssl=1)
17+
118
[SickBeard]
219
host=localhost
320
port=8081
421
username=
522
password=
6-
web_root=
7-
ssl=0
23+
web_root=/
24+
ssl=0

autoProcessTV/autoProcessTV.py

Lines changed: 152 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,152 @@
1-
# Author: Nic Wolfe <nic@wolfeden.ca>
2-
# URL: http://code.google.com/p/sickbeard/
3-
#
4-
# This file is part of Sick Beard.
5-
#
6-
# Sick Beard is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU General Public License as published by
8-
# the Free Software Foundation, either version 3 of the License, or
9-
# (at your option) any later version.
10-
#
11-
# Sick Beard is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
18-
19-
20-
import sys
21-
import urllib
22-
import os.path
23-
import ConfigParser
24-
25-
class AuthURLOpener(urllib.FancyURLopener):
26-
def __init__(self, user, pw):
27-
self.username = user
28-
self.password = pw
29-
self.numTries = 0
30-
urllib.FancyURLopener.__init__(self)
31-
32-
def prompt_user_passwd(self, host, realm):
33-
if self.numTries == 0:
34-
self.numTries = 1
35-
return (self.username, self.password)
36-
else:
37-
return ('', '')
38-
39-
def openit(self, url):
40-
self.numTries = 0
41-
return urllib.FancyURLopener.open(self, url)
42-
43-
44-
def processEpisode(dirName, nzbName=None):
45-
46-
config = ConfigParser.ConfigParser()
47-
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
48-
print "Loading config from", configFilename
49-
50-
if not os.path.isfile(configFilename):
51-
print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?"
52-
sys.exit(-1)
53-
54-
try:
55-
fp = open(configFilename, "r")
56-
config.readfp(fp)
57-
fp.close()
58-
except IOError, e:
59-
print "Could not read configuration file: ", str(e)
60-
sys.exit(1)
61-
62-
host = config.get("SickBeard", "host")
63-
port = config.get("SickBeard", "port")
64-
username = config.get("SickBeard", "username")
65-
password = config.get("SickBeard", "password")
66-
try:
67-
ssl = int(config.get("SickBeard", "ssl"))
68-
except (ConfigParser.NoOptionError, ValueError):
69-
ssl = 0
70-
71-
try:
72-
web_root = config.get("SickBeard", "web_root")
73-
except ConfigParser.NoOptionError:
74-
web_root = ""
75-
76-
params = {}
77-
78-
params['quiet'] = 1
79-
80-
params['dir'] = dirName
81-
if nzbName != None:
82-
params['nzbName'] = nzbName
83-
84-
myOpener = AuthURLOpener(username, password)
85-
86-
if ssl:
87-
protocol = "https://"
88-
else:
89-
protocol = "http://"
90-
91-
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params)
92-
93-
print "Opening URL:", url
94-
95-
try:
96-
urlObj = myOpener.openit(url)
97-
except IOError, e:
98-
print "Unable to open URL: ", str(e)
99-
sys.exit(1)
100-
101-
result = urlObj.readlines()
102-
for line in result:
103-
print line
104-
1+
#!/usr/bin/env python
2+
3+
# Author: Nic Wolfe <nic@wolfeden.ca>
4+
# URL: http://code.google.com/p/sickbeard/
5+
#
6+
# This file is part of Sick Beard.
7+
#
8+
# Sick Beard is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# Sick Beard is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
20+
21+
from __future__ import with_statement
22+
23+
import os.path
24+
import sys
25+
26+
# Try importing Python 2 modules using new names
27+
try:
28+
import ConfigParser as configparser
29+
import urllib2
30+
from urllib import urlencode
31+
32+
# On error import Python 3 modules
33+
except ImportError:
34+
import configparser
35+
import urllib.request as urllib2
36+
from urllib.parse import urlencode
37+
38+
# workaround for broken urllib2 in python 2.6.5: wrong credentials lead to an infinite recursion
39+
if sys.version_info >= (2, 6, 5) and sys.version_info < (2, 6, 6):
40+
class HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
41+
def retry_http_basic_auth(self, host, req, realm):
42+
# don't retry if auth failed
43+
if req.get_header(self.auth_header, None) is not None:
44+
return None
45+
46+
return urllib2.HTTPBasicAuthHandler.retry_http_basic_auth(self, host, req, realm)
47+
48+
else:
49+
HTTPBasicAuthHandler = urllib2.HTTPBasicAuthHandler
50+
51+
52+
def processEpisode(dir_to_process, org_NZB_name=None):
53+
54+
# Default values
55+
host = "localhost"
56+
port = "8081"
57+
username = ""
58+
password = ""
59+
ssl = 0
60+
web_root = "/"
61+
62+
default_url = host + ":" + port + web_root
63+
if ssl:
64+
default_url = "https://" + default_url
65+
else:
66+
default_url = "http://" + default_url
67+
68+
# Get values from config_file
69+
config = configparser.RawConfigParser()
70+
config_filename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
71+
72+
if not os.path.isfile(config_filename):
73+
print ("ERROR: " + config_filename + " doesn\'t exist")
74+
print ("copy /rename " + config_filename + ".sample and edit\n")
75+
print ("Trying default url: " + default_url + "\n")
76+
77+
else:
78+
try:
79+
print ("Loading config from " + config_filename + "\n")
80+
81+
with open(config_filename, "r") as fp:
82+
config.readfp(fp)
83+
84+
# Replace default values with config_file values
85+
host = config.get("SickBeard", "host")
86+
port = config.get("SickBeard", "port")
87+
username = config.get("SickBeard", "username")
88+
password = config.get("SickBeard", "password")
89+
90+
try:
91+
ssl = int(config.get("SickBeard", "ssl"))
92+
93+
except (configparser.NoOptionError, ValueError):
94+
pass
95+
96+
try:
97+
web_root = config.get("SickBeard", "web_root")
98+
if not web_root.startswith("/"):
99+
web_root = "/" + web_root
100+
101+
if not web_root.endswith("/"):
102+
web_root = web_root + "/"
103+
104+
except configparser.NoOptionError:
105+
pass
106+
107+
except EnvironmentError:
108+
e = sys.exc_info()[1]
109+
print ("Could not read configuration file: " + str(e))
110+
# There was a config_file, don't use default values but exit
111+
sys.exit(1)
112+
113+
params = {}
114+
115+
params['quiet'] = 1
116+
117+
params['dir'] = dir_to_process
118+
if org_NZB_name != None:
119+
params['nzbName'] = org_NZB_name
120+
121+
if ssl:
122+
protocol = "https://"
123+
else:
124+
protocol = "http://"
125+
126+
url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode?" + urlencode(params)
127+
128+
print ("Opening URL: " + url)
129+
130+
try:
131+
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
132+
password_mgr.add_password(None, url, username, password)
133+
handler = HTTPBasicAuthHandler(password_mgr)
134+
opener = urllib2.build_opener(handler)
135+
urllib2.install_opener(opener)
136+
137+
result = opener.open(url).readlines()
138+
139+
for line in result:
140+
if line:
141+
print (line.strip())
142+
143+
except IOError:
144+
e = sys.exc_info()[1]
145+
print ("Unable to open URL: " + str(e))
146+
sys.exit(1)
147+
148+
149+
if __name__ == "__main__":
150+
print ("This module is supposed to be used as import in other scripts and not run standalone.")
151+
print ("Use sabToSickBeard instead.")
152+
sys.exit(1)

autoProcessTV/hellaToSickBeard.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121

2222
import sys
2323

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

2630
if len(sys.argv) < 4:
27-
print "No folder supplied - is this being called from HellaVCR?"
28-
sys.exit()
31+
print ("No folder supplied - is this being called from HellaVCR?")
32+
sys.exit(1)
2933
else:
3034
autoProcessTV.processEpisode(sys.argv[3], sys.argv[2])

autoProcessTV/sabToSickBeard.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,47 @@
1414
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
# GNU General Public License for more details.
17-
#
17+
#
1818
# You should have received a copy of the GNU General Public License
1919
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
2020

2121

2222
import sys
23-
import autoProcessTV
2423

24+
try:
25+
import autoProcessTV
26+
except:
27+
print ("Can't import autoProcessTV.py, make sure it's in the same folder as " + sys.argv[0])
28+
sys.exit(1)
29+
30+
# SABnzbd user script parameters - see: http://wiki.sabnzbd.org/user-scripts
31+
32+
# 0 sys.argv[0] is the name of this script
33+
34+
# 1 The final directory of the job (full path)
2535
if len(sys.argv) < 2:
26-
print "No folder supplied - is this being called from SABnzbd?"
27-
sys.exit()
28-
elif len(sys.argv) >= 3:
29-
autoProcessTV.processEpisode(sys.argv[1], sys.argv[2])
36+
print ("No folder supplied - is this being called from SABnzbd?")
37+
sys.exit(1)
3038
else:
31-
autoProcessTV.processEpisode(sys.argv[1])
39+
download_final_dir = sys.argv[1]
40+
41+
# 2 The original name of the NZB file
42+
org_NZB_name = sys.argv[2] if len(sys.argv) > 3 else None
43+
44+
# 3 Clean version of the job name (no path info and ".nzb" removed)
45+
clean_NZB_file = sys.argv[3] if len(sys.argv) > 4 else None
46+
47+
# 4 Indexer's report number (if supported)
48+
indexer_report = sys.argv[4] if len(sys.argv) > 5 else None
49+
50+
# 5 User-defined category
51+
sab_user_category = sys.argv[5] if len(sys.argv) > 6 else None
52+
53+
# 6 Group that the NZB was posted in e.g. alt.binaries.x
54+
group_NZB = sys.argv[6] if len(sys.argv) > 7 else None
55+
56+
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
57+
sab_post_processing_status = sys.argv[7] if len(sys.argv) > 8 else None
58+
59+
# Only final_dir and org_NZB_name are being used to process episodes
60+
autoProcessTV.processEpisode(download_final_dir, org_NZB_name)

0 commit comments

Comments
 (0)