mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-15 01:32:53 -07:00
Remove superfluous classes
This commit is contained in:
parent
5a04a7b4d9
commit
d95fc59b45
7 changed files with 1042 additions and 1038 deletions
|
@ -10,6 +10,7 @@ import sys
|
||||||
|
|
||||||
import core
|
import core
|
||||||
from core import logger, main_db
|
from core import logger, main_db
|
||||||
|
from core.auto_process import comics, games, movies, music, tv
|
||||||
from core.user_scripts import external_script
|
from core.user_scripts import external_script
|
||||||
from core.utils import char_replace, convert_to_ascii, plex_update, replace_links
|
from core.utils import char_replace, convert_to_ascii, plex_update, replace_links
|
||||||
from six import text_type
|
from six import text_type
|
||||||
|
@ -237,21 +238,21 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
||||||
result = external_script(output_destination, input_name, input_category, section)
|
result = external_script(output_destination, input_name, input_category, section)
|
||||||
|
|
||||||
elif section_name in ['CouchPotato', 'Radarr']:
|
elif section_name in ['CouchPotato', 'Radarr']:
|
||||||
result = core.Movie().process(section_name, output_destination, input_name,
|
result = movies.process(section_name, output_destination, input_name,
|
||||||
status, client_agent, input_hash, input_category)
|
status, client_agent, input_hash, input_category)
|
||||||
elif section_name in ['SickBeard', 'NzbDrone', 'Sonarr']:
|
elif section_name in ['SickBeard', 'NzbDrone', 'Sonarr']:
|
||||||
if input_hash:
|
if input_hash:
|
||||||
input_hash = input_hash.upper()
|
input_hash = input_hash.upper()
|
||||||
result = core.TV().process(section_name, output_destination, input_name,
|
result = tv.process(section_name, output_destination, input_name,
|
||||||
status, client_agent, input_hash, input_category)
|
status, client_agent, input_hash, input_category)
|
||||||
elif section_name in ['HeadPhones', 'Lidarr']:
|
elif section_name in ['HeadPhones', 'Lidarr']:
|
||||||
result = core.Music().process(section_name, output_destination, input_name,
|
result = music.process(section_name, output_destination, input_name,
|
||||||
status, client_agent, input_category)
|
status, client_agent, input_category)
|
||||||
elif section_name == 'Mylar':
|
elif section_name == 'Mylar':
|
||||||
result = core.Comic().process(section_name, output_destination, input_name,
|
result = comics.process(section_name, output_destination, input_name,
|
||||||
status, client_agent, input_category)
|
status, client_agent, input_category)
|
||||||
elif section_name == 'Gamez':
|
elif section_name == 'Gamez':
|
||||||
result = core.Game().process(section_name, output_destination, input_name,
|
result = games.process(section_name, output_destination, input_name,
|
||||||
status, client_agent, input_category)
|
status, client_agent, input_category)
|
||||||
|
|
||||||
plex_update(input_category)
|
plex_update(input_category)
|
||||||
|
|
|
@ -11,8 +11,7 @@ from core.utils import convert_to_ascii, remote_dir, server_responding
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class Comic(object):
|
def process(section, dir_name, input_name=None, status=0, client_agent='manual', input_category=None):
|
||||||
def process(self, section, dir_name, input_name=None, status=0, client_agent='manual', input_category=None):
|
|
||||||
apc_version = "2.04"
|
apc_version = "2.04"
|
||||||
comicrn_version = "1.01"
|
comicrn_version = "1.01"
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,7 @@ from core.utils import convert_to_ascii, server_responding
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class Game(object):
|
def process(section, dir_name, input_name=None, status=0, client_agent='manual', input_category=None):
|
||||||
def process(self, section, dir_name, input_name=None, status=0, client_agent='manual', input_category=None):
|
|
||||||
status = int(status)
|
status = int(status)
|
||||||
|
|
||||||
cfg = dict(core.CFG[section][input_category])
|
cfg = dict(core.CFG[section][input_category])
|
||||||
|
|
|
@ -14,8 +14,7 @@ from core.utils import convert_to_ascii, find_download, find_imdbid, import_subs
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class Movie(object):
|
def process(section, dir_name, input_name=None, status=0, client_agent="manual", download_id="", input_category=None, failure_link=None):
|
||||||
def process(self, section, dir_name, input_name=None, status=0, client_agent="manual", download_id="", input_category=None, failure_link=None):
|
|
||||||
|
|
||||||
cfg = dict(core.CFG[section][input_category])
|
cfg = dict(core.CFG[section][input_category])
|
||||||
|
|
||||||
|
@ -56,7 +55,7 @@ class Movie(object):
|
||||||
release = None
|
release = None
|
||||||
elif server_responding(base_url):
|
elif server_responding(base_url):
|
||||||
if section == "CouchPotato":
|
if section == "CouchPotato":
|
||||||
release = self.get_release(base_url, imdbid, download_id)
|
release = get_release(base_url, imdbid, download_id)
|
||||||
else:
|
else:
|
||||||
release = None
|
release = None
|
||||||
else:
|
else:
|
||||||
|
@ -282,7 +281,7 @@ class Movie(object):
|
||||||
while time.time() < timeout: # only wait 2 (default) minutes, then return.
|
while time.time() < timeout: # only wait 2 (default) minutes, then return.
|
||||||
logger.postprocess("Checking for status change, please stand by ...", section)
|
logger.postprocess("Checking for status change, please stand by ...", section)
|
||||||
if section == "CouchPotato":
|
if section == "CouchPotato":
|
||||||
release = self.get_release(base_url, imdbid, download_id, release_id)
|
release = get_release(base_url, imdbid, download_id, release_id)
|
||||||
scan_id = None
|
scan_id = None
|
||||||
else:
|
else:
|
||||||
release = None
|
release = None
|
||||||
|
@ -304,7 +303,7 @@ class Movie(object):
|
||||||
pass
|
pass
|
||||||
elif scan_id:
|
elif scan_id:
|
||||||
url = "{0}/{1}".format(base_url, scan_id)
|
url = "{0}/{1}".format(base_url, scan_id)
|
||||||
command_status = self.command_complete(url, params, headers, section)
|
command_status = command_complete(url, params, headers, section)
|
||||||
if command_status:
|
if command_status:
|
||||||
logger.debug("The Scan command return status: {0}".format(command_status), section)
|
logger.debug("The Scan command return status: {0}".format(command_status), section)
|
||||||
if command_status in ['completed']:
|
if command_status in ['completed']:
|
||||||
|
@ -328,7 +327,7 @@ class Movie(object):
|
||||||
time.sleep(10 * wait_for)
|
time.sleep(10 * wait_for)
|
||||||
|
|
||||||
# The status hasn't changed. we have waited wait_for minutes which is more than enough. uTorrent can resume seeding now.
|
# The status hasn't changed. we have waited wait_for minutes which is more than enough. uTorrent can resume seeding now.
|
||||||
if section == "Radarr" and self.completed_download_handling(url2, headers, section=section):
|
if section == "Radarr" and completed_download_handling(url2, headers, section=section):
|
||||||
logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.".format(section), section)
|
logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.".format(section), section)
|
||||||
return [status, "{0}: Complete DownLoad Handling is enabled. Passing back to {1}".format(section, section)]
|
return [status, "{0}: Complete DownLoad Handling is enabled. Passing back to {1}".format(section, section)]
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
@ -336,7 +335,8 @@ class Movie(object):
|
||||||
section)
|
section)
|
||||||
return [1, "{0}: Failed to post-process - No change in status".format(section)]
|
return [1, "{0}: Failed to post-process - No change in status".format(section)]
|
||||||
|
|
||||||
def command_complete(self, url, params, headers, section):
|
|
||||||
|
def command_complete(url, params, headers, section):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
|
@ -353,7 +353,8 @@ class Movie(object):
|
||||||
logger.error("{0} did not return expected json data.".format(section), section)
|
logger.error("{0} did not return expected json data.".format(section), section)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def completed_download_handling(self, url2, headers, section="MAIN"):
|
|
||||||
|
def completed_download_handling(url2, headers, section="MAIN"):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
|
@ -369,7 +370,8 @@ class Movie(object):
|
||||||
# ValueError catches simplejson's JSONDecodeError and json's ValueError
|
# ValueError catches simplejson's JSONDecodeError and json's ValueError
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_release(self, base_url, imdb_id=None, download_id=None, release_id=None):
|
|
||||||
|
def get_release(base_url, imdb_id=None, download_id=None, release_id=None):
|
||||||
results = {}
|
results = {}
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,7 @@ from core.utils import convert_to_ascii, list_media_files, remote_dir, remove_di
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class Music(object):
|
def process(section, dir_name, input_name=None, status=0, client_agent="manual", input_category=None):
|
||||||
def process(self, section, dir_name, input_name=None, status=0, client_agent="manual", input_category=None):
|
|
||||||
status = int(status)
|
status = int(status)
|
||||||
|
|
||||||
cfg = dict(core.CFG[section][input_category])
|
cfg = dict(core.CFG[section][input_category])
|
||||||
|
@ -73,7 +72,7 @@ class Music(object):
|
||||||
'dir': remote_dir(dir_name) if remote_path else dir_name
|
'dir': remote_dir(dir_name) if remote_path else dir_name
|
||||||
}
|
}
|
||||||
|
|
||||||
res = self.force_process(params, url, apikey, input_name, dir_name, section, wait_for)
|
res = force_process(params, url, apikey, input_name, dir_name, section, wait_for)
|
||||||
if res[0] in [0, 1]:
|
if res[0] in [0, 1]:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -83,7 +82,7 @@ class Music(object):
|
||||||
'dir': os.path.split(remote_dir(dir_name))[0] if remote_path else os.path.split(dir_name)[0]
|
'dir': os.path.split(remote_dir(dir_name))[0] if remote_path else os.path.split(dir_name)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
res = self.force_process(params, url, apikey, input_name, dir_name, section, wait_for)
|
res = force_process(params, url, apikey, input_name, dir_name, section, wait_for)
|
||||||
if res[0] in [0, 1]:
|
if res[0] in [0, 1]:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ class Music(object):
|
||||||
url = "{0}/{1}".format(url, scan_id)
|
url = "{0}/{1}".format(url, scan_id)
|
||||||
while n < 6: # set up wait_for minutes to see if command completes..
|
while n < 6: # set up wait_for minutes to see if command completes..
|
||||||
time.sleep(10 * wait_for)
|
time.sleep(10 * wait_for)
|
||||||
command_status = self.command_complete(url, params, headers, section)
|
command_status = command_complete(url, params, headers, section)
|
||||||
if command_status and command_status in ['completed', 'failed']:
|
if command_status and command_status in ['completed', 'failed']:
|
||||||
break
|
break
|
||||||
n += 1
|
n += 1
|
||||||
|
@ -157,7 +156,8 @@ class Music(object):
|
||||||
remove_dir(dir_name)
|
remove_dir(dir_name)
|
||||||
return [1, "{0}: Failed to post-process. {1} does not support failed downloads".format(section, section)] # Return as failed to flag this in the downloader.
|
return [1, "{0}: Failed to post-process. {1} does not support failed downloads".format(section, section)] # Return as failed to flag this in the downloader.
|
||||||
|
|
||||||
def command_complete(self, url, params, headers, section):
|
|
||||||
|
def command_complete(url, params, headers, section):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
|
@ -174,7 +174,8 @@ class Music(object):
|
||||||
logger.error("{0} did not return expected json data.".format(section), section)
|
logger.error("{0} did not return expected json data.".format(section), section)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_status(self, url, apikey, dir_name):
|
|
||||||
|
def get_status(url, apikey, dir_name):
|
||||||
logger.debug("Attempting to get current status for release:{0}".format(os.path.basename(dir_name)))
|
logger.debug("Attempting to get current status for release:{0}".format(os.path.basename(dir_name)))
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
@ -200,8 +201,9 @@ class Music(object):
|
||||||
if os.path.basename(dir_name) == album['FolderName']:
|
if os.path.basename(dir_name) == album['FolderName']:
|
||||||
return album["Status"].lower()
|
return album["Status"].lower()
|
||||||
|
|
||||||
def force_process(self, params, url, apikey, input_name, dir_name, section, wait_for):
|
|
||||||
release_status = self.get_status(url, apikey, dir_name)
|
def force_process(params, url, apikey, input_name, dir_name, section, wait_for):
|
||||||
|
release_status = get_status(url, apikey, dir_name)
|
||||||
if not release_status:
|
if not release_status:
|
||||||
logger.error("Could not find a status for {0}, is it in the wanted list ?".format(input_name), section)
|
logger.error("Could not find a status for {0}, is it in the wanted list ?".format(input_name), section)
|
||||||
|
|
||||||
|
@ -227,7 +229,7 @@ class Music(object):
|
||||||
# we will now wait for this album to be processed before returning to TorrentToMedia and unpausing.
|
# we will now wait for this album to be processed before returning to TorrentToMedia and unpausing.
|
||||||
timeout = time.time() + 60 * wait_for
|
timeout = time.time() + 60 * wait_for
|
||||||
while time.time() < timeout:
|
while time.time() < timeout:
|
||||||
current_status = self.get_status(url, apikey, dir_name)
|
current_status = get_status(url, apikey, dir_name)
|
||||||
if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie.
|
if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie.
|
||||||
logger.postprocess("SUCCESS: This release is now marked as status [{0}]".format(current_status), section)
|
logger.postprocess("SUCCESS: This release is now marked as status [{0}]".format(current_status), section)
|
||||||
return [0, "{0}: Successfully post-processed {1}".format(section, input_name)]
|
return [0, "{0}: Successfully post-processed {1}".format(section, input_name)]
|
||||||
|
|
|
@ -17,8 +17,7 @@ from core.utils import convert_to_ascii, flatten, import_subs, list_media_files,
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class TV(object):
|
def process(section, dir_name, input_name=None, failed=False, client_agent="manual", download_id=None, input_category=None, failure_link=None):
|
||||||
def process(self, section, dir_name, input_name=None, failed=False, client_agent="manual", download_id=None, input_category=None, failure_link=None):
|
|
||||||
|
|
||||||
cfg = dict(core.CFG[section][input_category])
|
cfg = dict(core.CFG[section][input_category])
|
||||||
|
|
||||||
|
@ -316,7 +315,7 @@ class TV(object):
|
||||||
url = "{0}/{1}".format(url, scan_id)
|
url = "{0}/{1}".format(url, scan_id)
|
||||||
while n < 6: # set up wait_for minutes to see if command completes..
|
while n < 6: # set up wait_for minutes to see if command completes..
|
||||||
time.sleep(10 * wait_for)
|
time.sleep(10 * wait_for)
|
||||||
command_status = self.command_complete(url, params, headers, section)
|
command_status = command_complete(url, params, headers, section)
|
||||||
if command_status and command_status in ['completed', 'failed']:
|
if command_status and command_status in ['completed', 'failed']:
|
||||||
break
|
break
|
||||||
n += 1
|
n += 1
|
||||||
|
@ -331,7 +330,7 @@ class TV(object):
|
||||||
elif command_status and command_status in ['failed']:
|
elif command_status and command_status in ['failed']:
|
||||||
logger.debug("The Scan command has failed. Renaming was not successful.", section)
|
logger.debug("The Scan command has failed. Renaming was not successful.", section)
|
||||||
# return [1, "%s: Failed to post-process %s" % (section, input_name) ]
|
# return [1, "%s: Failed to post-process %s" % (section, input_name) ]
|
||||||
if self.completed_download_handling(url2, headers, section=section):
|
if completed_download_handling(url2, headers, section=section):
|
||||||
logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.".format(section), section)
|
logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.".format(section), section)
|
||||||
return [status, "{0}: Complete DownLoad Handling is enabled. Passing back to {1}".format(section, section)]
|
return [status, "{0}: Complete DownLoad Handling is enabled. Passing back to {1}".format(section, section)]
|
||||||
else:
|
else:
|
||||||
|
@ -340,7 +339,8 @@ class TV(object):
|
||||||
else:
|
else:
|
||||||
return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)] # We did not receive Success confirmation.
|
return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)] # We did not receive Success confirmation.
|
||||||
|
|
||||||
def command_complete(self, url, params, headers, section):
|
|
||||||
|
def command_complete(url, params, headers, section):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
|
@ -357,7 +357,8 @@ class TV(object):
|
||||||
logger.error("{0} did not return expected json data.".format(section), section)
|
logger.error("{0} did not return expected json data.".format(section), section)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def completed_download_handling(self, url2, headers, section="MAIN"):
|
|
||||||
|
def completed_download_handling(url2, headers, section="MAIN"):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
|
|
|
@ -12,7 +12,7 @@ import sys
|
||||||
|
|
||||||
import core
|
import core
|
||||||
from core import logger, main_db
|
from core import logger, main_db
|
||||||
from core.auto_process import Comic, Game, Movie, Music, TV
|
from core.auto_process import comics, games, movies, music, tv
|
||||||
from core.user_scripts import external_script
|
from core.user_scripts import external_script
|
||||||
from core.utils import char_replace, clean_dir, convert_to_ascii, extract_files, get_dirs, get_download_info, get_nzoid, plex_update, update_download_info_status
|
from core.utils import char_replace, clean_dir, convert_to_ascii, extract_files, get_dirs, get_download_info, get_nzoid, plex_update, update_download_info_status
|
||||||
|
|
||||||
|
@ -109,18 +109,18 @@ def process(input_directory, input_name=None, status=0, client_agent='manual', d
|
||||||
logger.info("Calling {0}:{1} to post-process:{2}".format(section_name, input_category, input_name))
|
logger.info("Calling {0}:{1} to post-process:{2}".format(section_name, input_category, input_name))
|
||||||
|
|
||||||
if section_name in ["CouchPotato", "Radarr"]:
|
if section_name in ["CouchPotato", "Radarr"]:
|
||||||
result = Movie().process(section_name, input_directory, input_name, status, client_agent, download_id,
|
result = movies.process(section_name, input_directory, input_name, status, client_agent, download_id,
|
||||||
input_category, failure_link)
|
input_category, failure_link)
|
||||||
elif section_name in ["SickBeard", "NzbDrone", "Sonarr"]:
|
elif section_name in ["SickBeard", "NzbDrone", "Sonarr"]:
|
||||||
result = TV().process(section_name, input_directory, input_name, status, client_agent,
|
result = tv.process(section_name, input_directory, input_name, status, client_agent,
|
||||||
download_id, input_category, failure_link)
|
download_id, input_category, failure_link)
|
||||||
elif section_name in ["HeadPhones", "Lidarr"]:
|
elif section_name in ["HeadPhones", "Lidarr"]:
|
||||||
result = Music().process(section_name, input_directory, input_name, status, client_agent, input_category)
|
result = music.process(section_name, input_directory, input_name, status, client_agent, input_category)
|
||||||
elif section_name == "Mylar":
|
elif section_name == "Mylar":
|
||||||
result = Comic().process(section_name, input_directory, input_name, status, client_agent,
|
result = comics.process(section_name, input_directory, input_name, status, client_agent,
|
||||||
input_category)
|
input_category)
|
||||||
elif section_name == "Gamez":
|
elif section_name == "Gamez":
|
||||||
result = Game().process(section_name, input_directory, input_name, status, client_agent, input_category)
|
result = games.process(section_name, input_directory, input_name, status, client_agent, input_category)
|
||||||
elif section_name == 'UserScript':
|
elif section_name == 'UserScript':
|
||||||
result = external_script(input_directory, input_name, input_category, section[usercat])
|
result = external_script(input_directory, input_name, input_category, section[usercat])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue