Commit 6c346a8c authored by echel0n's avatar echel0n
Browse files

Misc code improvements for Plex notifier

Refactored database backups to use pickle default protocol to stay compatible with Python 3.5.x
Refactored aniDBfileInfo.py to use pickle default protocol to stay compatible with Python 3.5.x
parent ec0d14e0
......@@ -290,9 +290,9 @@ class SRDatabase(object):
def backup(self, filename):
metadata = self.get_metadata()
data = {t: dumps(self.session().query(metadata.tables[t]).all()) for t in metadata.tables}
data = {t: dumps(self.session().query(metadata.tables[t]).all(), protocol=pickle.DEFAULT_PROTOCOL) for t in metadata.tables}
with open(filename, 'wb') as fh:
pickle.dump(data, fh)
pickle.dump(data, fh, protocol=pickle.DEFAULT_PROTOCOL)
def restore(self, filename):
session = self.session()
......
......@@ -64,7 +64,7 @@ def get_ED2K(filePath, forceHash=False, cacheLocation=os.path.normpath(sys.path[
try:
if len(get_ED2K.ED2KCache) != 0:
with open(cacheLocation, 'wb') as f:
pickle.dump(get_ED2K.ED2KCache, f, pickle.HIGHEST_PROTOCOL)
pickle.dump(get_ED2K.ED2KCache, f, pickle.DEFAULT_PROTOCOL)
except:
logger.error("Error occurred while writing back to disk")
return
......
......@@ -82,13 +82,13 @@ class PLEXNotifier(Notifiers):
else:
sickrage.app.log.debug('PLEX: Contacting via url: ' + url)
try:
result = WebSession().get(url, headers=headers).text
except Exception as e:
resp = WebSession().get(url, headers=headers)
if not resp or not resp.text:
sickrage.app.log.warning('PLEX: Warning: Couldn\'t contact Plex at {}: {}'.format(url, e))
return False
sickrage.app.log.debug('PLEX: HTTP response: ' + result.replace('\n', ''))
sickrage.app.log.debug('PLEX: HTTP response: ' + resp.text.replace('\n', ''))
return 'OK'
def _notify_pmc(self, message, title='SiCKRAGE', host=None, username=None, password=None, force=False):
......@@ -234,13 +234,14 @@ class PLEXNotifier(Notifiers):
hosts_try = (hosts_all.copy(), hosts_match.copy())[bool(hosts_match)]
host_list = []
for section_key, cur_host in hosts_try.items():
try:
url = 'http://%s/library/sections/%s/refresh' % (cur_host, section_key)
WebSession().get(url, headers=self.headers)
host_list.append(cur_host)
except Exception as e:
sickrage.app.log.warning('PLEX: Error updating library section for Plex Media Server: {}'.format(e))
url = 'http://%s/library/sections/%s/refresh' % (cur_host, section_key)
resp = WebSession().get(url, headers=self.headers)
if not resp or not resp.ok:
sickrage.app.log.warning('PLEX: Error updating library section for Plex Media Server')
hosts_failed.add(cur_host)
continue
host_list.append(cur_host)
if hosts_match:
sickrage.app.log.debug('PLEX: Updating hosts where TV section paths match the downloaded show: ' + ', '.join(set(host_list)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment