mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-07 02:23:38 +00:00
Minor bugfixes and improvements
This commit is contained in:
parent
23348e0bd0
commit
fb222902c1
5 changed files with 124 additions and 78 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# 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/
|
||||||
#
|
#
|
||||||
|
@ -12,95 +14,138 @@
|
||||||
# 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/>.
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
|
||||||
import urllib
|
|
||||||
import os.path
|
import os.path
|
||||||
import ConfigParser
|
import sys
|
||||||
|
|
||||||
class AuthURLOpener(urllib.FancyURLopener):
|
# Try importing Python 2 modules using new names
|
||||||
def __init__(self, user, pw):
|
try:
|
||||||
self.username = user
|
import ConfigParser as configparser
|
||||||
self.password = pw
|
import urllib2
|
||||||
self.numTries = 0
|
from urllib import urlencode
|
||||||
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):
|
# On error import Python 3 modules
|
||||||
self.numTries = 0
|
except ImportError:
|
||||||
return urllib.FancyURLopener.open(self, url)
|
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(dirName, nzbName=None, failed=False):
|
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)
|
||||||
|
|
||||||
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 = {}
|
||||||
|
|
||||||
params['quiet'] = 1
|
params['quiet'] = 1
|
||||||
|
|
||||||
params['dir'] = dirName
|
params['dir'] = dir_to_process
|
||||||
if nzbName != None:
|
if org_NZB_name != None:
|
||||||
params['nzbName'] = nzbName
|
params['nzbName'] = org_NZB_name
|
||||||
|
|
||||||
params['failed'] = int(failed)
|
|
||||||
|
|
||||||
myOpener = AuthURLOpener(username, password)
|
|
||||||
|
|
||||||
if ssl:
|
if ssl:
|
||||||
protocol = "https://"
|
protocol = "https://"
|
||||||
else:
|
else:
|
||||||
protocol = "http://"
|
protocol = "http://"
|
||||||
|
|
||||||
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params)
|
url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode?" + urlencode(params)
|
||||||
|
|
||||||
print "Opening URL:", url
|
print ("Opening URL: " + url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
||||||
except IOError, e:
|
password_mgr.add_password(None, url, username, password)
|
||||||
print "Unable to open URL: ", str(e)
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
result = urlObj.readlines()
|
|
||||||
for line in result:
|
if __name__ == "__main__":
|
||||||
print line
|
print ("This module is supposed to be used as import in other scripts and not run standalone.")
|
||||||
|
print ("Use sabToSickBeard instead.")
|
||||||
|
sys.exit(1)
|
|
@ -1001,7 +1001,7 @@ class PostProcessor(object):
|
||||||
self._moveAndSymlink(self.file_path, dest_path, new_base_name, sickbeard.MOVE_ASSOCIATED_FILES,
|
self._moveAndSymlink(self.file_path, dest_path, new_base_name, sickbeard.MOVE_ASSOCIATED_FILES,
|
||||||
sickbeard.USE_SUBTITLES and ep_obj.show.subtitles)
|
sickbeard.USE_SUBTITLES and ep_obj.show.subtitles)
|
||||||
else:
|
else:
|
||||||
logger.log(u"Unknown process method: " + sickbeard.PROCESS_METHOD, logger.ERROR)
|
logger.log(u"Unknown process method: " + str(self.process_method), logger.ERROR)
|
||||||
raise exceptions.PostProcessingFailed("Unable to move the files to their new home")
|
raise exceptions.PostProcessingFailed("Unable to move the files to their new home")
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
raise exceptions.PostProcessingFailed("Unable to move the files to their new home")
|
raise exceptions.PostProcessingFailed("Unable to move the files to their new home")
|
||||||
|
|
|
@ -254,9 +254,7 @@ class ProperFinder():
|
||||||
result.quality = curProper.quality
|
result.quality = curProper.quality
|
||||||
|
|
||||||
# snatch it
|
# snatch it
|
||||||
downloadResult = search.snatchEpisode(result, SNATCHED_PROPER)
|
search.snatchEpisode(result, SNATCHED_PROPER)
|
||||||
|
|
||||||
return downloadResult
|
|
||||||
|
|
||||||
def _genericName(self, name):
|
def _genericName(self, name):
|
||||||
return name.replace(".", " ").replace("-", " ").replace("_", " ").lower()
|
return name.replace(".", " ").replace("-", " ").replace("_", " ").lower()
|
||||||
|
|
|
@ -253,7 +253,7 @@ class KATProvider(generic.TorrentProvider):
|
||||||
for tr in torrent_rows[1:]:
|
for tr in torrent_rows[1:]:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
link = self.url + (tr.find('div', {'class': 'torrentname'}).find_all('a')[1])['href']
|
link = urlparse.urljoin(self.url,(tr.find('div', {'class': 'torrentname'}).find_all('a')[1])['href'])
|
||||||
id = tr.get('id')[-7:]
|
id = tr.get('id')[-7:]
|
||||||
title = (tr.find('div', {'class': 'torrentname'}).find_all('a')[1]).text
|
title = (tr.find('div', {'class': 'torrentname'}).find_all('a')[1]).text
|
||||||
url = tr.find('a', 'imagnet')['href']
|
url = tr.find('a', 'imagnet')['href']
|
||||||
|
|
|
@ -174,8 +174,11 @@ class SCCProvider(generic.TorrentProvider):
|
||||||
|
|
||||||
#Continue only if one Release is found
|
#Continue only if one Release is found
|
||||||
if len(torrent_rows) < 2:
|
if len(torrent_rows) < 2:
|
||||||
logger.log(u"The Data returned from " + self.name + " do not contains any torrent",
|
if html.title:
|
||||||
logger.DEBUG)
|
source = self.name + " (" + html.title.string + ")"
|
||||||
|
else:
|
||||||
|
source = self.name
|
||||||
|
logger.log(u"The Data returned from " + source + " does not contain any torrent", logger.DEBUG)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for result in torrent_table.find_all('tr')[1:]:
|
for result in torrent_table.find_all('tr')[1:]:
|
||||||
|
|
Loading…
Reference in a new issue