mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 10:36:52 -07:00
Medusa apiv2 (#1812)
* add fork Medusa-apiV2 * Added classes for sickbeard (base) and PyMedusa. * refactored part of the forks.py code -> InitSickBeard class. * Add .vscode to gitignore * Further refactor forks.py -> sickbeard.py * Working example for pyMedusa when fork is 'medusa' (no api key) * fix import for Py2 Co-authored-by: clinton-hall <fock_wulf@hotmail.com>
This commit is contained in:
parent
0acf78f196
commit
6a6b25fece
7 changed files with 492 additions and 256 deletions
38
core/auto_process/managers/pymedusa.py
Normal file
38
core/auto_process/managers/pymedusa.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import requests
|
||||
|
||||
from core import logger
|
||||
|
||||
from .sickbeard import SickBeard
|
||||
|
||||
|
||||
class PyMedusa(SickBeard):
|
||||
"""PyMedusa class."""
|
||||
|
||||
def __init__(self, sb_init):
|
||||
super(PyMedusa, self).__init__(sb_init)
|
||||
self.cfg = self.sb_init.config # in case we need something that's not already directly on self.sb_init.
|
||||
|
||||
def _configure():
|
||||
"""Configure pymedusa with config options."""
|
||||
|
||||
def _create_url(self):
|
||||
if self.sb_init.apikey:
|
||||
return '{0}{1}:{2}{3}/api/{4}/'.format(self.sb_init.protocol, self.sb_init.host, self.sb_init.port, self.sb_init.web_root, self.sb_init.apikey)
|
||||
return '{0}{1}:{2}{3}/home/postprocess/processEpisode'.format(self.sb_init.protocol, self.sb_init.host, self.sb_init.port, self.sb_init.web_root)
|
||||
|
||||
def api_call(self):
|
||||
"""Perform the api call with PyMedusa."""
|
||||
s = requests.Session()
|
||||
|
||||
self._process_fork_prarams()
|
||||
url = self._create_url()
|
||||
|
||||
logger.debug('Opening URL: {0} with params: {1}'.format(url, self.sb_init.fork_params), self.sb_init.section)
|
||||
if not self.sb_init.apikey and self.sb_init.username and self.sb_init.password:
|
||||
login = '{0}{1}:{2}{3}/login'.format(self.sb_init.protocol, self.sb_init.host, self.sb_init.port, self.sb_init.web_root)
|
||||
login_params = {'username': self.sb_init.username, 'password': self.sb_init.password}
|
||||
r = s.get(login, verify=False, timeout=(30, 60))
|
||||
if r.status_code in [401, 403] and r.cookies.get('_xsrf'):
|
||||
login_params['_xsrf'] = r.cookies.get('_xsrf')
|
||||
s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60))
|
||||
return s.get(url, auth=(self.sb_init.username, self.sb_init.password), params=self.sb_init.fork_params, stream=True, verify=False, timeout=(30, 1800))
|
Loading…
Add table
Add a link
Reference in a new issue