mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 13:53:15 -07:00
Update autoProcessTV.py
This commit is contained in:
parent
67dfcc5b13
commit
3ea619634e
1 changed files with 105 additions and 109 deletions
214
autoProcessTV.py
214
autoProcessTV.py
|
@ -1,109 +1,105 @@
|
||||||
# Author: Nic Wolfe <nic@wolfeden.ca>
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
||||||
# URL: http://code.google.com/p/sickbeard/
|
# URL: http://code.google.com/p/sickbeard/
|
||||||
#
|
#
|
||||||
# This file is part of Sick Beard.
|
# This file is part of Sick Beard.
|
||||||
#
|
#
|
||||||
# Sick Beard is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# Sick Beard is distributed in the hope that it will be useful,
|
# Sick Beard is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
import os.path
|
import os.path
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
class AuthURLOpener(urllib.FancyURLopener):
|
class AuthURLOpener(urllib.FancyURLopener):
|
||||||
def __init__(self, user, pw):
|
def __init__(self, user, pw):
|
||||||
self.username = user
|
self.username = user
|
||||||
self.password = pw
|
self.password = pw
|
||||||
self.numTries = 0
|
self.numTries = 0
|
||||||
urllib.FancyURLopener.__init__(self)
|
urllib.FancyURLopener.__init__(self)
|
||||||
|
|
||||||
def prompt_user_passwd(self, host, realm):
|
def prompt_user_passwd(self, host, realm):
|
||||||
if self.numTries == 0:
|
if self.numTries == 0:
|
||||||
self.numTries = 1
|
self.numTries = 1
|
||||||
return (self.username, self.password)
|
return (self.username, self.password)
|
||||||
else:
|
else:
|
||||||
return ('', '')
|
return ('', '')
|
||||||
|
|
||||||
def openit(self, url):
|
def openit(self, url):
|
||||||
self.numTries = 0
|
self.numTries = 0
|
||||||
return urllib.FancyURLopener.open(self, url)
|
return urllib.FancyURLopener.open(self, url)
|
||||||
|
|
||||||
|
|
||||||
def processEpisode(dirName, nzbName=None, status=0):
|
def processEpisode(dirName, nzbName=None, failed=False):
|
||||||
|
config = ConfigParser.ConfigParser()
|
||||||
status = int(status)
|
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
|
||||||
if status > 0:
|
print "Loading config from", configFilename
|
||||||
print "the download failed. nothing to process"
|
|
||||||
sys.exit()
|
if not os.path.isfile(configFilename):
|
||||||
|
print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?"
|
||||||
config = ConfigParser.ConfigParser()
|
sys.exit(-1)
|
||||||
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
|
|
||||||
print "Loading config from", configFilename
|
try:
|
||||||
|
fp = open(configFilename, "r")
|
||||||
if not os.path.isfile(configFilename):
|
config.readfp(fp)
|
||||||
print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?"
|
fp.close()
|
||||||
sys.exit(-1)
|
except IOError, e:
|
||||||
|
print "Could not read configuration file: ", str(e)
|
||||||
try:
|
sys.exit(1)
|
||||||
fp = open(configFilename, "r")
|
|
||||||
config.readfp(fp)
|
host = config.get("SickBeard", "host")
|
||||||
fp.close()
|
port = config.get("SickBeard", "port")
|
||||||
except IOError, e:
|
username = config.get("SickBeard", "username")
|
||||||
print "Could not read configuration file: ", str(e)
|
password = config.get("SickBeard", "password")
|
||||||
sys.exit(1)
|
try:
|
||||||
|
ssl = int(config.get("SickBeard", "ssl"))
|
||||||
host = config.get("SickBeard", "host")
|
except (ConfigParser.NoOptionError, ValueError):
|
||||||
port = config.get("SickBeard", "port")
|
ssl = 0
|
||||||
username = config.get("SickBeard", "username")
|
|
||||||
password = config.get("SickBeard", "password")
|
try:
|
||||||
try:
|
web_root = config.get("SickBeard", "web_root")
|
||||||
ssl = int(config.get("SickBeard", "ssl"))
|
except ConfigParser.NoOptionError:
|
||||||
except (ConfigParser.NoOptionError, ValueError):
|
web_root = ""
|
||||||
ssl = 0
|
|
||||||
|
params = {}
|
||||||
try:
|
|
||||||
web_root = config.get("SickBeard", "web_root")
|
params['quiet'] = 1
|
||||||
except ConfigParser.NoOptionError:
|
|
||||||
web_root = ""
|
params['dirName'] = dirName
|
||||||
|
if nzbName != None:
|
||||||
params = {}
|
params['nzbName'] = nzbName
|
||||||
|
|
||||||
params['quiet'] = 1
|
params['failed'] = failed
|
||||||
|
|
||||||
params['dir'] = dirName
|
myOpener = AuthURLOpener(username, password)
|
||||||
if nzbName != None:
|
|
||||||
params['nzbName'] = nzbName
|
if ssl:
|
||||||
|
protocol = "https://"
|
||||||
myOpener = AuthURLOpener(username, password)
|
else:
|
||||||
|
protocol = "http://"
|
||||||
if ssl:
|
|
||||||
protocol = "https://"
|
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params)
|
||||||
else:
|
|
||||||
protocol = "http://"
|
print "Opening URL:", url
|
||||||
|
|
||||||
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params)
|
try:
|
||||||
|
urlObj = myOpener.openit(url)
|
||||||
print "Opening URL:", url
|
except IOError, e:
|
||||||
|
print "Unable to open URL: ", str(e)
|
||||||
try:
|
sys.exit(1)
|
||||||
urlObj = myOpener.openit(url)
|
|
||||||
except IOError, e:
|
result = urlObj.readlines()
|
||||||
print "Unable to open URL: ", str(e)
|
for line in result:
|
||||||
sys.exit(1)
|
print line
|
||||||
|
|
||||||
result = urlObj.readlines()
|
|
||||||
for line in result:
|
|
||||||
print line
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue