mirror of
https://github.com/moparisthebest/SickRage
synced 2024-08-13 16:53:54 -04:00
Fixed issue #1092 - auto post-processing scripts re-coded to work with new login system.
This commit is contained in:
parent
92a554da99
commit
931d5f41c2
@ -22,6 +22,7 @@ from __future__ import with_statement
|
|||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
import requests
|
||||||
|
|
||||||
# Try importing Python 2 modules using new names
|
# Try importing Python 2 modules using new names
|
||||||
try:
|
try:
|
||||||
@ -35,20 +36,6 @@ except ImportError:
|
|||||||
import urllib.request as urllib2
|
import urllib.request as urllib2
|
||||||
from urllib.parse import urlencode
|
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, status=None):
|
def processEpisode(dir_to_process, org_NZB_name=None, status=None):
|
||||||
# Default values
|
# Default values
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
@ -125,20 +112,17 @@ def processEpisode(dir_to_process, org_NZB_name=None, status=None):
|
|||||||
else:
|
else:
|
||||||
protocol = "http://"
|
protocol = "http://"
|
||||||
|
|
||||||
url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode?" + urlencode(params)
|
url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode"
|
||||||
|
login_url = protocol + host + ":" + port + web_root + "login"
|
||||||
|
|
||||||
print ("Opening URL: " + url)
|
print ("Opening URL: " + url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
sess = requests.Session()
|
||||||
password_mgr.add_password(None, url, username, password)
|
sess.post(login_url, data={'username': username, 'password': password}, stream=True, verify=False)
|
||||||
handler = HTTPBasicAuthHandler(password_mgr)
|
result = sess.get(url, params=params, stream=True, verify=False)
|
||||||
opener = urllib2.build_opener(handler)
|
|
||||||
urllib2.install_opener(opener)
|
|
||||||
|
|
||||||
result = opener.open(url).readlines()
|
for line in result.iter_lines():
|
||||||
|
|
||||||
for line in result:
|
|
||||||
if line:
|
if line:
|
||||||
print (line.strip())
|
print (line.strip())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user