mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 05:43:16 -07:00
Merge pull request #1943 from clinton-hall/core-breach
Refactor core -> nzb2media
This commit is contained in:
commit
5f6b46f73c
75 changed files with 993 additions and 1000 deletions
|
@ -3,10 +3,6 @@ current_version = 12.1.11
|
|||
commit = True
|
||||
tag = False
|
||||
|
||||
[bumpversion:file:setup.py]
|
||||
search = version='{current_version}'
|
||||
replace = version='{new_version}'
|
||||
|
||||
[bumpversion:file:core/__init__.py]
|
||||
[bumpversion:file:nzb2media/__init__.py]
|
||||
search = __version__ = '{current_version}'
|
||||
replace = __version__ = '{new_version}'
|
||||
|
|
|
@ -7,14 +7,14 @@ import cleanup
|
|||
eol.check()
|
||||
cleanup.clean(cleanup.FOLDER_STRUCTURE)
|
||||
|
||||
import core
|
||||
from core import logger, main_db
|
||||
from core.auto_process import comics, games, movies, music, tv, books
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.plugins.plex import plex_update
|
||||
from core.user_scripts import external_script
|
||||
from core.utils.encoding import char_replace, convert_to_ascii
|
||||
from core.utils.links import replace_links
|
||||
import nzb2media
|
||||
from nzb2media import logger, main_db
|
||||
from nzb2media.auto_process import comics, games, movies, music, tv, books
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.plugins.plex import plex_update
|
||||
from nzb2media.user_scripts import external_script
|
||||
from nzb2media.utils.encoding import char_replace, convert_to_ascii
|
||||
from nzb2media.utils.links import replace_links
|
||||
|
||||
|
||||
def process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent):
|
||||
|
@ -22,7 +22,7 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
root = 0
|
||||
found_file = 0
|
||||
|
||||
if client_agent != 'manual' and not core.DOWNLOAD_INFO:
|
||||
if client_agent != 'manual' and not nzb2media.DOWNLOAD_INFO:
|
||||
logger.debug(f'Adding TORRENT download info for directory {input_directory} to database')
|
||||
|
||||
my_db = main_db.DBConnection()
|
||||
|
@ -50,9 +50,9 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
logger.debug(f'Received Directory: {input_directory} | Name: {input_name} | Category: {input_category}')
|
||||
|
||||
# Confirm the category by parsing directory structure
|
||||
input_directory, input_name, input_category, root = core.category_search(
|
||||
input_directory, input_name, input_category, root = nzb2media.category_search(
|
||||
input_directory, input_name, input_category,
|
||||
root, core.CATEGORIES,
|
||||
root, nzb2media.CATEGORIES,
|
||||
)
|
||||
if input_category == '':
|
||||
input_category = 'UNCAT'
|
||||
|
@ -62,13 +62,13 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
logger.debug(f'Determined Directory: {input_directory} | Name: {input_name} | Category: {input_category}')
|
||||
|
||||
# auto-detect section
|
||||
section = core.CFG.findsection(input_category).isenabled()
|
||||
section = nzb2media.CFG.findsection(input_category).isenabled()
|
||||
if section is None: #Check for user_scripts for 'ALL' and 'UNCAT'
|
||||
if usercat in core.CATEGORIES:
|
||||
section = core.CFG.findsection('ALL').isenabled()
|
||||
if usercat in nzb2media.CATEGORIES:
|
||||
section = nzb2media.CFG.findsection('ALL').isenabled()
|
||||
usercat = 'ALL'
|
||||
else:
|
||||
section = core.CFG.findsection('UNCAT').isenabled()
|
||||
section = nzb2media.CFG.findsection('UNCAT').isenabled()
|
||||
usercat = 'UNCAT'
|
||||
if section is None: # We haven't found any categories to process.
|
||||
logger.error(f'Category:[{input_category}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.')
|
||||
|
@ -94,22 +94,22 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
unique_path = int(section.get('unique_path', 1))
|
||||
|
||||
if client_agent != 'manual':
|
||||
core.pause_torrent(client_agent, input_hash, input_id, input_name)
|
||||
nzb2media.pause_torrent(client_agent, input_hash, input_id, input_name)
|
||||
|
||||
# In case input is not directory, make sure to create one.
|
||||
# This way Processing is isolated.
|
||||
if not os.path.isdir(os.path.join(input_directory, input_name)):
|
||||
basename = os.path.basename(input_directory)
|
||||
basename = core.sanitize_name(input_name) \
|
||||
if input_name == basename else os.path.splitext(core.sanitize_name(input_name))[0]
|
||||
output_destination = os.path.join(core.OUTPUT_DIRECTORY, input_category, basename)
|
||||
basename = nzb2media.sanitize_name(input_name) \
|
||||
if input_name == basename else os.path.splitext(nzb2media.sanitize_name(input_name))[0]
|
||||
output_destination = os.path.join(nzb2media.OUTPUT_DIRECTORY, input_category, basename)
|
||||
elif unique_path:
|
||||
output_destination = os.path.normpath(
|
||||
core.os.path.join(core.OUTPUT_DIRECTORY, input_category, core.sanitize_name(input_name).replace(' ', '.')),
|
||||
nzb2media.os.path.join(nzb2media.OUTPUT_DIRECTORY, input_category, nzb2media.sanitize_name(input_name).replace(' ', '.')),
|
||||
)
|
||||
else:
|
||||
output_destination = os.path.normpath(
|
||||
core.os.path.join(core.OUTPUT_DIRECTORY, input_category),
|
||||
nzb2media.os.path.join(nzb2media.OUTPUT_DIRECTORY, input_category),
|
||||
)
|
||||
|
||||
if output_destination in input_directory:
|
||||
|
@ -117,23 +117,23 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
|
||||
logger.info(f'Output directory set to: {output_destination}')
|
||||
|
||||
if core.SAFE_MODE and output_destination == core.TORRENT_DEFAULT_DIRECTORY:
|
||||
if nzb2media.SAFE_MODE and output_destination == nzb2media.TORRENT_DEFAULT_DIRECTORY:
|
||||
logger.error(f'The output directory:[{input_directory}] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting')
|
||||
return [-1, '']
|
||||
|
||||
logger.debug(f'Scanning files in directory: {input_directory}')
|
||||
|
||||
if section_name in ['HeadPhones', 'Lidarr']:
|
||||
core.NOFLATTEN.extend(
|
||||
nzb2media.NOFLATTEN.extend(
|
||||
input_category,
|
||||
) # Make sure we preserve folder structure for HeadPhones.
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
||||
if extract == 1:
|
||||
input_files = core.list_media_files(input_directory, archives=False, other=True, otherext=extensions)
|
||||
input_files = nzb2media.list_media_files(input_directory, archives=False, other=True, otherext=extensions)
|
||||
else:
|
||||
input_files = core.list_media_files(input_directory, other=True, otherext=extensions)
|
||||
input_files = nzb2media.list_media_files(input_directory, other=True, otherext=extensions)
|
||||
if len(input_files) == 0 and os.path.isfile(input_directory):
|
||||
input_files = [input_directory]
|
||||
logger.debug(f'Found 1 file to process: {input_directory}')
|
||||
|
@ -144,19 +144,19 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
file_name, file_ext = os.path.splitext(os.path.basename(inputFile))
|
||||
full_file_name = os.path.basename(inputFile)
|
||||
|
||||
target_file = core.os.path.join(output_destination, full_file_name)
|
||||
if input_category in core.NOFLATTEN:
|
||||
target_file = nzb2media.os.path.join(output_destination, full_file_name)
|
||||
if input_category in nzb2media.NOFLATTEN:
|
||||
if not os.path.basename(file_path) in output_destination:
|
||||
target_file = core.os.path.join(
|
||||
core.os.path.join(output_destination, os.path.basename(file_path)), full_file_name,
|
||||
target_file = nzb2media.os.path.join(
|
||||
nzb2media.os.path.join(output_destination, os.path.basename(file_path)), full_file_name,
|
||||
)
|
||||
logger.debug(f'Setting outputDestination to {os.path.dirname(target_file)} to preserve folder structure')
|
||||
if root == 1:
|
||||
if not found_file:
|
||||
logger.debug(f'Looking for {input_name} in: {inputFile}')
|
||||
if any([
|
||||
core.sanitize_name(input_name) in core.sanitize_name(inputFile),
|
||||
core.sanitize_name(file_name) in core.sanitize_name(input_name),
|
||||
nzb2media.sanitize_name(input_name) in nzb2media.sanitize_name(inputFile),
|
||||
nzb2media.sanitize_name(file_name) in nzb2media.sanitize_name(input_name),
|
||||
]):
|
||||
found_file = True
|
||||
logger.debug(f'Found file {full_file_name} that matches Torrent Name {input_name}')
|
||||
|
@ -177,8 +177,8 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
|
||||
if torrent_no_link == 0:
|
||||
try:
|
||||
core.copy_link(inputFile, target_file, core.USE_LINK)
|
||||
core.remove_read_only(target_file)
|
||||
nzb2media.copy_link(inputFile, target_file, nzb2media.USE_LINK)
|
||||
nzb2media.remove_read_only(target_file)
|
||||
except Exception:
|
||||
logger.error(f'Failed to link: {inputFile} to {target_file}')
|
||||
|
||||
|
@ -186,16 +186,16 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
|
||||
if extract == 1:
|
||||
logger.debug(f'Checking for archives to extract in directory: {input_directory}')
|
||||
core.extract_files(input_directory, output_destination, keep_archive)
|
||||
nzb2media.extract_files(input_directory, output_destination, keep_archive)
|
||||
|
||||
if input_category not in core.NOFLATTEN:
|
||||
if input_category not in nzb2media.NOFLATTEN:
|
||||
# don't flatten hp in case multi cd albums, and we need to copy this back later.
|
||||
core.flatten(output_destination)
|
||||
nzb2media.flatten(output_destination)
|
||||
|
||||
# Now check if video files exist in destination:
|
||||
if section_name in ['SickBeard', 'SiCKRAGE', 'NzbDrone', 'Sonarr', 'CouchPotato', 'Radarr', 'Watcher3']:
|
||||
num_videos = len(
|
||||
core.list_media_files(output_destination, media=True, audio=False, meta=False, archives=False),
|
||||
nzb2media.list_media_files(output_destination, media=True, audio=False, meta=False, archives=False),
|
||||
)
|
||||
if num_videos > 0:
|
||||
logger.info(f'Found {num_videos} media files in {output_destination}')
|
||||
|
@ -213,8 +213,8 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
|
||||
logger.info(f'Calling {section_name}:{usercat} to post-process:{input_name}')
|
||||
|
||||
if core.TORRENT_CHMOD_DIRECTORY:
|
||||
core.rchmod(output_destination, core.TORRENT_CHMOD_DIRECTORY)
|
||||
if nzb2media.TORRENT_CHMOD_DIRECTORY:
|
||||
nzb2media.rchmod(output_destination, nzb2media.TORRENT_CHMOD_DIRECTORY)
|
||||
|
||||
if section_name == 'UserScript':
|
||||
result = external_script(output_destination, input_name, input_category, section)
|
||||
|
@ -249,7 +249,7 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
plex_update(input_category)
|
||||
|
||||
if result.status_code != 0:
|
||||
if not core.TORRENT_RESUME_ON_FAILURE:
|
||||
if not nzb2media.TORRENT_RESUME_ON_FAILURE:
|
||||
logger.error(
|
||||
'A problem was reported in the autoProcess* script. '
|
||||
'Torrent won\'t resume seeding (settings)',
|
||||
|
@ -259,36 +259,36 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
'A problem was reported in the autoProcess* script. '
|
||||
'If torrent was paused we will resume seeding',
|
||||
)
|
||||
core.resume_torrent(client_agent, input_hash, input_id, input_name)
|
||||
nzb2media.resume_torrent(client_agent, input_hash, input_id, input_name)
|
||||
|
||||
else:
|
||||
if client_agent != 'manual':
|
||||
# update download status in our DB
|
||||
core.update_download_info_status(input_name, 1)
|
||||
nzb2media.update_download_info_status(input_name, 1)
|
||||
|
||||
# remove torrent
|
||||
if core.USE_LINK == 'move-sym' and not core.DELETE_ORIGINAL == 1:
|
||||
if nzb2media.USE_LINK == 'move-sym' and not nzb2media.DELETE_ORIGINAL == 1:
|
||||
logger.debug(f'Checking for sym-links to re-direct in: {input_directory}')
|
||||
for dirpath, _, files in os.walk(input_directory):
|
||||
for file in files:
|
||||
logger.debug(f'Checking symlink: {os.path.join(dirpath, file)}')
|
||||
replace_links(os.path.join(dirpath, file))
|
||||
core.remove_torrent(client_agent, input_hash, input_id, input_name)
|
||||
nzb2media.remove_torrent(client_agent, input_hash, input_id, input_name)
|
||||
|
||||
if section_name != 'UserScript':
|
||||
# for user script, we assume this is cleaned by the script or option USER_SCRIPT_CLEAN
|
||||
# cleanup our processing folders of any misc unwanted files and empty directories
|
||||
core.clean_dir(output_destination, section_name, input_category)
|
||||
nzb2media.clean_dir(output_destination, section_name, input_category)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def main(args):
|
||||
# Initialize the config
|
||||
core.initialize()
|
||||
nzb2media.initialize()
|
||||
|
||||
# clientAgent for Torrents
|
||||
client_agent = core.TORRENT_CLIENT_AGENT
|
||||
client_agent = nzb2media.TORRENT_CLIENT_AGENT
|
||||
|
||||
logger.info('#########################################################')
|
||||
logger.info(f'## ..::[{os.path.basename(__file__)}]::.. ##')
|
||||
|
@ -304,32 +304,32 @@ def main(args):
|
|||
)
|
||||
|
||||
try:
|
||||
input_directory, input_name, input_category, input_hash, input_id = core.parse_args(client_agent, args)
|
||||
input_directory, input_name, input_category, input_hash, input_id = nzb2media.parse_args(client_agent, args)
|
||||
except Exception:
|
||||
logger.error('There was a problem loading variables')
|
||||
return -1
|
||||
|
||||
if input_directory and input_name and input_hash and input_id:
|
||||
result = process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent)
|
||||
elif core.TORRENT_NO_MANUAL:
|
||||
elif nzb2media.TORRENT_NO_MANUAL:
|
||||
logger.warning('Invalid number of arguments received from client, and no_manual set')
|
||||
else:
|
||||
# Perform Manual Post-Processing
|
||||
logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...')
|
||||
|
||||
for section, subsections in core.SECTIONS.items():
|
||||
for section, subsections in nzb2media.SECTIONS.items():
|
||||
for subsection in subsections:
|
||||
if not core.CFG[section][subsection].isenabled():
|
||||
if not nzb2media.CFG[section][subsection].isenabled():
|
||||
continue
|
||||
for dir_name in core.get_dirs(section, subsection, link='hard'):
|
||||
for dir_name in nzb2media.get_dirs(section, subsection, link='hard'):
|
||||
logger.info(f'Starting manual run for {section}:{subsection} - Folder:{dir_name}')
|
||||
|
||||
logger.info(f'Checking database for download info for {os.path.basename(dir_name)} ...')
|
||||
core.DOWNLOAD_INFO = core.get_download_info(os.path.basename(dir_name), 0)
|
||||
if core.DOWNLOAD_INFO:
|
||||
client_agent = core.DOWNLOAD_INFO[0]['client_agent'] or 'manual'
|
||||
input_hash = core.DOWNLOAD_INFO[0]['input_hash'] or ''
|
||||
input_id = core.DOWNLOAD_INFO[0]['input_id'] or ''
|
||||
nzb2media.DOWNLOAD_INFO = nzb2media.get_download_info(os.path.basename(dir_name), 0)
|
||||
if nzb2media.DOWNLOAD_INFO:
|
||||
client_agent = nzb2media.DOWNLOAD_INFO[0]['client_agent'] or 'manual'
|
||||
input_hash = nzb2media.DOWNLOAD_INFO[0]['input_hash'] or ''
|
||||
input_id = nzb2media.DOWNLOAD_INFO[0]['input_id'] or ''
|
||||
logger.info(f'Found download info for {os.path.basename(dir_name)}, setting variables now ...')
|
||||
else:
|
||||
logger.info(f'Unable to locate download info for {os.path.basename(dir_name)}, continuing to try and process this release ...')
|
||||
|
@ -337,7 +337,7 @@ def main(args):
|
|||
input_hash = ''
|
||||
input_id = ''
|
||||
|
||||
if client_agent.lower() not in core.TORRENT_CLIENTS:
|
||||
if client_agent.lower() not in nzb2media.TORRENT_CLIENTS:
|
||||
continue
|
||||
|
||||
input_name = os.path.basename(dir_name)
|
||||
|
@ -354,7 +354,7 @@ def main(args):
|
|||
logger.info(f'The {args[0]} script completed successfully.')
|
||||
else:
|
||||
logger.error(f'A problem was reported in the {args[0]} script.')
|
||||
del core.MYAPP
|
||||
del nzb2media.MYAPP
|
||||
return result.status_code
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import sys
|
|||
sys.dont_write_bytecode = True
|
||||
|
||||
FOLDER_STRUCTURE = {
|
||||
'core': [
|
||||
'nzb2media': [
|
||||
'auto_process',
|
||||
'extractor',
|
||||
'plugins',
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from core.plugins.downloaders.nzb.configuration import configure_nzbs
|
||||
from core.plugins.downloaders.torrent.configuration import (
|
||||
configure_torrent_class,
|
||||
)
|
||||
from core.plugins.downloaders.torrent.configuration import configure_torrents
|
|
@ -1,20 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import core
|
||||
|
||||
|
||||
def configure_nzbs(config):
|
||||
nzb_config = config['Nzb']
|
||||
core.NZB_CLIENT_AGENT = nzb_config['clientAgent'] # sabnzbd
|
||||
core.NZB_DEFAULT_DIRECTORY = nzb_config['default_downloadDirectory']
|
||||
core.NZB_NO_MANUAL = int(nzb_config['no_manual'], 0)
|
||||
|
||||
configure_sabnzbd(nzb_config)
|
||||
|
||||
|
||||
def configure_sabnzbd(config):
|
||||
core.SABNZBD_HOST = config['sabnzbd_host']
|
||||
core.SABNZBD_PORT = int(
|
||||
config['sabnzbd_port'] or 8080,
|
||||
) # defaults to accommodate NzbGet
|
||||
core.SABNZBD_APIKEY = config['sabnzbd_apikey']
|
|
@ -1,102 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import core
|
||||
from core.plugins.downloaders.torrent.utils import create_torrent_class
|
||||
|
||||
|
||||
def configure_torrents(config):
|
||||
torrent_config = config['Torrent']
|
||||
core.TORRENT_CLIENT_AGENT = torrent_config[
|
||||
'clientAgent'
|
||||
] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent | synods | other
|
||||
core.OUTPUT_DIRECTORY = torrent_config[
|
||||
'outputDirectory'
|
||||
] # /abs/path/to/complete/
|
||||
core.TORRENT_DEFAULT_DIRECTORY = torrent_config[
|
||||
'default_downloadDirectory'
|
||||
]
|
||||
core.TORRENT_NO_MANUAL = int(torrent_config['no_manual'], 0)
|
||||
|
||||
configure_torrent_linking(torrent_config)
|
||||
configure_flattening(torrent_config)
|
||||
configure_torrent_deletion(torrent_config)
|
||||
configure_torrent_categories(torrent_config)
|
||||
configure_torrent_permissions(torrent_config)
|
||||
configure_torrent_resuming(torrent_config)
|
||||
configure_utorrent(torrent_config)
|
||||
configure_transmission(torrent_config)
|
||||
configure_deluge(torrent_config)
|
||||
configure_qbittorrent(torrent_config)
|
||||
configure_syno(torrent_config)
|
||||
|
||||
|
||||
def configure_torrent_linking(config):
|
||||
core.USE_LINK = config['useLink'] # no | hard | sym
|
||||
|
||||
|
||||
def configure_flattening(config):
|
||||
core.NOFLATTEN = config['noFlatten']
|
||||
if isinstance(core.NOFLATTEN, str):
|
||||
core.NOFLATTEN = core.NOFLATTEN.split(',')
|
||||
|
||||
|
||||
def configure_torrent_categories(config):
|
||||
core.CATEGORIES = config[
|
||||
'categories'
|
||||
] # music,music_videos,pictures,software
|
||||
if isinstance(core.CATEGORIES, str):
|
||||
core.CATEGORIES = core.CATEGORIES.split(',')
|
||||
|
||||
|
||||
def configure_torrent_resuming(config):
|
||||
core.TORRENT_RESUME_ON_FAILURE = int(config['resumeOnFailure'])
|
||||
core.TORRENT_RESUME = int(config['resume'])
|
||||
|
||||
|
||||
def configure_torrent_permissions(config):
|
||||
core.TORRENT_CHMOD_DIRECTORY = int(str(config['chmodDirectory']), 8)
|
||||
|
||||
|
||||
def configure_torrent_deletion(config):
|
||||
core.DELETE_ORIGINAL = int(config['deleteOriginal'])
|
||||
|
||||
|
||||
def configure_utorrent(config):
|
||||
core.UTORRENT_WEB_UI = config[
|
||||
'uTorrentWEBui'
|
||||
] # http://localhost:8090/gui/
|
||||
core.UTORRENT_USER = config['uTorrentUSR'] # mysecretusr
|
||||
core.UTORRENT_PASSWORD = config['uTorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_transmission(config):
|
||||
core.TRANSMISSION_HOST = config['TransmissionHost'] # localhost
|
||||
core.TRANSMISSION_PORT = int(config['TransmissionPort'])
|
||||
core.TRANSMISSION_USER = config['TransmissionUSR'] # mysecretusr
|
||||
core.TRANSMISSION_PASSWORD = config['TransmissionPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_syno(config):
|
||||
core.SYNO_HOST = config['synoHost'] # localhost
|
||||
core.SYNO_PORT = int(config['synoPort'])
|
||||
core.SYNO_USER = config['synoUSR'] # mysecretusr
|
||||
core.SYNO_PASSWORD = config['synoPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_deluge(config):
|
||||
core.DELUGE_HOST = config['DelugeHost'] # localhost
|
||||
core.DELUGE_PORT = int(config['DelugePort']) # 8084
|
||||
core.DELUGE_USER = config['DelugeUSR'] # mysecretusr
|
||||
core.DELUGE_PASSWORD = config['DelugePWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_qbittorrent(config):
|
||||
core.QBITTORRENT_HOST = config['qBittorrentHost'] # localhost
|
||||
core.QBITTORRENT_PORT = int(config['qBittorrentPort']) # 8080
|
||||
core.QBITTORRENT_USER = config['qBittorrentUSR'] # mysecretusr
|
||||
core.QBITTORRENT_PASSWORD = config['qBittorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_torrent_class():
|
||||
# create torrent class
|
||||
core.TORRENT_CLASS = create_torrent_class(core.TORRENT_CLIENT_AGENT)
|
|
@ -1,97 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
from .deluge import configure_client as deluge_client
|
||||
from .qbittorrent import configure_client as qbittorrent_client
|
||||
from .synology import configure_client as synology_client
|
||||
from .transmission import configure_client as transmission_client
|
||||
from .utorrent import configure_client as utorrent_client
|
||||
|
||||
torrent_clients = {
|
||||
'deluge': deluge_client,
|
||||
'qbittorrent': qbittorrent_client,
|
||||
'transmission': transmission_client,
|
||||
'utorrent': utorrent_client,
|
||||
'synods': synology_client,
|
||||
}
|
||||
|
||||
|
||||
def create_torrent_class(client_agent):
|
||||
if not core.APP_NAME == 'TorrentToMedia.py':
|
||||
return # Skip loading Torrent for NZBs.
|
||||
|
||||
client = torrent_clients.get(client_agent)
|
||||
if client:
|
||||
return client()
|
||||
|
||||
|
||||
def pause_torrent(client_agent, input_hash, input_id, input_name):
|
||||
logger.debug(
|
||||
f'Stopping torrent {input_name} in {client_agent} while processing',
|
||||
)
|
||||
try:
|
||||
if client_agent == 'utorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.stop(input_hash)
|
||||
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.stop_torrent(input_id)
|
||||
if client_agent == 'synods' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.pause_task(input_id)
|
||||
if client_agent == 'deluge' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.core.pause_torrent([input_id])
|
||||
if client_agent == 'qbittorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.pause(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
f'Failed to stop torrent {input_name} in {client_agent}',
|
||||
)
|
||||
|
||||
|
||||
def resume_torrent(client_agent, input_hash, input_id, input_name):
|
||||
if not core.TORRENT_RESUME == 1:
|
||||
return
|
||||
logger.debug(f'Starting torrent {input_name} in {client_agent}')
|
||||
try:
|
||||
if client_agent == 'utorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.start(input_hash)
|
||||
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.start_torrent(input_id)
|
||||
if client_agent == 'synods' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.resume_task(input_id)
|
||||
if client_agent == 'deluge' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.core.resume_torrent([input_id])
|
||||
if client_agent == 'qbittorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.resume(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
f'Failed to start torrent {input_name} in {client_agent}',
|
||||
)
|
||||
|
||||
|
||||
def remove_torrent(client_agent, input_hash, input_id, input_name):
|
||||
if core.DELETE_ORIGINAL == 1 or core.USE_LINK == 'move':
|
||||
logger.debug(f'Deleting torrent {input_name} from {client_agent}')
|
||||
try:
|
||||
if client_agent == 'utorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.removedata(input_hash)
|
||||
core.TORRENT_CLASS.remove(input_hash)
|
||||
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.remove_torrent(input_id, True)
|
||||
if client_agent == 'synods' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.delete_task(input_id)
|
||||
if client_agent == 'deluge' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.core.remove_torrent(input_id, True)
|
||||
if client_agent == 'qbittorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.delete_permanently(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
f'Failed to delete torrent {input_name} in {client_agent}',
|
||||
)
|
||||
else:
|
||||
resume_torrent(client_agent, input_hash, input_id, input_name)
|
|
@ -1,5 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from core.plugins.downloaders.torrent.utils import pause_torrent
|
||||
from core.plugins.downloaders.torrent.utils import remove_torrent
|
||||
from core.plugins.downloaders.torrent.utils import resume_torrent
|
|
@ -45,37 +45,37 @@ CONFIG_TV_FILE = APP_ROOT / 'autoProcessTv.cfg'
|
|||
TEST_FILE = APP_ROOT / 'tests' / 'test.mp4'
|
||||
MYAPP = None
|
||||
|
||||
from core import logger, main_db, version_check, databases, transcoder
|
||||
from core.configuration import config
|
||||
from core.plugins.downloaders.configuration import (
|
||||
from nzb2media import logger, main_db, version_check, databases, transcoder
|
||||
from nzb2media.configuration import config
|
||||
from nzb2media.plugins.downloaders.configuration import (
|
||||
configure_nzbs,
|
||||
configure_torrents,
|
||||
configure_torrent_class,
|
||||
)
|
||||
from core.plugins.downloaders.utils import (
|
||||
from nzb2media.plugins.downloaders.utils import (
|
||||
pause_torrent,
|
||||
remove_torrent,
|
||||
resume_torrent,
|
||||
)
|
||||
from core.plugins.plex import configure_plex
|
||||
from core.utils.processes import RunningProcess
|
||||
from core.utils.processes import restart
|
||||
from core.utils.files import copy_link
|
||||
from core.utils.files import extract_files
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.files import make_dir
|
||||
from core.utils.files import sanitize_name
|
||||
from core.utils.paths import rchmod
|
||||
from core.utils.paths import remove_dir
|
||||
from core.utils.paths import remove_read_only
|
||||
from core.utils.common import clean_dir
|
||||
from core.utils.common import flatten
|
||||
from core.utils.common import get_dirs
|
||||
from core.utils.download_info import get_download_info
|
||||
from core.utils.download_info import update_download_info_status
|
||||
from core.utils.parsers import parse_args
|
||||
from core.utils.network import wake_up
|
||||
from core.utils.identification import category_search
|
||||
from nzb2media.plugins.plex import configure_plex
|
||||
from nzb2media.utils.processes import RunningProcess
|
||||
from nzb2media.utils.processes import restart
|
||||
from nzb2media.utils.files import copy_link
|
||||
from nzb2media.utils.files import extract_files
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.files import make_dir
|
||||
from nzb2media.utils.files import sanitize_name
|
||||
from nzb2media.utils.paths import rchmod
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.utils.paths import remove_read_only
|
||||
from nzb2media.utils.common import clean_dir
|
||||
from nzb2media.utils.common import flatten
|
||||
from nzb2media.utils.common import get_dirs
|
||||
from nzb2media.utils.download_info import get_download_info
|
||||
from nzb2media.utils.download_info import update_download_info_status
|
||||
from nzb2media.utils.parsers import parse_args
|
||||
from nzb2media.utils.network import wake_up
|
||||
from nzb2media.utils.identification import category_search
|
||||
|
||||
|
||||
__version__ = '12.1.11'
|
||||
|
@ -1421,7 +1421,7 @@ def configure_utility_locations():
|
|||
FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg.exe')
|
||||
FFPROBE = os.path.join(FFMPEG_PATH, 'ffprobe.exe')
|
||||
SEVENZIP = os.path.join(
|
||||
APP_ROOT, 'core', 'extractor', 'bin', platform.machine(), '7z.exe',
|
||||
APP_ROOT, 'nzb2media', 'extractor', 'bin', platform.machine(), '7z.exe',
|
||||
)
|
||||
SHOWEXTRACT = int(str(CFG['Windows']['show_extraction']), 0)
|
||||
|
|
@ -11,25 +11,25 @@ import requests
|
|||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core import transcoder
|
||||
from core.auto_process.common import command_complete
|
||||
from core.auto_process.common import completed_download_handling
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.plugins.subtitles import rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils.encoding import convert_to_ascii
|
||||
from core.utils.network import find_download
|
||||
from core.utils.identification import find_imdbid
|
||||
from core.utils.common import flatten
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.paths import remote_dir
|
||||
from core.utils.paths import remove_dir
|
||||
from core.utils.network import server_responding
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media import transcoder
|
||||
from nzb2media.auto_process.common import command_complete
|
||||
from nzb2media.auto_process.common import completed_download_handling
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.auto_process.managers.sickbeard import InitSickBeard
|
||||
from nzb2media.plugins.downloaders.nzb.utils import report_nzb
|
||||
from nzb2media.plugins.subtitles import import_subs
|
||||
from nzb2media.plugins.subtitles import rename_subs
|
||||
from nzb2media.scene_exceptions import process_all_exceptions
|
||||
from nzb2media.utils.encoding import convert_to_ascii
|
||||
from nzb2media.utils.network import find_download
|
||||
from nzb2media.utils.identification import find_imdbid
|
||||
from nzb2media.utils.common import flatten
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.paths import remote_dir
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.utils.network import server_responding
|
||||
|
||||
|
||||
def process(
|
||||
|
@ -44,9 +44,9 @@ def process(
|
|||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
# Get configuration
|
||||
if core.CFG is None:
|
||||
if nzb2media.CFG is None:
|
||||
raise RuntimeError('Configuration not loaded.')
|
||||
cfg = core.CFG[section][input_category]
|
||||
cfg = nzb2media.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
|
@ -64,7 +64,7 @@ def process(
|
|||
# Misc
|
||||
|
||||
# Begin processing
|
||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||
url = nzb2media.utils.common.create_url(scheme, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult.failure(
|
|
@ -11,25 +11,25 @@ import requests
|
|||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core import transcoder
|
||||
from core.auto_process.common import command_complete
|
||||
from core.auto_process.common import completed_download_handling
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.plugins.subtitles import rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils.encoding import convert_to_ascii
|
||||
from core.utils.network import find_download
|
||||
from core.utils.identification import find_imdbid
|
||||
from core.utils.common import flatten
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.paths import remote_dir
|
||||
from core.utils.paths import remove_dir
|
||||
from core.utils.network import server_responding
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media import transcoder
|
||||
from nzb2media.auto_process.common import command_complete
|
||||
from nzb2media.auto_process.common import completed_download_handling
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.auto_process.managers.sickbeard import InitSickBeard
|
||||
from nzb2media.plugins.downloaders.nzb.utils import report_nzb
|
||||
from nzb2media.plugins.subtitles import import_subs
|
||||
from nzb2media.plugins.subtitles import rename_subs
|
||||
from nzb2media.scene_exceptions import process_all_exceptions
|
||||
from nzb2media.utils.encoding import convert_to_ascii
|
||||
from nzb2media.utils.network import find_download
|
||||
from nzb2media.utils.identification import find_imdbid
|
||||
from nzb2media.utils.common import flatten
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.paths import remote_dir
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.utils.network import server_responding
|
||||
|
||||
|
||||
def process(
|
||||
|
@ -44,9 +44,9 @@ def process(
|
|||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
# Get configuration
|
||||
if core.CFG is None:
|
||||
if nzb2media.CFG is None:
|
||||
raise RuntimeError('Configuration not loaded.')
|
||||
cfg = core.CFG[section][input_category]
|
||||
cfg = nzb2media.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
|
@ -66,7 +66,7 @@ def process(
|
|||
comicrn_version = '1.01'
|
||||
|
||||
# Begin processing
|
||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||
url = nzb2media.utils.common.create_url(scheme, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult.failure(
|
|
@ -4,7 +4,7 @@ import typing
|
|||
|
||||
import requests
|
||||
|
||||
from core import logger
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
class ProcessResult(typing.NamedTuple):
|
|
@ -11,25 +11,25 @@ import requests
|
|||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core import transcoder
|
||||
from core.auto_process.common import command_complete
|
||||
from core.auto_process.common import completed_download_handling
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.plugins.subtitles import rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils.encoding import convert_to_ascii
|
||||
from core.utils.network import find_download
|
||||
from core.utils.identification import find_imdbid
|
||||
from core.utils.common import flatten
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.paths import remote_dir
|
||||
from core.utils.paths import remove_dir
|
||||
from core.utils.network import server_responding
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media import transcoder
|
||||
from nzb2media.auto_process.common import command_complete
|
||||
from nzb2media.auto_process.common import completed_download_handling
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.auto_process.managers.sickbeard import InitSickBeard
|
||||
from nzb2media.plugins.downloaders.nzb.utils import report_nzb
|
||||
from nzb2media.plugins.subtitles import import_subs
|
||||
from nzb2media.plugins.subtitles import rename_subs
|
||||
from nzb2media.scene_exceptions import process_all_exceptions
|
||||
from nzb2media.utils.encoding import convert_to_ascii
|
||||
from nzb2media.utils.network import find_download
|
||||
from nzb2media.utils.identification import find_imdbid
|
||||
from nzb2media.utils.common import flatten
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.paths import remote_dir
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.utils.network import server_responding
|
||||
|
||||
|
||||
def process(
|
||||
|
@ -44,9 +44,9 @@ def process(
|
|||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
# Get configuration
|
||||
if core.CFG is None:
|
||||
if nzb2media.CFG is None:
|
||||
raise RuntimeError('Configuration not loaded.')
|
||||
cfg = core.CFG[section][input_category]
|
||||
cfg = nzb2media.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
|
@ -64,7 +64,7 @@ def process(
|
|||
library = cfg.get('library')
|
||||
|
||||
# Begin processing
|
||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||
url = nzb2media.utils.common.create_url(scheme, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult.failure(
|
|
@ -4,10 +4,10 @@ import time
|
|||
|
||||
import requests
|
||||
|
||||
import core.utils.common
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.auto_process.managers.sickbeard import SickBeard
|
||||
import nzb2media.utils.common
|
||||
from nzb2media import logger
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.auto_process.managers.sickbeard import SickBeard
|
||||
|
||||
|
||||
class PyMedusa(SickBeard):
|
||||
|
@ -16,7 +16,7 @@ class PyMedusa(SickBeard):
|
|||
@property
|
||||
def url(self):
|
||||
route = f'{self.sb_init.web_root}/home/postprocess/processEpisode'
|
||||
return core.utils.common.create_url(
|
||||
return nzb2media.utils.common.create_url(
|
||||
self.sb_init.protocol,
|
||||
self.sb_init.host,
|
||||
self.sb_init.port,
|
||||
|
@ -30,7 +30,7 @@ class PyMedusaApiV1(SickBeard):
|
|||
@property
|
||||
def url(self) -> str:
|
||||
route = f'{self.sb_init.web_root}/api/{self.sb_init.apikey}/'
|
||||
return core.utils.common.create_url(
|
||||
return nzb2media.utils.common.create_url(
|
||||
self.sb_init.protocol,
|
||||
self.sb_init.host,
|
||||
self.sb_init.port,
|
||||
|
@ -108,7 +108,7 @@ class PyMedusaApiV2(SickBeard):
|
|||
@property
|
||||
def url(self):
|
||||
route = f'{self.sb_init.web_root}/api/v2/postprocess'
|
||||
return core.utils.common.create_url(
|
||||
return nzb2media.utils.common.create_url(
|
||||
self.sb_init.protocol,
|
||||
self.sb_init.host,
|
||||
self.sb_init.port,
|
|
@ -6,12 +6,12 @@ import requests
|
|||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import (
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media.auto_process.common import (
|
||||
ProcessResult,
|
||||
)
|
||||
from core.utils.paths import remote_dir
|
||||
from nzb2media.utils.paths import remote_dir
|
||||
|
||||
|
||||
class InitSickBeard:
|
||||
|
@ -53,7 +53,7 @@ class InitSickBeard:
|
|||
_val = cfg.get('fork', 'auto')
|
||||
f1 = replace.get(_val, _val)
|
||||
try:
|
||||
self.fork = f1, core.FORKS[f1]
|
||||
self.fork = f1, nzb2media.FORKS[f1]
|
||||
except KeyError:
|
||||
self.fork = 'auto'
|
||||
self.protocol = 'https://' if self.ssl else 'http://'
|
||||
|
@ -61,15 +61,15 @@ class InitSickBeard:
|
|||
def auto_fork(self):
|
||||
# auto-detect correct section
|
||||
# config settings
|
||||
if core.FORK_SET:
|
||||
if nzb2media.FORK_SET:
|
||||
# keep using determined fork for multiple (manual) post-processing
|
||||
logger.info(
|
||||
f'{self.section}:{self.input_category} fork already set to '
|
||||
f'{core.FORK_SET[0]}',
|
||||
f'{nzb2media.FORK_SET[0]}',
|
||||
)
|
||||
return core.FORK_SET[0], core.FORK_SET[1]
|
||||
return nzb2media.FORK_SET[0], nzb2media.FORK_SET[1]
|
||||
|
||||
cfg = dict(core.CFG[self.section][self.input_category])
|
||||
cfg = dict(nzb2media.CFG[self.section][self.input_category])
|
||||
|
||||
replace = {
|
||||
'medusa': 'Medusa',
|
||||
|
@ -84,14 +84,14 @@ class InitSickBeard:
|
|||
_val = cfg.get('fork', 'auto')
|
||||
f1 = replace.get(_val.lower(), _val)
|
||||
try:
|
||||
self.fork = f1, core.FORKS[f1]
|
||||
self.fork = f1, nzb2media.FORKS[f1]
|
||||
except KeyError:
|
||||
self.fork = 'auto'
|
||||
protocol = 'https://' if self.ssl else 'http://'
|
||||
|
||||
if self.section == 'NzbDrone':
|
||||
logger.info(f'Attempting to verify {self.input_category} fork')
|
||||
url = core.utils.common.create_url(
|
||||
url = nzb2media.utils.common.create_url(
|
||||
scheme=protocol,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
|
@ -123,7 +123,7 @@ class InitSickBeard:
|
|||
logger.info(f'Attempting to verify {self.input_category} fork')
|
||||
|
||||
if self.api_version >= 2:
|
||||
url = core.utils.common.create_url(
|
||||
url = nzb2media.utils.common.create_url(
|
||||
scheme=protocol,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
|
@ -132,7 +132,7 @@ class InitSickBeard:
|
|||
api_params = {}
|
||||
else:
|
||||
api_version = f'v{self.api_version}'
|
||||
url = core.utils.common.create_url(
|
||||
url = nzb2media.utils.common.create_url(
|
||||
scheme=protocol,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
|
@ -148,12 +148,12 @@ class InitSickBeard:
|
|||
):
|
||||
oauth = OAuth2Session(
|
||||
client=LegacyApplicationClient(
|
||||
client_id=core.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
client_id=nzb2media.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
),
|
||||
)
|
||||
oauth_token = oauth.fetch_token(
|
||||
client_id=core.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
token_url=core.SICKRAGE_OAUTH_TOKEN_URL,
|
||||
client_id=nzb2media.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
token_url=nzb2media.SICKRAGE_OAUTH_TOKEN_URL,
|
||||
username=self.sso_username,
|
||||
password=self.sso_password,
|
||||
)
|
||||
|
@ -203,7 +203,7 @@ class InitSickBeard:
|
|||
logger.info(
|
||||
f'{self.section}:{self.input_category} fork set to {self.fork[0]}',
|
||||
)
|
||||
core.FORK_SET = self.fork
|
||||
nzb2media.FORK_SET = self.fork
|
||||
self.fork, self.fork_params = self.fork[0], self.fork[1]
|
||||
# This will create the fork object, and attach to self.fork_obj.
|
||||
self._init_fork()
|
||||
|
@ -246,7 +246,7 @@ class InitSickBeard:
|
|||
def detect_fork(self):
|
||||
"""Try to detect a specific fork."""
|
||||
detected = False
|
||||
params = core.ALL_FORKS
|
||||
params = nzb2media.ALL_FORKS
|
||||
rem_params = []
|
||||
logger.info(f'Attempting to auto-detect {self.input_category} fork')
|
||||
# Define the order to test.
|
||||
|
@ -254,7 +254,7 @@ class InitSickBeard:
|
|||
# Then in order of most unique parameters.
|
||||
|
||||
if self.apikey:
|
||||
url = core.utils.common.create_url(
|
||||
url = nzb2media.utils.common.create_url(
|
||||
scheme=self.protocol,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
|
@ -262,7 +262,7 @@ class InitSickBeard:
|
|||
)
|
||||
api_params = {'cmd': 'sg.postprocess', 'help': '1'}
|
||||
else:
|
||||
url = core.utils.common.create_url(
|
||||
url = nzb2media.utils.common.create_url(
|
||||
scheme=self.protocol,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
|
@ -275,7 +275,7 @@ class InitSickBeard:
|
|||
s = requests.Session()
|
||||
|
||||
if not self.apikey and self.username and self.password:
|
||||
login = core.utils.common.create_url(
|
||||
login = nzb2media.utils.common.create_url(
|
||||
scheme=self.protocol,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
|
@ -339,7 +339,7 @@ class InitSickBeard:
|
|||
for param in rem_params:
|
||||
params.pop(param)
|
||||
|
||||
for fork in sorted(core.FORKS, reverse=False):
|
||||
for fork in sorted(nzb2media.FORKS, reverse=False):
|
||||
if params == fork[1]:
|
||||
detected = True
|
||||
break
|
||||
|
@ -361,8 +361,8 @@ class InitSickBeard:
|
|||
f'{self.section}:{self.input_category} fork auto-detection '
|
||||
f'failed',
|
||||
)
|
||||
self.fork = list(core.FORKS.items())[
|
||||
list(core.FORKS.keys()).index(core.FORK_DEFAULT)
|
||||
self.fork = list(nzb2media.FORKS.items())[
|
||||
list(nzb2media.FORKS.keys()).index(nzb2media.FORK_DEFAULT)
|
||||
]
|
||||
|
||||
def _init_fork(self):
|
||||
|
@ -434,13 +434,13 @@ class SickBeard:
|
|||
self.input_name = input_name
|
||||
self.failed = failed
|
||||
self.status = int(self.failed)
|
||||
if self.status > 0 and core.NOEXTRACTFAILED:
|
||||
if self.status > 0 and nzb2media.NOEXTRACTFAILED:
|
||||
self.extract = 0
|
||||
else:
|
||||
self.extract = int(self.sb_init.config.get('extract', 0))
|
||||
if (
|
||||
client_agent == core.TORRENT_CLIENT_AGENT
|
||||
and core.USE_LINK == 'move-sym'
|
||||
client_agent == nzb2media.TORRENT_CLIENT_AGENT
|
||||
and nzb2media.USE_LINK == 'move-sym'
|
||||
):
|
||||
self.process_method = 'symlink'
|
||||
|
||||
|
@ -450,7 +450,7 @@ class SickBeard:
|
|||
route = f'{self.sb_init.web_root}/api/{self.sb_init.apikey}/'
|
||||
else:
|
||||
route = f'{self.sb_init.web_root}/home/postprocess/processEpisode'
|
||||
return core.utils.common.create_url(
|
||||
return nzb2media.utils.common.create_url(
|
||||
scheme=self.sb_init.protocol,
|
||||
host=self.sb_init.host,
|
||||
port=self.sb_init.port,
|
||||
|
@ -552,7 +552,7 @@ class SickBeard:
|
|||
):
|
||||
# If not using the api, we need to login using user/pass first.
|
||||
route = f'{self.sb_init.web_root}/login'
|
||||
login = core.utils.common.create_url(
|
||||
login = nzb2media.utils.common.create_url(
|
||||
self.sb_init.protocol,
|
||||
self.sb_init.host,
|
||||
self.sb_init.port,
|
|
@ -11,25 +11,25 @@ import requests
|
|||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core import transcoder
|
||||
from core.auto_process.common import command_complete
|
||||
from core.auto_process.common import completed_download_handling
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.plugins.subtitles import rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils.encoding import convert_to_ascii
|
||||
from core.utils.network import find_download
|
||||
from core.utils.identification import find_imdbid
|
||||
from core.utils.common import flatten
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.paths import remote_dir
|
||||
from core.utils.paths import remove_dir
|
||||
from core.utils.network import server_responding
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media import transcoder
|
||||
from nzb2media.auto_process.common import command_complete
|
||||
from nzb2media.auto_process.common import completed_download_handling
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.auto_process.managers.sickbeard import InitSickBeard
|
||||
from nzb2media.plugins.downloaders.nzb.utils import report_nzb
|
||||
from nzb2media.plugins.subtitles import import_subs
|
||||
from nzb2media.plugins.subtitles import rename_subs
|
||||
from nzb2media.scene_exceptions import process_all_exceptions
|
||||
from nzb2media.utils.encoding import convert_to_ascii
|
||||
from nzb2media.utils.network import find_download
|
||||
from nzb2media.utils.identification import find_imdbid
|
||||
from nzb2media.utils.common import flatten
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.paths import remote_dir
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.utils.network import server_responding
|
||||
|
||||
|
||||
def process(
|
||||
|
@ -44,9 +44,9 @@ def process(
|
|||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
# Get configuration
|
||||
if core.CFG is None:
|
||||
if nzb2media.CFG is None:
|
||||
raise RuntimeError('Configuration not loaded.')
|
||||
cfg = core.CFG[section][input_category]
|
||||
cfg = nzb2media.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
|
@ -65,7 +65,7 @@ def process(
|
|||
wait_for = int(cfg.get('wait_for', 2))
|
||||
|
||||
# Misc
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
if status > 0 and nzb2media.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get('extract', 0))
|
||||
|
@ -85,13 +85,13 @@ def process(
|
|||
elif section == 'Radarr':
|
||||
route = f'{web_root}/api/v3/command'
|
||||
route2 = f'{web_root}/api/v3/config/downloadClient'
|
||||
url2 = core.utils.common.create_url(scheme, host, port, route2)
|
||||
url2 = nzb2media.utils.common.create_url(scheme, host, port, route2)
|
||||
headers = {'X-Api-Key': apikey, 'Content-Type': 'application/json'}
|
||||
elif section == 'Watcher3':
|
||||
route = f'{web_root}/postprocessing'
|
||||
else:
|
||||
route = web_root
|
||||
base_url = core.utils.common.create_url(scheme, host, port, route)
|
||||
base_url = nzb2media.utils.common.create_url(scheme, host, port, route)
|
||||
if not apikey:
|
||||
logger.info(
|
||||
'No CouchPotato or Radarr apikey entered. Performing transcoder functions only',
|
||||
|
@ -150,7 +150,7 @@ def process(
|
|||
logger.debug(
|
||||
f'Checking for archives to extract in directory: {dir_name}',
|
||||
)
|
||||
core.extract_files(dir_name)
|
||||
nzb2media.extract_files(dir_name)
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
|
||||
good_files = 0
|
||||
|
@ -163,8 +163,8 @@ def process(
|
|||
num_files += 1
|
||||
if transcoder.is_video_good(video, status):
|
||||
good_files += 1
|
||||
if not core.REQUIRE_LAN or transcoder.is_video_good(
|
||||
video, status, require_lan=core.REQUIRE_LAN,
|
||||
if not nzb2media.REQUIRE_LAN or transcoder.is_video_good(
|
||||
video, status, require_lan=nzb2media.REQUIRE_LAN,
|
||||
):
|
||||
valid_files += 1
|
||||
import_subs(video)
|
||||
|
@ -189,7 +189,7 @@ def process(
|
|||
print('[NZB] MARK=BAD')
|
||||
if good_files == num_files:
|
||||
logger.debug(
|
||||
f'Video marked as failed due to missing required language: {core.REQUIRE_LAN}',
|
||||
f'Video marked as failed due to missing required language: {nzb2media.REQUIRE_LAN}',
|
||||
section,
|
||||
)
|
||||
else:
|
||||
|
@ -223,7 +223,7 @@ def process(
|
|||
print('[NZB] MARK=BAD')
|
||||
|
||||
if status == 0:
|
||||
if core.TRANSCODE == 1:
|
||||
if nzb2media.TRANSCODE == 1:
|
||||
result, new_dir_name = transcoder.transcode_directory(dir_name)
|
||||
if result == 0:
|
||||
logger.debug(
|
||||
|
@ -240,7 +240,7 @@ def process(
|
|||
f'Attempting to set the octal permission of \'{oct(chmod_directory)}\' on directory \'{dir_name}\'',
|
||||
section,
|
||||
)
|
||||
core.rchmod(dir_name, chmod_directory)
|
||||
nzb2media.rchmod(dir_name, chmod_directory)
|
||||
else:
|
||||
logger.error(
|
||||
f'Transcoding failed for files in {dir_name}', section,
|
||||
|
@ -256,8 +256,8 @@ def process(
|
|||
video_name, video_ext = os.path.splitext(video)
|
||||
video2 = f'{video_name}.cp({imdbid}){video_ext}'
|
||||
if not (
|
||||
client_agent in [core.TORRENT_CLIENT_AGENT, 'manual']
|
||||
and core.USE_LINK == 'move-sym'
|
||||
client_agent in [nzb2media.TORRENT_CLIENT_AGENT, 'manual']
|
||||
and nzb2media.USE_LINK == 'move-sym'
|
||||
):
|
||||
logger.debug(f'Renaming: {video} to: {video2}')
|
||||
os.rename(video, video2)
|
||||
|
@ -408,7 +408,7 @@ def process(
|
|||
status_code=1,
|
||||
)
|
||||
else:
|
||||
core.FAILED = True
|
||||
nzb2media.FAILED = True
|
||||
logger.postprocess(
|
||||
f'FAILED DOWNLOAD DETECTED FOR {input_name}', section,
|
||||
)
|
|
@ -11,25 +11,25 @@ import requests
|
|||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core import transcoder
|
||||
from core.auto_process.common import command_complete
|
||||
from core.auto_process.common import completed_download_handling
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.plugins.subtitles import rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils.encoding import convert_to_ascii
|
||||
from core.utils.network import find_download
|
||||
from core.utils.identification import find_imdbid
|
||||
from core.utils.common import flatten
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.paths import remote_dir
|
||||
from core.utils.paths import remove_dir
|
||||
from core.utils.network import server_responding
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media import transcoder
|
||||
from nzb2media.auto_process.common import command_complete
|
||||
from nzb2media.auto_process.common import completed_download_handling
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.auto_process.managers.sickbeard import InitSickBeard
|
||||
from nzb2media.plugins.downloaders.nzb.utils import report_nzb
|
||||
from nzb2media.plugins.subtitles import import_subs
|
||||
from nzb2media.plugins.subtitles import rename_subs
|
||||
from nzb2media.scene_exceptions import process_all_exceptions
|
||||
from nzb2media.utils.encoding import convert_to_ascii
|
||||
from nzb2media.utils.network import find_download
|
||||
from nzb2media.utils.identification import find_imdbid
|
||||
from nzb2media.utils.common import flatten
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.paths import remote_dir
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.utils.network import server_responding
|
||||
|
||||
|
||||
def process(
|
||||
|
@ -44,9 +44,9 @@ def process(
|
|||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
# Get configuration
|
||||
if core.CFG is None:
|
||||
if nzb2media.CFG is None:
|
||||
raise RuntimeError('Configuration not loaded.')
|
||||
cfg = core.CFG[section][input_category]
|
||||
cfg = nzb2media.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
|
@ -64,14 +64,14 @@ def process(
|
|||
wait_for = int(cfg.get('wait_for', 2))
|
||||
|
||||
# Misc
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
if status > 0 and nzb2media.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get('extract', 0))
|
||||
|
||||
# Begin processing
|
||||
route = f'{web_root}/api/v1' if section == 'Lidarr' else f'{web_root}/api'
|
||||
url = core.utils.common.create_url(scheme, host, port, route)
|
||||
url = nzb2media.utils.common.create_url(scheme, host, port, route)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult.failure(
|
||||
|
@ -105,7 +105,7 @@ def process(
|
|||
logger.debug(
|
||||
f'Checking for archives to extract in directory: {dir_name}',
|
||||
)
|
||||
core.extract_files(dir_name)
|
||||
nzb2media.extract_files(dir_name)
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
|
||||
# if listMediaFiles(dir_name, media=False, audio=True, meta=False, archives=False) and status:
|
||||
|
@ -151,7 +151,7 @@ def process(
|
|||
|
||||
elif status == 0 and section == 'Lidarr':
|
||||
route = f'{web_root}/api/v1/command'
|
||||
url = core.utils.common.create_url(scheme, host, port, route)
|
||||
url = nzb2media.utils.common.create_url(scheme, host, port, route)
|
||||
headers = {'X-Api-Key': apikey}
|
||||
if remote_path:
|
||||
logger.debug(f'remote_path: {remote_dir(dir_name)}', section)
|
|
@ -11,25 +11,25 @@ import requests
|
|||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core import transcoder
|
||||
from core.auto_process.common import command_complete
|
||||
from core.auto_process.common import completed_download_handling
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.plugins.subtitles import rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils.encoding import convert_to_ascii
|
||||
from core.utils.network import find_download
|
||||
from core.utils.identification import find_imdbid
|
||||
from core.utils.common import flatten
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.paths import remote_dir
|
||||
from core.utils.paths import remove_dir
|
||||
from core.utils.network import server_responding
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media import transcoder
|
||||
from nzb2media.auto_process.common import command_complete
|
||||
from nzb2media.auto_process.common import completed_download_handling
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.auto_process.managers.sickbeard import InitSickBeard
|
||||
from nzb2media.plugins.downloaders.nzb.utils import report_nzb
|
||||
from nzb2media.plugins.subtitles import import_subs
|
||||
from nzb2media.plugins.subtitles import rename_subs
|
||||
from nzb2media.scene_exceptions import process_all_exceptions
|
||||
from nzb2media.utils.encoding import convert_to_ascii
|
||||
from nzb2media.utils.network import find_download
|
||||
from nzb2media.utils.identification import find_imdbid
|
||||
from nzb2media.utils.common import flatten
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.paths import remote_dir
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.utils.network import server_responding
|
||||
|
||||
|
||||
def process(
|
||||
|
@ -44,9 +44,9 @@ def process(
|
|||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
# Get configuration
|
||||
if core.CFG is None:
|
||||
if nzb2media.CFG is None:
|
||||
raise RuntimeError('Configuration not loaded.')
|
||||
cfg = core.CFG[section][input_category]
|
||||
cfg = nzb2media.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
|
@ -69,7 +69,7 @@ def process(
|
|||
wait_for = int(cfg.get('wait_for', 2))
|
||||
|
||||
# Misc
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
if status > 0 and nzb2media.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get('extract', 0))
|
||||
|
@ -87,7 +87,7 @@ def process(
|
|||
# For now let's do botch the OO and the serialized code, until everything has been migrated.
|
||||
init_sickbeard = InitSickBeard(cfg, section, input_category)
|
||||
|
||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||
url = nzb2media.utils.common.create_url(scheme, host, port, web_root)
|
||||
if server_responding(url):
|
||||
# auto-detect correct fork
|
||||
# During reactor we also return fork, fork_params. But these are also stored in the object.
|
||||
|
@ -105,8 +105,8 @@ def process(
|
|||
)
|
||||
|
||||
if (
|
||||
client_agent == core.TORRENT_CLIENT_AGENT
|
||||
and core.USE_LINK == 'move-sym'
|
||||
client_agent == nzb2media.TORRENT_CLIENT_AGENT
|
||||
and nzb2media.USE_LINK == 'move-sym'
|
||||
):
|
||||
process_method = 'symlink'
|
||||
if not os.path.isdir(dir_name) and os.path.isfile(
|
||||
|
@ -157,7 +157,7 @@ def process(
|
|||
logger.debug(
|
||||
f'Checking for archives to extract in directory: {dir_name}',
|
||||
)
|
||||
core.extract_files(dir_name)
|
||||
nzb2media.extract_files(dir_name)
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
|
||||
if list_media_files(
|
||||
|
@ -175,8 +175,8 @@ def process(
|
|||
num_files += 1
|
||||
if transcoder.is_video_good(video, status):
|
||||
good_files += 1
|
||||
if not core.REQUIRE_LAN or transcoder.is_video_good(
|
||||
video, status, require_lan=core.REQUIRE_LAN,
|
||||
if not nzb2media.REQUIRE_LAN or transcoder.is_video_good(
|
||||
video, status, require_lan=nzb2media.REQUIRE_LAN,
|
||||
):
|
||||
valid_files += 1
|
||||
import_subs(video)
|
||||
|
@ -195,7 +195,7 @@ def process(
|
|||
print('[NZB] MARK=BAD')
|
||||
if good_files == num_files:
|
||||
logger.debug(
|
||||
f'Video marked as failed due to missing required language: {core.REQUIRE_LAN}',
|
||||
f'Video marked as failed due to missing required language: {nzb2media.REQUIRE_LAN}',
|
||||
section,
|
||||
)
|
||||
else:
|
||||
|
@ -238,7 +238,7 @@ def process(
|
|||
print('[NZB] MARK=BAD')
|
||||
|
||||
if (
|
||||
status == 0 and core.TRANSCODE == 1
|
||||
status == 0 and nzb2media.TRANSCODE == 1
|
||||
): # only transcode successful downloads
|
||||
result, new_dir_name = transcoder.transcode_directory(dir_name)
|
||||
if result == 0:
|
||||
|
@ -257,7 +257,7 @@ def process(
|
|||
f'Attempting to set the octal permission of \'{oct(chmod_directory)}\' on directory \'{dir_name}\'',
|
||||
section,
|
||||
)
|
||||
core.rchmod(dir_name, chmod_directory)
|
||||
nzb2media.rchmod(dir_name, chmod_directory)
|
||||
else:
|
||||
logger.error(
|
||||
f'FAILED: Transcoding failed for files in {dir_name}', section,
|
||||
|
@ -356,7 +356,7 @@ def process(
|
|||
section,
|
||||
)
|
||||
else:
|
||||
core.FAILED = True
|
||||
nzb2media.FAILED = True
|
||||
if failure_link:
|
||||
report_nzb(failure_link, client_agent)
|
||||
if 'failed' in fork_params:
|
||||
|
@ -431,7 +431,7 @@ def process(
|
|||
}
|
||||
if not download_id:
|
||||
data.pop('downloadClientId')
|
||||
url = core.utils.common.create_url(scheme, host, port, route)
|
||||
url = nzb2media.utils.common.create_url(scheme, host, port, route)
|
||||
try:
|
||||
if section == 'SickBeard':
|
||||
if init_sickbeard.fork_obj:
|
||||
|
@ -469,12 +469,12 @@ def process(
|
|||
if api_version >= 2 and sso_username and sso_password:
|
||||
oauth = OAuth2Session(
|
||||
client=LegacyApplicationClient(
|
||||
client_id=core.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
client_id=nzb2media.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
),
|
||||
)
|
||||
oauth_token = oauth.fetch_token(
|
||||
client_id=core.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
token_url=core.SICKRAGE_OAUTH_TOKEN_URL,
|
||||
client_id=nzb2media.SICKRAGE_OAUTH_CLIENT_ID,
|
||||
token_url=nzb2media.SICKRAGE_OAUTH_TOKEN_URL,
|
||||
username=sso_username,
|
||||
password=sso_password,
|
||||
)
|
||||
|
@ -628,7 +628,7 @@ def process(
|
|||
# f'{section}: Failed to post-process {input_name}'
|
||||
# )
|
||||
|
||||
url2 = core.utils.common.create_url(scheme, host, port, route)
|
||||
url2 = nzb2media.utils.common.create_url(scheme, host, port, route)
|
||||
if completed_download_handling(url2, headers, section=section):
|
||||
logger.debug(
|
||||
f'The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {section}.',
|
|
@ -7,8 +7,8 @@ from itertools import chain
|
|||
|
||||
import configobj
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
class Section(configobj.Section):
|
||||
|
@ -92,7 +92,7 @@ class Section(configobj.Section):
|
|||
class ConfigObj(configobj.ConfigObj, Section):
|
||||
def __init__(self, infile=None, *args, **kw):
|
||||
if infile is None:
|
||||
infile = core.CONFIG_FILE
|
||||
infile = nzb2media.CONFIG_FILE
|
||||
super().__init__(os.fspath(infile), *args, **kw)
|
||||
self.interpolation = False
|
||||
|
||||
|
@ -115,17 +115,17 @@ class ConfigObj(configobj.ConfigObj, Section):
|
|||
|
||||
try:
|
||||
# check for autoProcessMedia.cfg and create if it does not exist
|
||||
if not core.CONFIG_FILE.is_file():
|
||||
shutil.copyfile(core.CONFIG_SPEC_FILE, core.CONFIG_FILE)
|
||||
CFG_OLD = config(core.CONFIG_FILE)
|
||||
if not nzb2media.CONFIG_FILE.is_file():
|
||||
shutil.copyfile(nzb2media.CONFIG_SPEC_FILE, nzb2media.CONFIG_FILE)
|
||||
CFG_OLD = config(nzb2media.CONFIG_FILE)
|
||||
except Exception as error:
|
||||
logger.error(f'Error {error} when copying to .cfg')
|
||||
|
||||
try:
|
||||
# check for autoProcessMedia.cfg.spec and create if it does not exist
|
||||
if not core.CONFIG_SPEC_FILE.is_file():
|
||||
shutil.copyfile(core.CONFIG_FILE, core.CONFIG_SPEC_FILE)
|
||||
CFG_NEW = config(core.CONFIG_SPEC_FILE)
|
||||
if not nzb2media.CONFIG_SPEC_FILE.is_file():
|
||||
shutil.copyfile(nzb2media.CONFIG_FILE, nzb2media.CONFIG_SPEC_FILE)
|
||||
CFG_NEW = config(nzb2media.CONFIG_SPEC_FILE)
|
||||
except Exception as error:
|
||||
logger.error(f'Error {error} when copying to .spec')
|
||||
|
||||
|
@ -291,11 +291,11 @@ class ConfigObj(configobj.ConfigObj, Section):
|
|||
CFG_NEW['SickBeard']['tv']['fork'] = 'auto'
|
||||
|
||||
# create a backup of our old config
|
||||
CFG_OLD.filename = f'{core.CONFIG_FILE}.old'
|
||||
CFG_OLD.filename = f'{nzb2media.CONFIG_FILE}.old'
|
||||
CFG_OLD.write()
|
||||
|
||||
# write our new config to autoProcessMedia.cfg
|
||||
CFG_NEW.filename = core.CONFIG_FILE
|
||||
CFG_NEW.filename = nzb2media.CONFIG_FILE
|
||||
CFG_NEW.write()
|
||||
|
||||
return True
|
||||
|
@ -1123,7 +1123,7 @@ class ConfigObj(configobj.ConfigObj, Section):
|
|||
|
||||
try:
|
||||
# write our new config to autoProcessMedia.cfg
|
||||
cfg_new.filename = core.CONFIG_FILE
|
||||
cfg_new.filename = nzb2media.CONFIG_FILE
|
||||
cfg_new.write()
|
||||
except Exception as error:
|
||||
logger.debug(f'Error {error} when writing changes to .cfg')
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from core import logger
|
||||
from core import main_db
|
||||
from core.utils.files import backup_versioned_file
|
||||
from nzb2media import logger
|
||||
from nzb2media import main_db
|
||||
from nzb2media.utils.files import backup_versioned_file
|
||||
|
||||
MIN_DB_VERSION = 1 # oldest db version we support migrating from
|
||||
MAX_DB_VERSION = 2
|
|
@ -9,27 +9,27 @@ from subprocess import call
|
|||
from subprocess import Popen
|
||||
from time import sleep
|
||||
|
||||
import core
|
||||
import nzb2media
|
||||
|
||||
|
||||
def extract(file_path, output_destination):
|
||||
success = 0
|
||||
# Using Windows
|
||||
if platform.system() == 'Windows':
|
||||
if not os.path.exists(core.SEVENZIP):
|
||||
core.logger.error('EXTRACTOR: Could not find 7-zip, Exiting')
|
||||
if not os.path.exists(nzb2media.SEVENZIP):
|
||||
nzb2media.logger.error('EXTRACTOR: Could not find 7-zip, Exiting')
|
||||
return False
|
||||
wscriptlocation = os.path.join(
|
||||
os.environ['WINDIR'], 'system32', 'wscript.exe',
|
||||
)
|
||||
invislocation = os.path.join(
|
||||
core.APP_ROOT, 'core', 'extractor', 'bin', 'invisible.vbs',
|
||||
nzb2media.APP_ROOT, 'nzb2media', 'extractor', 'bin', 'invisible.vbs',
|
||||
)
|
||||
cmd_7zip = [
|
||||
wscriptlocation,
|
||||
invislocation,
|
||||
str(core.SHOWEXTRACT),
|
||||
core.SEVENZIP,
|
||||
str(nzb2media.SHOWEXTRACT),
|
||||
nzb2media.SEVENZIP,
|
||||
'x',
|
||||
'-y',
|
||||
]
|
||||
|
@ -109,18 +109,18 @@ def extract(file_path, output_destination):
|
|||
): # we do have '7za'
|
||||
extract_commands[k] = ['7za', 'x', '-y']
|
||||
else:
|
||||
core.logger.error(
|
||||
nzb2media.logger.error(
|
||||
f'EXTRACTOR: {cmd} not found, disabling support for {k}',
|
||||
)
|
||||
del extract_commands[k]
|
||||
devnull.close()
|
||||
else:
|
||||
core.logger.warning(
|
||||
nzb2media.logger.warning(
|
||||
'EXTRACTOR: Cannot determine which tool to use when called from Transmission',
|
||||
)
|
||||
|
||||
if not extract_commands:
|
||||
core.logger.warning(
|
||||
nzb2media.logger.warning(
|
||||
'EXTRACTOR: No archive extracting programs found, plugin will be disabled',
|
||||
)
|
||||
|
||||
|
@ -150,24 +150,24 @@ def extract(file_path, output_destination):
|
|||
if ext[1] in extract_commands:
|
||||
cmd = extract_commands[ext[1]]
|
||||
else:
|
||||
core.logger.debug(f'EXTRACTOR: Unknown file type: {ext[1]}')
|
||||
nzb2media.logger.debug(f'EXTRACTOR: Unknown file type: {ext[1]}')
|
||||
return False
|
||||
|
||||
# Create outputDestination folder
|
||||
core.make_dir(output_destination)
|
||||
nzb2media.make_dir(output_destination)
|
||||
|
||||
if core.PASSWORDS_FILE and os.path.isfile(
|
||||
os.path.normpath(core.PASSWORDS_FILE),
|
||||
if nzb2media.PASSWORDS_FILE and os.path.isfile(
|
||||
os.path.normpath(nzb2media.PASSWORDS_FILE),
|
||||
):
|
||||
passwords = [
|
||||
line.strip()
|
||||
for line in open(os.path.normpath(core.PASSWORDS_FILE))
|
||||
for line in open(os.path.normpath(nzb2media.PASSWORDS_FILE))
|
||||
]
|
||||
else:
|
||||
passwords = []
|
||||
|
||||
core.logger.info(f'Extracting {file_path} to {output_destination}')
|
||||
core.logger.debug(f'Extracting {cmd} {file_path} {output_destination}')
|
||||
nzb2media.logger.info(f'Extracting {file_path} to {output_destination}')
|
||||
nzb2media.logger.debug(f'Extracting {cmd} {file_path} {output_destination}')
|
||||
|
||||
orig_files = []
|
||||
orig_dirs = []
|
||||
|
@ -190,7 +190,7 @@ def extract(file_path, output_destination):
|
|||
info = subprocess.STARTUPINFO()
|
||||
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
else:
|
||||
cmd = core.NICENESS + cmd
|
||||
cmd = nzb2media.NICENESS + cmd
|
||||
cmd2 = cmd
|
||||
if not 'gunzip' in cmd: # gunzip doesn't support password
|
||||
cmd2.append('-p-') # don't prompt for password.
|
||||
|
@ -199,12 +199,12 @@ def extract(file_path, output_destination):
|
|||
) # should extract files fine.
|
||||
res = p.wait()
|
||||
if res == 0: # Both Linux and Windows return 0 for successful.
|
||||
core.logger.info(
|
||||
nzb2media.logger.info(
|
||||
f'EXTRACTOR: Extraction was successful for {file_path} to {output_destination}',
|
||||
)
|
||||
success = 1
|
||||
elif len(passwords) > 0 and not 'gunzip' in cmd:
|
||||
core.logger.info('EXTRACTOR: Attempting to extract with passwords')
|
||||
nzb2media.logger.info('EXTRACTOR: Attempting to extract with passwords')
|
||||
for password in passwords:
|
||||
if (
|
||||
password == ''
|
||||
|
@ -219,7 +219,7 @@ def extract(file_path, output_destination):
|
|||
) # should extract files fine.
|
||||
res = p.wait()
|
||||
if (res >= 0 and platform == 'Windows') or res == 0:
|
||||
core.logger.info(
|
||||
nzb2media.logger.info(
|
||||
f'EXTRACTOR: Extraction was successful for {file_path} to {output_destination} using password: {password}',
|
||||
)
|
||||
success = 1
|
||||
|
@ -227,7 +227,7 @@ def extract(file_path, output_destination):
|
|||
else:
|
||||
continue
|
||||
except Exception:
|
||||
core.logger.error(
|
||||
nzb2media.logger.error(
|
||||
f'EXTRACTOR: Extraction failed for {file_path}. Could not call command {cmd}',
|
||||
)
|
||||
os.chdir(pwd)
|
||||
|
@ -256,7 +256,7 @@ def extract(file_path, output_destination):
|
|||
pass
|
||||
return True
|
||||
else:
|
||||
core.logger.error(
|
||||
nzb2media.logger.error(
|
||||
f'EXTRACTOR: Extraction failed for {file_path}. Result was {res}',
|
||||
)
|
||||
return False
|
0
core/extractor/bin/invisible.vbs → nzb2media/extractor/bin/invisible.vbs
Executable file → Normal file
0
core/extractor/bin/invisible.vbs → nzb2media/extractor/bin/invisible.vbs
Executable file → Normal file
|
@ -6,7 +6,7 @@ import os
|
|||
import sys
|
||||
import threading
|
||||
|
||||
import core
|
||||
import nzb2media
|
||||
|
||||
# number of log files to keep
|
||||
NUM_LOGS = 3
|
||||
|
@ -110,7 +110,7 @@ class NTMRotatingLogHandler:
|
|||
logging.getLogger('postprocess').addHandler(console)
|
||||
logging.getLogger('db').addHandler(console)
|
||||
|
||||
self.log_file_path = os.path.join(core.LOG_DIR, self.log_file)
|
||||
self.log_file_path = os.path.join(nzb2media.LOG_DIR, self.log_file)
|
||||
|
||||
self.cur_handler = self._config_handler()
|
||||
|
||||
|
@ -241,7 +241,7 @@ class NTMRotatingLogHandler:
|
|||
db_logger.db = functools.partial(db_logger.log, DB)
|
||||
try:
|
||||
if log_level == DEBUG:
|
||||
if core.LOG_DEBUG == 1:
|
||||
if nzb2media.LOG_DEBUG == 1:
|
||||
ntm_logger.debug(out_line)
|
||||
elif log_level == MESSAGE:
|
||||
ntm_logger.info(out_line)
|
||||
|
@ -252,7 +252,7 @@ class NTMRotatingLogHandler:
|
|||
elif log_level == POSTPROCESS:
|
||||
pp_logger.postprocess(out_line)
|
||||
elif log_level == DB:
|
||||
if core.LOG_DB == 1:
|
||||
if nzb2media.LOG_DB == 1:
|
||||
db_logger.db(out_line)
|
||||
else:
|
||||
ntm_logger.info(log_level, out_line)
|
||||
|
@ -263,9 +263,9 @@ class NTMRotatingLogHandler:
|
|||
log(error_msg, ERROR)
|
||||
|
||||
if 'NZBOP_SCRIPTDIR' in os.environ:
|
||||
sys.exit(core.NZBGET_POSTPROCESS_ERROR)
|
||||
sys.exit(nzb2media.NZBGET_POSTPROCESS_ERROR)
|
||||
elif not self.console_logging:
|
||||
sys.exit(error_msg.encode(core.SYS_ENCODING, 'xmlcharrefreplace'))
|
||||
sys.exit(error_msg.encode(nzb2media.SYS_ENCODING, 'xmlcharrefreplace'))
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -280,7 +280,7 @@ class DispatchingFormatter:
|
|||
return formatter.format(record)
|
||||
|
||||
|
||||
ntm_log_instance = NTMRotatingLogHandler(core.LOG_FILE, NUM_LOGS, LOG_SIZE)
|
||||
ntm_log_instance = NTMRotatingLogHandler(nzb2media.LOG_FILE, NUM_LOGS, LOG_SIZE)
|
||||
|
||||
|
||||
def log(to_log, log_level=MESSAGE, section='MAIN'):
|
|
@ -4,8 +4,8 @@ import re
|
|||
import sqlite3
|
||||
import time
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def db_filename(filename='nzbtomedia.db', suffix=None):
|
||||
|
@ -20,7 +20,7 @@ def db_filename(filename='nzbtomedia.db', suffix=None):
|
|||
"""
|
||||
if suffix:
|
||||
filename = f'{filename}.{suffix}'
|
||||
return core.os.path.join(core.APP_ROOT, filename)
|
||||
return nzb2media.os.path.join(nzb2media.APP_ROOT, filename)
|
||||
|
||||
|
||||
class DBConnection:
|
7
nzb2media/plugins/downloaders/configuration.py
Normal file
7
nzb2media/plugins/downloaders/configuration.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from nzb2media.plugins.downloaders.nzb.configuration import configure_nzbs
|
||||
from nzb2media.plugins.downloaders.torrent.configuration import (
|
||||
configure_torrent_class,
|
||||
)
|
||||
from nzb2media.plugins.downloaders.torrent.configuration import configure_torrents
|
20
nzb2media/plugins/downloaders/nzb/configuration.py
Normal file
20
nzb2media/plugins/downloaders/nzb/configuration.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import nzb2media
|
||||
|
||||
|
||||
def configure_nzbs(config):
|
||||
nzb_config = config['Nzb']
|
||||
nzb2media.NZB_CLIENT_AGENT = nzb_config['clientAgent'] # sabnzbd
|
||||
nzb2media.NZB_DEFAULT_DIRECTORY = nzb_config['default_downloadDirectory']
|
||||
nzb2media.NZB_NO_MANUAL = int(nzb_config['no_manual'], 0)
|
||||
|
||||
configure_sabnzbd(nzb_config)
|
||||
|
||||
|
||||
def configure_sabnzbd(config):
|
||||
nzb2media.SABNZBD_HOST = config['sabnzbd_host']
|
||||
nzb2media.SABNZBD_PORT = int(
|
||||
config['sabnzbd_port'] or 8080,
|
||||
) # defaults to accommodate NzbGet
|
||||
nzb2media.SABNZBD_APIKEY = config['sabnzbd_apikey']
|
|
@ -4,21 +4,21 @@ import os
|
|||
|
||||
import requests
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def get_nzoid(input_name):
|
||||
nzoid = None
|
||||
slots = []
|
||||
logger.debug('Searching for nzoid from SAbnzbd ...')
|
||||
if 'http' in core.SABNZBD_HOST:
|
||||
base_url = f'{core.SABNZBD_HOST}:{core.SABNZBD_PORT}/api'
|
||||
if 'http' in nzb2media.SABNZBD_HOST:
|
||||
base_url = f'{nzb2media.SABNZBD_HOST}:{nzb2media.SABNZBD_PORT}/api'
|
||||
else:
|
||||
base_url = f'http://{core.SABNZBD_HOST}:{core.SABNZBD_PORT}/api'
|
||||
base_url = f'http://{nzb2media.SABNZBD_HOST}:{nzb2media.SABNZBD_PORT}/api'
|
||||
url = base_url
|
||||
params = {
|
||||
'apikey': core.SABNZBD_APIKEY,
|
||||
'apikey': nzb2media.SABNZBD_APIKEY,
|
||||
'mode': 'queue',
|
||||
'output': 'json',
|
||||
}
|
102
nzb2media/plugins/downloaders/torrent/configuration.py
Normal file
102
nzb2media/plugins/downloaders/torrent/configuration.py
Normal file
|
@ -0,0 +1,102 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import nzb2media
|
||||
from nzb2media.plugins.downloaders.torrent.utils import create_torrent_class
|
||||
|
||||
|
||||
def configure_torrents(config):
|
||||
torrent_config = config['Torrent']
|
||||
nzb2media.TORRENT_CLIENT_AGENT = torrent_config[
|
||||
'clientAgent'
|
||||
] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent | synods | other
|
||||
nzb2media.OUTPUT_DIRECTORY = torrent_config[
|
||||
'outputDirectory'
|
||||
] # /abs/path/to/complete/
|
||||
nzb2media.TORRENT_DEFAULT_DIRECTORY = torrent_config[
|
||||
'default_downloadDirectory'
|
||||
]
|
||||
nzb2media.TORRENT_NO_MANUAL = int(torrent_config['no_manual'], 0)
|
||||
|
||||
configure_torrent_linking(torrent_config)
|
||||
configure_flattening(torrent_config)
|
||||
configure_torrent_deletion(torrent_config)
|
||||
configure_torrent_categories(torrent_config)
|
||||
configure_torrent_permissions(torrent_config)
|
||||
configure_torrent_resuming(torrent_config)
|
||||
configure_utorrent(torrent_config)
|
||||
configure_transmission(torrent_config)
|
||||
configure_deluge(torrent_config)
|
||||
configure_qbittorrent(torrent_config)
|
||||
configure_syno(torrent_config)
|
||||
|
||||
|
||||
def configure_torrent_linking(config):
|
||||
nzb2media.USE_LINK = config['useLink'] # no | hard | sym
|
||||
|
||||
|
||||
def configure_flattening(config):
|
||||
nzb2media.NOFLATTEN = config['noFlatten']
|
||||
if isinstance(nzb2media.NOFLATTEN, str):
|
||||
nzb2media.NOFLATTEN = nzb2media.NOFLATTEN.split(',')
|
||||
|
||||
|
||||
def configure_torrent_categories(config):
|
||||
nzb2media.CATEGORIES = config[
|
||||
'categories'
|
||||
] # music,music_videos,pictures,software
|
||||
if isinstance(nzb2media.CATEGORIES, str):
|
||||
nzb2media.CATEGORIES = nzb2media.CATEGORIES.split(',')
|
||||
|
||||
|
||||
def configure_torrent_resuming(config):
|
||||
nzb2media.TORRENT_RESUME_ON_FAILURE = int(config['resumeOnFailure'])
|
||||
nzb2media.TORRENT_RESUME = int(config['resume'])
|
||||
|
||||
|
||||
def configure_torrent_permissions(config):
|
||||
nzb2media.TORRENT_CHMOD_DIRECTORY = int(str(config['chmodDirectory']), 8)
|
||||
|
||||
|
||||
def configure_torrent_deletion(config):
|
||||
nzb2media.DELETE_ORIGINAL = int(config['deleteOriginal'])
|
||||
|
||||
|
||||
def configure_utorrent(config):
|
||||
nzb2media.UTORRENT_WEB_UI = config[
|
||||
'uTorrentWEBui'
|
||||
] # http://localhost:8090/gui/
|
||||
nzb2media.UTORRENT_USER = config['uTorrentUSR'] # mysecretusr
|
||||
nzb2media.UTORRENT_PASSWORD = config['uTorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_transmission(config):
|
||||
nzb2media.TRANSMISSION_HOST = config['TransmissionHost'] # localhost
|
||||
nzb2media.TRANSMISSION_PORT = int(config['TransmissionPort'])
|
||||
nzb2media.TRANSMISSION_USER = config['TransmissionUSR'] # mysecretusr
|
||||
nzb2media.TRANSMISSION_PASSWORD = config['TransmissionPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_syno(config):
|
||||
nzb2media.SYNO_HOST = config['synoHost'] # localhost
|
||||
nzb2media.SYNO_PORT = int(config['synoPort'])
|
||||
nzb2media.SYNO_USER = config['synoUSR'] # mysecretusr
|
||||
nzb2media.SYNO_PASSWORD = config['synoPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_deluge(config):
|
||||
nzb2media.DELUGE_HOST = config['DelugeHost'] # localhost
|
||||
nzb2media.DELUGE_PORT = int(config['DelugePort']) # 8084
|
||||
nzb2media.DELUGE_USER = config['DelugeUSR'] # mysecretusr
|
||||
nzb2media.DELUGE_PASSWORD = config['DelugePWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_qbittorrent(config):
|
||||
nzb2media.QBITTORRENT_HOST = config['qBittorrentHost'] # localhost
|
||||
nzb2media.QBITTORRENT_PORT = int(config['qBittorrentPort']) # 8080
|
||||
nzb2media.QBITTORRENT_USER = config['qBittorrentUSR'] # mysecretusr
|
||||
nzb2media.QBITTORRENT_PASSWORD = config['qBittorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_torrent_class():
|
||||
# create torrent class
|
||||
nzb2media.TORRENT_CLASS = create_torrent_class(nzb2media.TORRENT_CLIENT_AGENT)
|
|
@ -2,16 +2,16 @@ from __future__ import annotations
|
|||
|
||||
from deluge_client import DelugeRPCClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'deluge'
|
||||
host = core.DELUGE_HOST
|
||||
port = core.DELUGE_PORT
|
||||
user = core.DELUGE_USER
|
||||
password = core.DELUGE_PASSWORD
|
||||
host = nzb2media.DELUGE_HOST
|
||||
port = nzb2media.DELUGE_PORT
|
||||
user = nzb2media.DELUGE_USER
|
||||
password = nzb2media.DELUGE_PASSWORD
|
||||
|
||||
logger.debug(f'Connecting to {agent}: http://{host}:{port}')
|
||||
client = DelugeRPCClient(host, port, user, password)
|
|
@ -2,16 +2,16 @@ from __future__ import annotations
|
|||
|
||||
from qbittorrent import Client as qBittorrentClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'qbittorrent'
|
||||
host = core.QBITTORRENT_HOST
|
||||
port = core.QBITTORRENT_PORT
|
||||
user = core.QBITTORRENT_USER
|
||||
password = core.QBITTORRENT_PASSWORD
|
||||
host = nzb2media.QBITTORRENT_HOST
|
||||
port = nzb2media.QBITTORRENT_PORT
|
||||
user = nzb2media.QBITTORRENT_USER
|
||||
password = nzb2media.QBITTORRENT_PASSWORD
|
||||
|
||||
logger.debug(
|
||||
f'Connecting to {agent}: http://{host}:{port}',
|
|
@ -2,16 +2,16 @@ from __future__ import annotations
|
|||
|
||||
from syno.downloadstation import DownloadStation
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'synology'
|
||||
host = core.SYNO_HOST
|
||||
port = core.SYNO_PORT
|
||||
user = core.SYNO_USER
|
||||
password = core.SYNO_PASSWORD
|
||||
host = nzb2media.SYNO_HOST
|
||||
port = nzb2media.SYNO_PORT
|
||||
user = nzb2media.SYNO_USER
|
||||
password = nzb2media.SYNO_PASSWORD
|
||||
|
||||
logger.debug(f'Connecting to {agent}: http://{host}:{port}')
|
||||
try:
|
|
@ -2,16 +2,16 @@ from __future__ import annotations
|
|||
|
||||
from transmissionrpc.client import Client as TransmissionClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'transmission'
|
||||
host = core.TRANSMISSION_HOST
|
||||
port = core.TRANSMISSION_PORT
|
||||
user = core.TRANSMISSION_USER
|
||||
password = core.TRANSMISSION_PASSWORD
|
||||
host = nzb2media.TRANSMISSION_HOST
|
||||
port = nzb2media.TRANSMISSION_PORT
|
||||
user = nzb2media.TRANSMISSION_USER
|
||||
password = nzb2media.TRANSMISSION_PASSWORD
|
||||
|
||||
logger.debug(f'Connecting to {agent}: http://{host}:{port}')
|
||||
try:
|
97
nzb2media/plugins/downloaders/torrent/utils.py
Normal file
97
nzb2media/plugins/downloaders/torrent/utils.py
Normal file
|
@ -0,0 +1,97 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
from .deluge import configure_client as deluge_client
|
||||
from .qbittorrent import configure_client as qbittorrent_client
|
||||
from .synology import configure_client as synology_client
|
||||
from .transmission import configure_client as transmission_client
|
||||
from .utorrent import configure_client as utorrent_client
|
||||
|
||||
torrent_clients = {
|
||||
'deluge': deluge_client,
|
||||
'qbittorrent': qbittorrent_client,
|
||||
'transmission': transmission_client,
|
||||
'utorrent': utorrent_client,
|
||||
'synods': synology_client,
|
||||
}
|
||||
|
||||
|
||||
def create_torrent_class(client_agent):
|
||||
if not nzb2media.APP_NAME == 'TorrentToMedia.py':
|
||||
return # Skip loading Torrent for NZBs.
|
||||
|
||||
client = torrent_clients.get(client_agent)
|
||||
if client:
|
||||
return client()
|
||||
|
||||
|
||||
def pause_torrent(client_agent, input_hash, input_id, input_name):
|
||||
logger.debug(
|
||||
f'Stopping torrent {input_name} in {client_agent} while processing',
|
||||
)
|
||||
try:
|
||||
if client_agent == 'utorrent' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.stop(input_hash)
|
||||
if client_agent == 'transmission' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.stop_torrent(input_id)
|
||||
if client_agent == 'synods' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.pause_task(input_id)
|
||||
if client_agent == 'deluge' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.core.pause_torrent([input_id])
|
||||
if client_agent == 'qbittorrent' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.pause(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
f'Failed to stop torrent {input_name} in {client_agent}',
|
||||
)
|
||||
|
||||
|
||||
def resume_torrent(client_agent, input_hash, input_id, input_name):
|
||||
if not nzb2media.TORRENT_RESUME == 1:
|
||||
return
|
||||
logger.debug(f'Starting torrent {input_name} in {client_agent}')
|
||||
try:
|
||||
if client_agent == 'utorrent' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.start(input_hash)
|
||||
if client_agent == 'transmission' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.start_torrent(input_id)
|
||||
if client_agent == 'synods' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.resume_task(input_id)
|
||||
if client_agent == 'deluge' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.core.resume_torrent([input_id])
|
||||
if client_agent == 'qbittorrent' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.resume(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
f'Failed to start torrent {input_name} in {client_agent}',
|
||||
)
|
||||
|
||||
|
||||
def remove_torrent(client_agent, input_hash, input_id, input_name):
|
||||
if nzb2media.DELETE_ORIGINAL == 1 or nzb2media.USE_LINK == 'move':
|
||||
logger.debug(f'Deleting torrent {input_name} from {client_agent}')
|
||||
try:
|
||||
if client_agent == 'utorrent' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.removedata(input_hash)
|
||||
nzb2media.TORRENT_CLASS.remove(input_hash)
|
||||
if client_agent == 'transmission' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.remove_torrent(input_id, True)
|
||||
if client_agent == 'synods' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.delete_task(input_id)
|
||||
if client_agent == 'deluge' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.core.remove_torrent(input_id, True)
|
||||
if client_agent == 'qbittorrent' and nzb2media.TORRENT_CLASS != '':
|
||||
nzb2media.TORRENT_CLASS.delete_permanently(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
f'Failed to delete torrent {input_name} in {client_agent}',
|
||||
)
|
||||
else:
|
||||
resume_torrent(client_agent, input_hash, input_id, input_name)
|
|
@ -2,15 +2,15 @@ from __future__ import annotations
|
|||
|
||||
from utorrent.client import UTorrentClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'utorrent'
|
||||
web_ui = core.UTORRENT_WEB_UI
|
||||
user = core.UTORRENT_USER
|
||||
password = core.UTORRENT_PASSWORD
|
||||
web_ui = nzb2media.UTORRENT_WEB_UI
|
||||
user = nzb2media.UTORRENT_USER
|
||||
password = nzb2media.UTORRENT_PASSWORD
|
||||
|
||||
logger.debug(f'Connecting to {agent}: {web_ui}')
|
||||
try:
|
5
nzb2media/plugins/downloaders/utils.py
Normal file
5
nzb2media/plugins/downloaders/utils.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from nzb2media.plugins.downloaders.torrent.utils import pause_torrent
|
||||
from nzb2media.plugins.downloaders.torrent.utils import remove_torrent
|
||||
from nzb2media.plugins.downloaders.torrent.utils import resume_torrent
|
|
@ -2,15 +2,15 @@ from __future__ import annotations
|
|||
|
||||
import requests
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def configure_plex(config):
|
||||
core.PLEX_SSL = int(config['Plex']['plex_ssl'])
|
||||
core.PLEX_HOST = config['Plex']['plex_host']
|
||||
core.PLEX_PORT = config['Plex']['plex_port']
|
||||
core.PLEX_TOKEN = config['Plex']['plex_token']
|
||||
nzb2media.PLEX_SSL = int(config['Plex']['plex_ssl'])
|
||||
nzb2media.PLEX_HOST = config['Plex']['plex_host']
|
||||
nzb2media.PLEX_PORT = config['Plex']['plex_port']
|
||||
nzb2media.PLEX_TOKEN = config['Plex']['plex_token']
|
||||
plex_section = config['Plex']['plex_sections'] or []
|
||||
|
||||
if plex_section:
|
||||
|
@ -22,29 +22,29 @@ def configure_plex(config):
|
|||
tuple(item.split(',')) for item in plex_section.split('|')
|
||||
]
|
||||
|
||||
core.PLEX_SECTION = plex_section
|
||||
nzb2media.PLEX_SECTION = plex_section
|
||||
|
||||
|
||||
def plex_update(category):
|
||||
if core.FAILED:
|
||||
if nzb2media.FAILED:
|
||||
return
|
||||
url = '{scheme}://{host}:{port}/library/sections/'.format(
|
||||
scheme='https' if core.PLEX_SSL else 'http',
|
||||
host=core.PLEX_HOST,
|
||||
port=core.PLEX_PORT,
|
||||
scheme='https' if nzb2media.PLEX_SSL else 'http',
|
||||
host=nzb2media.PLEX_HOST,
|
||||
port=nzb2media.PLEX_PORT,
|
||||
)
|
||||
section = None
|
||||
if not core.PLEX_SECTION:
|
||||
if not nzb2media.PLEX_SECTION:
|
||||
return
|
||||
logger.debug(
|
||||
f'Attempting to update Plex Library for category {category}.', 'PLEX',
|
||||
)
|
||||
for item in core.PLEX_SECTION:
|
||||
for item in nzb2media.PLEX_SECTION:
|
||||
if item[0] == category:
|
||||
section = item[1]
|
||||
|
||||
if section:
|
||||
url = f'{url}{section}/refresh?X-Plex-Token={core.PLEX_TOKEN}'
|
||||
url = f'{url}{section}/refresh?X-Plex-Token={nzb2media.PLEX_TOKEN}'
|
||||
requests.get(url, timeout=(60, 120), verify=False)
|
||||
logger.debug('Plex Library has been refreshed.', 'PLEX')
|
||||
else:
|
|
@ -6,12 +6,12 @@ import re
|
|||
import subliminal
|
||||
from babelfish import Language
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def import_subs(filename):
|
||||
if not core.GETSUBS:
|
||||
if not nzb2media.GETSUBS:
|
||||
return
|
||||
try:
|
||||
subliminal.region.configure(
|
||||
|
@ -21,7 +21,7 @@ def import_subs(filename):
|
|||
pass
|
||||
|
||||
languages = set()
|
||||
for item in core.SLANGUAGES:
|
||||
for item in nzb2media.SLANGUAGES:
|
||||
try:
|
||||
languages.add(Language(item))
|
||||
except Exception:
|
||||
|
@ -52,7 +52,7 @@ def import_subs(filename):
|
|||
def rename_subs(path):
|
||||
filepaths = []
|
||||
sub_ext = ['.srt', '.sub', '.idx']
|
||||
vidfiles = core.list_media_files(
|
||||
vidfiles = nzb2media.list_media_files(
|
||||
path, media=True, audio=False, meta=False, archives=False,
|
||||
)
|
||||
if (
|
|
@ -2,12 +2,12 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.processor import nzb
|
||||
from core.utils.common import get_dirs
|
||||
from core.utils.download_info import get_download_info
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.processor import nzb
|
||||
from nzb2media.utils.common import get_dirs
|
||||
from nzb2media.utils.download_info import get_download_info
|
||||
|
||||
|
||||
def process():
|
||||
|
@ -22,9 +22,9 @@ def process():
|
|||
status_code=0,
|
||||
)
|
||||
|
||||
for section, subsections in core.SECTIONS.items():
|
||||
for section, subsections in nzb2media.SECTIONS.items():
|
||||
for subsection in subsections:
|
||||
if not core.CFG[section][subsection].isenabled():
|
||||
if not nzb2media.CFG[section][subsection].isenabled():
|
||||
continue
|
||||
for dir_name in get_dirs(section, subsection, link='move'):
|
||||
logger.info(
|
||||
|
@ -34,18 +34,18 @@ def process():
|
|||
f'Checking database for download info for {os.path.basename(dir_name)} ...',
|
||||
)
|
||||
|
||||
core.DOWNLOAD_INFO = get_download_info(
|
||||
nzb2media.DOWNLOAD_INFO = get_download_info(
|
||||
os.path.basename(dir_name),
|
||||
0,
|
||||
)
|
||||
if core.DOWNLOAD_INFO:
|
||||
if nzb2media.DOWNLOAD_INFO:
|
||||
logger.info(
|
||||
f'Found download info for {os.path.basename(dir_name)}, setting variables now ...',
|
||||
)
|
||||
client_agent = (
|
||||
core.DOWNLOAD_INFO[0]['client_agent'] or 'manual'
|
||||
nzb2media.DOWNLOAD_INFO[0]['client_agent'] or 'manual'
|
||||
)
|
||||
download_id = core.DOWNLOAD_INFO[0]['input_id'] or ''
|
||||
download_id = nzb2media.DOWNLOAD_INFO[0]['input_id'] or ''
|
||||
else:
|
||||
logger.info(
|
||||
f'Unable to locate download info for {os.path.basename(dir_name)}, continuing to try and process this release ...',
|
||||
|
@ -55,7 +55,7 @@ def process():
|
|||
|
||||
if (
|
||||
client_agent
|
||||
and client_agent.lower() not in core.NZB_CLIENTS
|
||||
and client_agent.lower() not in nzb2media.NZB_CLIENTS
|
||||
):
|
||||
continue
|
||||
|
|
@ -2,24 +2,24 @@ from __future__ import annotations
|
|||
|
||||
import datetime
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core import main_db
|
||||
from core.auto_process import books
|
||||
from core.auto_process import comics
|
||||
from core.auto_process import games
|
||||
from core.auto_process import movies
|
||||
from core.auto_process import music
|
||||
from core.auto_process import tv
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.plugins.downloaders.nzb.utils import get_nzoid
|
||||
from core.plugins.plex import plex_update
|
||||
from core.user_scripts import external_script
|
||||
from core.utils.encoding import char_replace
|
||||
from core.utils.common import clean_dir
|
||||
from core.utils.encoding import convert_to_ascii
|
||||
from core.utils.files import extract_files
|
||||
from core.utils.download_info import update_download_info_status
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media import main_db
|
||||
from nzb2media.auto_process import books
|
||||
from nzb2media.auto_process import comics
|
||||
from nzb2media.auto_process import games
|
||||
from nzb2media.auto_process import movies
|
||||
from nzb2media.auto_process import music
|
||||
from nzb2media.auto_process import tv
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
from nzb2media.plugins.downloaders.nzb.utils import get_nzoid
|
||||
from nzb2media.plugins.plex import plex_update
|
||||
from nzb2media.user_scripts import external_script
|
||||
from nzb2media.utils.encoding import char_replace
|
||||
from nzb2media.utils.common import clean_dir
|
||||
from nzb2media.utils.encoding import convert_to_ascii
|
||||
from nzb2media.utils.files import extract_files
|
||||
from nzb2media.utils.download_info import update_download_info_status
|
||||
|
||||
|
||||
def process(
|
||||
|
@ -31,7 +31,7 @@ def process(
|
|||
input_category=None,
|
||||
failure_link=None,
|
||||
):
|
||||
if core.SAFE_MODE and input_directory == core.NZB_DEFAULT_DIRECTORY:
|
||||
if nzb2media.SAFE_MODE and input_directory == nzb2media.NZB_DEFAULT_DIRECTORY:
|
||||
logger.error(
|
||||
f'The input directory:[{input_directory}] is the Default Download Directory. Please configure category directories to prevent processing of other media.',
|
||||
)
|
||||
|
@ -43,7 +43,7 @@ def process(
|
|||
if not download_id and client_agent == 'sabnzbd':
|
||||
download_id = get_nzoid(input_name)
|
||||
|
||||
if client_agent != 'manual' and not core.DOWNLOAD_INFO:
|
||||
if client_agent != 'manual' and not nzb2media.DOWNLOAD_INFO:
|
||||
logger.debug(
|
||||
f'Adding NZB download info for directory {input_directory} to database',
|
||||
)
|
||||
|
@ -74,9 +74,9 @@ def process(
|
|||
if input_category is None:
|
||||
input_category = 'UNCAT'
|
||||
usercat = input_category
|
||||
section = core.CFG.findsection(input_category).isenabled()
|
||||
section = nzb2media.CFG.findsection(input_category).isenabled()
|
||||
if section is None:
|
||||
section = core.CFG.findsection('ALL').isenabled()
|
||||
section = nzb2media.CFG.findsection('ALL').isenabled()
|
||||
if section is None:
|
||||
logger.error(
|
||||
f'Category:[{input_category}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.',
|
||||
|
@ -109,12 +109,12 @@ def process(
|
|||
message='',
|
||||
)
|
||||
|
||||
cfg = dict(core.CFG[section_name][usercat])
|
||||
cfg = dict(nzb2media.CFG[section_name][usercat])
|
||||
|
||||
extract = int(cfg.get('extract', 0))
|
||||
|
||||
try:
|
||||
if int(cfg.get('remote_path')) and not core.REMOTE_PATHS:
|
||||
if int(cfg.get('remote_path')) and not nzb2media.REMOTE_PATHS:
|
||||
logger.error(
|
||||
f'Remote Path is enabled for {section_name}:{input_category} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!',
|
||||
)
|
||||
|
@ -130,7 +130,7 @@ def process(
|
|||
|
||||
input_name, input_directory = convert_to_ascii(input_name, input_directory)
|
||||
|
||||
if extract == 1 and not (status > 0 and core.NOEXTRACTFAILED):
|
||||
if extract == 1 and not (status > 0 and nzb2media.NOEXTRACTFAILED):
|
||||
logger.debug(
|
||||
f'Checking for archives to extract in directory: {input_directory}',
|
||||
)
|
|
@ -3,9 +3,9 @@ from __future__ import annotations
|
|||
import os
|
||||
import sys
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.processor import nzb
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media.processor import nzb
|
||||
|
||||
|
||||
def parse_download_id():
|
||||
|
@ -98,7 +98,7 @@ def check_version():
|
|||
logger.error(
|
||||
f'NZBGet Version {version} is not supported. Please update NZBGet.',
|
||||
)
|
||||
sys.exit(core.NZBGET_POSTPROCESS_ERROR)
|
||||
sys.exit(nzb2media.NZBGET_POSTPROCESS_ERROR)
|
||||
logger.info(f'Script triggered from NZBGet Version {version}.')
|
||||
|
||||
|
|
@ -2,8 +2,8 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
|
||||
from core import logger
|
||||
from core.processor import nzb
|
||||
from nzb2media import logger
|
||||
from nzb2media.processor import nzb
|
||||
|
||||
# Constants
|
||||
MINIMUM_ARGUMENTS = 8
|
|
@ -6,9 +6,9 @@ import re
|
|||
import shlex
|
||||
import subprocess
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.utils.files import list_media_files
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media.utils.files import list_media_files
|
||||
|
||||
reverse_list = [
|
||||
r'\.\d{2}e\d{2}s\.',
|
||||
|
@ -86,19 +86,19 @@ def process_all_exceptions(name, dirname):
|
|||
newfilename = filename
|
||||
if not newfilename:
|
||||
newfilename = exception(filename, parent_dir, name)
|
||||
if core.GROUPS:
|
||||
if nzb2media.GROUPS:
|
||||
newfilename = strip_groups(newfilename)
|
||||
if newfilename != filename:
|
||||
rename_file(filename, newfilename)
|
||||
|
||||
|
||||
def strip_groups(filename):
|
||||
if not core.GROUPS:
|
||||
if not nzb2media.GROUPS:
|
||||
return filename
|
||||
dirname, file = os.path.split(filename)
|
||||
head, file_extension = os.path.splitext(file)
|
||||
newname = head.replace(' ', '.')
|
||||
for group in core.GROUPS:
|
||||
for group in nzb2media.GROUPS:
|
||||
newname = newname.replace(group, '')
|
||||
newname = newname.replace('[]', '')
|
||||
newfile = newname + file_extension
|
||||
|
@ -224,7 +224,7 @@ def par2(dirname):
|
|||
if size > sofar:
|
||||
sofar = size
|
||||
parfile = item
|
||||
if core.PAR2CMD and parfile:
|
||||
if nzb2media.PAR2CMD and parfile:
|
||||
pwd = os.getcwd() # Get our Present Working Directory
|
||||
os.chdir(dirname) # set directory to run par on.
|
||||
if platform.system() == 'Windows':
|
||||
|
@ -232,7 +232,7 @@ def par2(dirname):
|
|||
else:
|
||||
bitbucket = open('/dev/null')
|
||||
logger.info(f'Running par2 on file {parfile}.', 'PAR2')
|
||||
command = [core.PAR2CMD, 'r', parfile, '*']
|
||||
command = [nzb2media.PAR2CMD, 'r', parfile, '*']
|
||||
cmd = ''
|
||||
for item in command:
|
||||
cmd = f'{cmd} {item}'
|
|
@ -13,9 +13,9 @@ import time
|
|||
|
||||
from babelfish import Language
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.utils.paths import make_dir
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media.utils.paths import make_dir
|
||||
|
||||
__author__ = 'Justin'
|
||||
|
||||
|
@ -24,15 +24,15 @@ def is_video_good(video: pathlib.Path, status, require_lan=None):
|
|||
file_ext = video.suffix
|
||||
disable = False
|
||||
if (
|
||||
file_ext not in core.MEDIA_CONTAINER
|
||||
or not core.FFPROBE
|
||||
or not core.CHECK_MEDIA
|
||||
file_ext not in nzb2media.MEDIA_CONTAINER
|
||||
or not nzb2media.FFPROBE
|
||||
or not nzb2media.CHECK_MEDIA
|
||||
or file_ext in ['.iso']
|
||||
or (status > 0 and core.NOEXTRACTFAILED)
|
||||
or (status > 0 and nzb2media.NOEXTRACTFAILED)
|
||||
):
|
||||
disable = True
|
||||
else:
|
||||
test_details, res = get_video_details(core.TEST_FILE)
|
||||
test_details, res = get_video_details(nzb2media.TEST_FILE)
|
||||
if res != 0 or test_details.get('error'):
|
||||
disable = True
|
||||
logger.info(
|
||||
|
@ -119,7 +119,7 @@ def zip_out(file, img, bitbucket):
|
|||
if os.path.isfile(file):
|
||||
cmd = ['cat', file]
|
||||
else:
|
||||
cmd = [core.SEVENZIP, '-so', 'e', img, file]
|
||||
cmd = [nzb2media.SEVENZIP, '-so', 'e', img, file]
|
||||
try:
|
||||
procin = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE, stderr=bitbucket,
|
||||
|
@ -133,14 +133,14 @@ def get_video_details(videofile, img=None, bitbucket=None):
|
|||
video_details = {}
|
||||
result = 1
|
||||
file = videofile
|
||||
if not core.FFPROBE:
|
||||
if not nzb2media.FFPROBE:
|
||||
return video_details, result
|
||||
print_format = '-of' if 'avprobe' in core.FFPROBE else '-print_format'
|
||||
print_format = '-of' if 'avprobe' in nzb2media.FFPROBE else '-print_format'
|
||||
try:
|
||||
if img:
|
||||
videofile = '-'
|
||||
command = [
|
||||
core.FFPROBE,
|
||||
nzb2media.FFPROBE,
|
||||
'-v',
|
||||
'quiet',
|
||||
print_format,
|
||||
|
@ -165,7 +165,7 @@ def get_video_details(videofile, img=None, bitbucket=None):
|
|||
except Exception:
|
||||
try: # try this again without -show error in case of ffmpeg limitation
|
||||
command = [
|
||||
core.FFPROBE,
|
||||
nzb2media.FFPROBE,
|
||||
'-v',
|
||||
'quiet',
|
||||
print_format,
|
||||
|
@ -223,17 +223,17 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
directory, name = os.path.split(file)
|
||||
name, ext = os.path.splitext(name)
|
||||
check = re.match('VTS_([0-9][0-9])_[0-9]+', name)
|
||||
if check and core.CONCAT:
|
||||
if check and nzb2media.CONCAT:
|
||||
name = movie_name
|
||||
elif check:
|
||||
name = f'{movie_name}.cd{check.groups()[0]}'
|
||||
elif core.CONCAT and re.match('(.+)[cC][dD][0-9]', name):
|
||||
elif nzb2media.CONCAT and re.match('(.+)[cC][dD][0-9]', name):
|
||||
name = re.sub('([ ._=:-]+[cC][dD][0-9])', '', name)
|
||||
if (
|
||||
ext == core.VEXTENSION and new_dir == directory
|
||||
ext == nzb2media.VEXTENSION and new_dir == directory
|
||||
): # we need to change the name to prevent overwriting itself.
|
||||
core.VEXTENSION = (
|
||||
f'-transcoded{core.VEXTENSION}' # adds '-transcoded.ext'
|
||||
nzb2media.VEXTENSION = (
|
||||
f'-transcoded{nzb2media.VEXTENSION}' # adds '-transcoded.ext'
|
||||
)
|
||||
new_file = file
|
||||
else:
|
||||
|
@ -256,7 +256,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
file = '-'
|
||||
|
||||
newfile_path = os.path.normpath(
|
||||
os.path.join(new_dir, name) + core.VEXTENSION,
|
||||
os.path.join(new_dir, name) + nzb2media.VEXTENSION,
|
||||
)
|
||||
|
||||
map_cmd = []
|
||||
|
@ -275,51 +275,51 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
sub_streams = []
|
||||
|
||||
map_cmd.extend(['-map', '0'])
|
||||
if core.VCODEC:
|
||||
video_cmd.extend(['-c:v', core.VCODEC])
|
||||
if core.VCODEC == 'libx264' and core.VPRESET:
|
||||
video_cmd.extend(['-pre', core.VPRESET])
|
||||
if nzb2media.VCODEC:
|
||||
video_cmd.extend(['-c:v', nzb2media.VCODEC])
|
||||
if nzb2media.VCODEC == 'libx264' and nzb2media.VPRESET:
|
||||
video_cmd.extend(['-pre', nzb2media.VPRESET])
|
||||
else:
|
||||
video_cmd.extend(['-c:v', 'copy'])
|
||||
if core.VFRAMERATE:
|
||||
video_cmd.extend(['-r', str(core.VFRAMERATE)])
|
||||
if core.VBITRATE:
|
||||
video_cmd.extend(['-b:v', str(core.VBITRATE)])
|
||||
if core.VRESOLUTION:
|
||||
video_cmd.extend(['-vf', f'scale={core.VRESOLUTION}'])
|
||||
if core.VPRESET:
|
||||
video_cmd.extend(['-preset', core.VPRESET])
|
||||
if core.VCRF:
|
||||
video_cmd.extend(['-crf', str(core.VCRF)])
|
||||
if core.VLEVEL:
|
||||
video_cmd.extend(['-level', str(core.VLEVEL)])
|
||||
if nzb2media.VFRAMERATE:
|
||||
video_cmd.extend(['-r', str(nzb2media.VFRAMERATE)])
|
||||
if nzb2media.VBITRATE:
|
||||
video_cmd.extend(['-b:v', str(nzb2media.VBITRATE)])
|
||||
if nzb2media.VRESOLUTION:
|
||||
video_cmd.extend(['-vf', f'scale={nzb2media.VRESOLUTION}'])
|
||||
if nzb2media.VPRESET:
|
||||
video_cmd.extend(['-preset', nzb2media.VPRESET])
|
||||
if nzb2media.VCRF:
|
||||
video_cmd.extend(['-crf', str(nzb2media.VCRF)])
|
||||
if nzb2media.VLEVEL:
|
||||
video_cmd.extend(['-level', str(nzb2media.VLEVEL)])
|
||||
|
||||
if core.ACODEC:
|
||||
audio_cmd.extend(['-c:a', core.ACODEC])
|
||||
if core.ACODEC in [
|
||||
if nzb2media.ACODEC:
|
||||
audio_cmd.extend(['-c:a', nzb2media.ACODEC])
|
||||
if nzb2media.ACODEC in [
|
||||
'aac',
|
||||
'dts',
|
||||
]: # Allow users to use the experimental AAC codec that's built into recent versions of ffmpeg
|
||||
audio_cmd.extend(['-strict', '-2'])
|
||||
else:
|
||||
audio_cmd.extend(['-c:a', 'copy'])
|
||||
if core.ACHANNELS:
|
||||
audio_cmd.extend(['-ac', str(core.ACHANNELS)])
|
||||
if core.ABITRATE:
|
||||
audio_cmd.extend(['-b:a', str(core.ABITRATE)])
|
||||
if core.OUTPUTQUALITYPERCENT:
|
||||
audio_cmd.extend(['-q:a', str(core.OUTPUTQUALITYPERCENT)])
|
||||
if nzb2media.ACHANNELS:
|
||||
audio_cmd.extend(['-ac', str(nzb2media.ACHANNELS)])
|
||||
if nzb2media.ABITRATE:
|
||||
audio_cmd.extend(['-b:a', str(nzb2media.ABITRATE)])
|
||||
if nzb2media.OUTPUTQUALITYPERCENT:
|
||||
audio_cmd.extend(['-q:a', str(nzb2media.OUTPUTQUALITYPERCENT)])
|
||||
|
||||
if core.SCODEC and core.ALLOWSUBS:
|
||||
sub_cmd.extend(['-c:s', core.SCODEC])
|
||||
if nzb2media.SCODEC and nzb2media.ALLOWSUBS:
|
||||
sub_cmd.extend(['-c:s', nzb2media.SCODEC])
|
||||
elif (
|
||||
core.ALLOWSUBS
|
||||
nzb2media.ALLOWSUBS
|
||||
): # Not every subtitle codec can be used for every video container format!
|
||||
sub_cmd.extend(['-c:s', 'copy'])
|
||||
else: # http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/subtitle_options
|
||||
sub_cmd.extend(['-sn']) # Don't copy the subtitles over
|
||||
|
||||
if core.OUTPUTFASTSTART:
|
||||
if nzb2media.OUTPUTFASTSTART:
|
||||
other_cmd.extend(['-movflags', '+faststart'])
|
||||
|
||||
else:
|
||||
|
@ -338,7 +338,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
for item in video_details['streams']
|
||||
if item['codec_type'] == 'subtitle'
|
||||
]
|
||||
if core.VEXTENSION not in ['.mkv', '.mpegts']:
|
||||
if nzb2media.VEXTENSION not in ['.mkv', '.mpegts']:
|
||||
sub_streams = [
|
||||
item
|
||||
for item in video_details['streams']
|
||||
|
@ -352,15 +352,15 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
fr = video.get('avg_frame_rate', 0)
|
||||
width = video.get('width', 0)
|
||||
height = video.get('height', 0)
|
||||
scale = core.VRESOLUTION
|
||||
if codec in core.VCODEC_ALLOW or not core.VCODEC:
|
||||
scale = nzb2media.VRESOLUTION
|
||||
if codec in nzb2media.VCODEC_ALLOW or not nzb2media.VCODEC:
|
||||
video_cmd.extend(['-c:v', 'copy'])
|
||||
else:
|
||||
video_cmd.extend(['-c:v', core.VCODEC])
|
||||
if core.VFRAMERATE and not (
|
||||
core.VFRAMERATE * 0.999 <= fr <= core.VFRAMERATE * 1.001
|
||||
video_cmd.extend(['-c:v', nzb2media.VCODEC])
|
||||
if nzb2media.VFRAMERATE and not (
|
||||
nzb2media.VFRAMERATE * 0.999 <= fr <= nzb2media.VFRAMERATE * 1.001
|
||||
):
|
||||
video_cmd.extend(['-r', str(core.VFRAMERATE)])
|
||||
video_cmd.extend(['-r', str(nzb2media.VFRAMERATE)])
|
||||
if scale:
|
||||
w_scale = width / float(scale.split(':')[0])
|
||||
h_scale = height / float(scale.split(':')[1])
|
||||
|
@ -378,19 +378,19 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
)
|
||||
if h_scale > 1:
|
||||
video_cmd.extend(['-vf', f'scale={scale}'])
|
||||
if core.VBITRATE:
|
||||
video_cmd.extend(['-b:v', str(core.VBITRATE)])
|
||||
if core.VPRESET:
|
||||
video_cmd.extend(['-preset', core.VPRESET])
|
||||
if core.VCRF:
|
||||
video_cmd.extend(['-crf', str(core.VCRF)])
|
||||
if core.VLEVEL:
|
||||
video_cmd.extend(['-level', str(core.VLEVEL)])
|
||||
if nzb2media.VBITRATE:
|
||||
video_cmd.extend(['-b:v', str(nzb2media.VBITRATE)])
|
||||
if nzb2media.VPRESET:
|
||||
video_cmd.extend(['-preset', nzb2media.VPRESET])
|
||||
if nzb2media.VCRF:
|
||||
video_cmd.extend(['-crf', str(nzb2media.VCRF)])
|
||||
if nzb2media.VLEVEL:
|
||||
video_cmd.extend(['-level', str(nzb2media.VLEVEL)])
|
||||
no_copy = ['-vf', '-r', '-crf', '-level', '-preset', '-b:v']
|
||||
if video_cmd[1] == 'copy' and any(i in video_cmd for i in no_copy):
|
||||
video_cmd[1] = core.VCODEC
|
||||
video_cmd[1] = nzb2media.VCODEC
|
||||
if (
|
||||
core.VCODEC == 'copy'
|
||||
nzb2media.VCODEC == 'copy'
|
||||
): # force copy. therefore ignore all other video transcoding.
|
||||
video_cmd = ['-c:v', 'copy']
|
||||
map_cmd.extend(['-map', '0:{index}'.format(index=video['index'])])
|
||||
|
@ -413,7 +413,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
audio1 = [
|
||||
item
|
||||
for item in audio_streams
|
||||
if item['tags']['language'] == core.ALANGUAGE
|
||||
if item['tags']['language'] == nzb2media.ALANGUAGE
|
||||
]
|
||||
except Exception: # no language tags. Assume only 1 language.
|
||||
audio1 = audio_streams
|
||||
|
@ -421,7 +421,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
audio2 = [
|
||||
item
|
||||
for item in audio1
|
||||
if item['codec_name'] in core.ACODEC_ALLOW
|
||||
if item['codec_name'] in nzb2media.ACODEC_ALLOW
|
||||
]
|
||||
except Exception:
|
||||
audio2 = []
|
||||
|
@ -429,7 +429,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
audio3 = [
|
||||
item
|
||||
for item in audio_streams
|
||||
if item['tags']['language'] != core.ALANGUAGE
|
||||
if item['tags']['language'] != nzb2media.ALANGUAGE
|
||||
]
|
||||
except Exception:
|
||||
audio3 = []
|
||||
|
@ -437,7 +437,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
audio4 = [
|
||||
item
|
||||
for item in audio3
|
||||
if item['codec_name'] in core.ACODEC_ALLOW
|
||||
if item['codec_name'] in nzb2media.ACODEC_ALLOW
|
||||
]
|
||||
except Exception:
|
||||
audio4 = []
|
||||
|
@ -458,7 +458,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
bitrate = int(float(audio1[0].get('bit_rate', 0))) / 1000
|
||||
channels = int(float(audio1[0].get('channels', 0)))
|
||||
audio_cmd.extend(
|
||||
[f'-c:a:{used_audio}', core.ACODEC if core.ACODEC else 'copy'],
|
||||
[f'-c:a:{used_audio}', nzb2media.ACODEC if nzb2media.ACODEC else 'copy'],
|
||||
)
|
||||
elif audio4: # wrong language, right codec.
|
||||
map_cmd.extend(
|
||||
|
@ -478,35 +478,35 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
bitrate = int(float(audio3[0].get('bit_rate', 0))) / 1000
|
||||
channels = int(float(audio3[0].get('channels', 0)))
|
||||
audio_cmd.extend(
|
||||
[f'-c:a:{used_audio}', core.ACODEC if core.ACODEC else 'copy'],
|
||||
[f'-c:a:{used_audio}', nzb2media.ACODEC if nzb2media.ACODEC else 'copy'],
|
||||
)
|
||||
|
||||
if core.ACHANNELS and channels and channels > core.ACHANNELS:
|
||||
audio_cmd.extend([f'-ac:a:{used_audio}', str(core.ACHANNELS)])
|
||||
if nzb2media.ACHANNELS and channels and channels > nzb2media.ACHANNELS:
|
||||
audio_cmd.extend([f'-ac:a:{used_audio}', str(nzb2media.ACHANNELS)])
|
||||
if audio_cmd[1] == 'copy':
|
||||
audio_cmd[1] = core.ACODEC
|
||||
if core.ABITRATE and not (
|
||||
core.ABITRATE * 0.9 < bitrate < core.ABITRATE * 1.1
|
||||
audio_cmd[1] = nzb2media.ACODEC
|
||||
if nzb2media.ABITRATE and not (
|
||||
nzb2media.ABITRATE * 0.9 < bitrate < nzb2media.ABITRATE * 1.1
|
||||
):
|
||||
audio_cmd.extend([f'-b:a:{used_audio}', str(core.ABITRATE)])
|
||||
audio_cmd.extend([f'-b:a:{used_audio}', str(nzb2media.ABITRATE)])
|
||||
if audio_cmd[1] == 'copy':
|
||||
audio_cmd[1] = core.ACODEC
|
||||
if core.OUTPUTQUALITYPERCENT:
|
||||
audio_cmd[1] = nzb2media.ACODEC
|
||||
if nzb2media.OUTPUTQUALITYPERCENT:
|
||||
audio_cmd.extend(
|
||||
[f'-q:a:{used_audio}', str(core.OUTPUTQUALITYPERCENT)],
|
||||
[f'-q:a:{used_audio}', str(nzb2media.OUTPUTQUALITYPERCENT)],
|
||||
)
|
||||
if audio_cmd[1] == 'copy':
|
||||
audio_cmd[1] = core.ACODEC
|
||||
audio_cmd[1] = nzb2media.ACODEC
|
||||
if audio_cmd[1] in ['aac', 'dts']:
|
||||
audio_cmd[2:2] = ['-strict', '-2']
|
||||
|
||||
if core.ACODEC2_ALLOW:
|
||||
if nzb2media.ACODEC2_ALLOW:
|
||||
used_audio += 1
|
||||
try:
|
||||
audio5 = [
|
||||
item
|
||||
for item in audio1
|
||||
if item['codec_name'] in core.ACODEC2_ALLOW
|
||||
if item['codec_name'] in nzb2media.ACODEC2_ALLOW
|
||||
]
|
||||
except Exception:
|
||||
audio5 = []
|
||||
|
@ -514,7 +514,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
audio6 = [
|
||||
item
|
||||
for item in audio3
|
||||
if item['codec_name'] in core.ACODEC2_ALLOW
|
||||
if item['codec_name'] in nzb2media.ACODEC2_ALLOW
|
||||
]
|
||||
except Exception:
|
||||
audio6 = []
|
||||
|
@ -533,8 +533,8 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
a_mapped.extend([audio1[0]['index']])
|
||||
bitrate = int(float(audio1[0].get('bit_rate', 0))) / 1000
|
||||
channels = int(float(audio1[0].get('channels', 0)))
|
||||
if core.ACODEC2:
|
||||
audio_cmd2.extend([f'-c:a:{used_audio}', core.ACODEC2])
|
||||
if nzb2media.ACODEC2:
|
||||
audio_cmd2.extend([f'-c:a:{used_audio}', nzb2media.ACODEC2])
|
||||
else:
|
||||
audio_cmd2.extend([f'-c:a:{used_audio}', 'copy'])
|
||||
elif audio6: # wrong language, right codec
|
||||
|
@ -554,29 +554,29 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
a_mapped.extend([audio3[0]['index']])
|
||||
bitrate = int(float(audio3[0].get('bit_rate', 0))) / 1000
|
||||
channels = int(float(audio3[0].get('channels', 0)))
|
||||
if core.ACODEC2:
|
||||
audio_cmd2.extend([f'-c:a:{used_audio}', core.ACODEC2])
|
||||
if nzb2media.ACODEC2:
|
||||
audio_cmd2.extend([f'-c:a:{used_audio}', nzb2media.ACODEC2])
|
||||
else:
|
||||
audio_cmd2.extend([f'-c:a:{used_audio}', 'copy'])
|
||||
|
||||
if core.ACHANNELS2 and channels and channels > core.ACHANNELS2:
|
||||
if nzb2media.ACHANNELS2 and channels and channels > nzb2media.ACHANNELS2:
|
||||
audio_cmd2.extend(
|
||||
[f'-ac:a:{used_audio}', str(core.ACHANNELS2)],
|
||||
[f'-ac:a:{used_audio}', str(nzb2media.ACHANNELS2)],
|
||||
)
|
||||
if audio_cmd2[1] == 'copy':
|
||||
audio_cmd2[1] = core.ACODEC2
|
||||
if core.ABITRATE2 and not (
|
||||
core.ABITRATE2 * 0.9 < bitrate < core.ABITRATE2 * 1.1
|
||||
audio_cmd2[1] = nzb2media.ACODEC2
|
||||
if nzb2media.ABITRATE2 and not (
|
||||
nzb2media.ABITRATE2 * 0.9 < bitrate < nzb2media.ABITRATE2 * 1.1
|
||||
):
|
||||
audio_cmd2.extend([f'-b:a:{used_audio}', str(core.ABITRATE2)])
|
||||
audio_cmd2.extend([f'-b:a:{used_audio}', str(nzb2media.ABITRATE2)])
|
||||
if audio_cmd2[1] == 'copy':
|
||||
audio_cmd2[1] = core.ACODEC2
|
||||
if core.OUTPUTQUALITYPERCENT:
|
||||
audio_cmd2[1] = nzb2media.ACODEC2
|
||||
if nzb2media.OUTPUTQUALITYPERCENT:
|
||||
audio_cmd2.extend(
|
||||
[f'-q:a:{used_audio}', str(core.OUTPUTQUALITYPERCENT)],
|
||||
[f'-q:a:{used_audio}', str(nzb2media.OUTPUTQUALITYPERCENT)],
|
||||
)
|
||||
if audio_cmd2[1] == 'copy':
|
||||
audio_cmd2[1] = core.ACODEC2
|
||||
audio_cmd2[1] = nzb2media.ACODEC2
|
||||
if audio_cmd2[1] in ['aac', 'dts']:
|
||||
audio_cmd2[2:2] = ['-strict', '-2']
|
||||
|
||||
|
@ -587,7 +587,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
else:
|
||||
audio_cmd.extend(audio_cmd2)
|
||||
|
||||
if core.AINCLUDE and core.ACODEC3:
|
||||
if nzb2media.AINCLUDE and nzb2media.ACODEC3:
|
||||
audio_streams.extend(commentary) # add commentry tracks back here.
|
||||
for audio in audio_streams:
|
||||
if audio['index'] in a_mapped:
|
||||
|
@ -599,34 +599,34 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
audio_cmd3 = []
|
||||
bitrate = int(float(audio.get('bit_rate', 0))) / 1000
|
||||
channels = int(float(audio.get('channels', 0)))
|
||||
if audio['codec_name'] in core.ACODEC3_ALLOW:
|
||||
if audio['codec_name'] in nzb2media.ACODEC3_ALLOW:
|
||||
audio_cmd3.extend([f'-c:a:{used_audio}', 'copy'])
|
||||
else:
|
||||
if core.ACODEC3:
|
||||
audio_cmd3.extend([f'-c:a:{used_audio}', core.ACODEC3])
|
||||
if nzb2media.ACODEC3:
|
||||
audio_cmd3.extend([f'-c:a:{used_audio}', nzb2media.ACODEC3])
|
||||
else:
|
||||
audio_cmd3.extend([f'-c:a:{used_audio}', 'copy'])
|
||||
|
||||
if core.ACHANNELS3 and channels and channels > core.ACHANNELS3:
|
||||
if nzb2media.ACHANNELS3 and channels and channels > nzb2media.ACHANNELS3:
|
||||
audio_cmd3.extend(
|
||||
[f'-ac:a:{used_audio}', str(core.ACHANNELS3)],
|
||||
[f'-ac:a:{used_audio}', str(nzb2media.ACHANNELS3)],
|
||||
)
|
||||
if audio_cmd3[1] == 'copy':
|
||||
audio_cmd3[1] = core.ACODEC3
|
||||
if core.ABITRATE3 and not (
|
||||
core.ABITRATE3 * 0.9 < bitrate < core.ABITRATE3 * 1.1
|
||||
audio_cmd3[1] = nzb2media.ACODEC3
|
||||
if nzb2media.ABITRATE3 and not (
|
||||
nzb2media.ABITRATE3 * 0.9 < bitrate < nzb2media.ABITRATE3 * 1.1
|
||||
):
|
||||
audio_cmd3.extend(
|
||||
[f'-b:a:{used_audio}', str(core.ABITRATE3)],
|
||||
[f'-b:a:{used_audio}', str(nzb2media.ABITRATE3)],
|
||||
)
|
||||
if audio_cmd3[1] == 'copy':
|
||||
audio_cmd3[1] = core.ACODEC3
|
||||
if core.OUTPUTQUALITYPERCENT > 0:
|
||||
audio_cmd3[1] = nzb2media.ACODEC3
|
||||
if nzb2media.OUTPUTQUALITYPERCENT > 0:
|
||||
audio_cmd3.extend(
|
||||
[f'-q:a:{used_audio}', str(core.OUTPUTQUALITYPERCENT)],
|
||||
[f'-q:a:{used_audio}', str(nzb2media.OUTPUTQUALITYPERCENT)],
|
||||
)
|
||||
if audio_cmd3[1] == 'copy':
|
||||
audio_cmd3[1] = core.ACODEC3
|
||||
audio_cmd3[1] = nzb2media.ACODEC3
|
||||
if audio_cmd3[1] in ['aac', 'dts']:
|
||||
audio_cmd3[2:2] = ['-strict', '-2']
|
||||
audio_cmd.extend(audio_cmd3)
|
||||
|
@ -634,20 +634,20 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
s_mapped = []
|
||||
burnt = 0
|
||||
n = 0
|
||||
for lan in core.SLANGUAGES:
|
||||
for lan in nzb2media.SLANGUAGES:
|
||||
try:
|
||||
subs1 = [
|
||||
item for item in sub_streams if item['tags']['language'] == lan
|
||||
]
|
||||
except Exception:
|
||||
subs1 = []
|
||||
if core.BURN and not subs1 and not burnt and os.path.isfile(file):
|
||||
if nzb2media.BURN and not subs1 and not burnt and os.path.isfile(file):
|
||||
for subfile in get_subs(file):
|
||||
if lan in os.path.split(subfile)[1]:
|
||||
video_cmd.extend(['-vf', f'subtitles={subfile}'])
|
||||
burnt = 1
|
||||
for sub in subs1:
|
||||
if core.BURN and not burnt and os.path.isfile(input_file):
|
||||
if nzb2media.BURN and not burnt and os.path.isfile(input_file):
|
||||
subloc = 0
|
||||
for index in range(len(sub_streams)):
|
||||
if sub_streams[index]['index'] == sub['index']:
|
||||
|
@ -657,50 +657,50 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
['-vf', f'subtitles={input_file}:si={subloc}'],
|
||||
)
|
||||
burnt = 1
|
||||
if not core.ALLOWSUBS:
|
||||
if not nzb2media.ALLOWSUBS:
|
||||
break
|
||||
if (
|
||||
sub['codec_name'] in ['dvd_subtitle', 'VobSub']
|
||||
and core.SCODEC == 'mov_text'
|
||||
and nzb2media.SCODEC == 'mov_text'
|
||||
): # We can't convert these.
|
||||
continue
|
||||
map_cmd.extend(['-map', '0:{index}'.format(index=sub['index'])])
|
||||
s_mapped.extend([sub['index']])
|
||||
|
||||
if core.SINCLUDE:
|
||||
if nzb2media.SINCLUDE:
|
||||
for sub in sub_streams:
|
||||
if not core.ALLOWSUBS:
|
||||
if not nzb2media.ALLOWSUBS:
|
||||
break
|
||||
if sub['index'] in s_mapped:
|
||||
continue
|
||||
if (
|
||||
sub['codec_name'] in ['dvd_subtitle', 'VobSub']
|
||||
and core.SCODEC == 'mov_text'
|
||||
and nzb2media.SCODEC == 'mov_text'
|
||||
): # We can't convert these.
|
||||
continue
|
||||
map_cmd.extend(['-map', '0:{index}'.format(index=sub['index'])])
|
||||
s_mapped.extend([sub['index']])
|
||||
|
||||
if core.OUTPUTFASTSTART:
|
||||
if nzb2media.OUTPUTFASTSTART:
|
||||
other_cmd.extend(['-movflags', '+faststart'])
|
||||
if core.OTHEROPTS:
|
||||
other_cmd.extend(core.OTHEROPTS)
|
||||
if nzb2media.OTHEROPTS:
|
||||
other_cmd.extend(nzb2media.OTHEROPTS)
|
||||
|
||||
command = [core.FFMPEG, '-loglevel', 'warning']
|
||||
command = [nzb2media.FFMPEG, '-loglevel', 'warning']
|
||||
|
||||
if core.HWACCEL:
|
||||
if nzb2media.HWACCEL:
|
||||
command.extend(['-hwaccel', 'auto'])
|
||||
if core.GENERALOPTS:
|
||||
command.extend(core.GENERALOPTS)
|
||||
if nzb2media.GENERALOPTS:
|
||||
command.extend(nzb2media.GENERALOPTS)
|
||||
|
||||
command.extend(['-i', input_file])
|
||||
|
||||
if core.SEMBED and os.path.isfile(file):
|
||||
if nzb2media.SEMBED and os.path.isfile(file):
|
||||
for subfile in get_subs(file):
|
||||
sub_details, result = get_video_details(subfile)
|
||||
if not sub_details or not sub_details.get('streams'):
|
||||
continue
|
||||
if core.SCODEC == 'mov_text':
|
||||
if nzb2media.SCODEC == 'mov_text':
|
||||
subcode = [
|
||||
stream['codec_name'] for stream in sub_details['streams']
|
||||
]
|
||||
|
@ -730,11 +730,11 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
n += 1
|
||||
map_cmd.extend(['-map', f'{n}:0'])
|
||||
|
||||
if not core.ALLOWSUBS or (not s_mapped and not n):
|
||||
if not nzb2media.ALLOWSUBS or (not s_mapped and not n):
|
||||
sub_cmd.extend(['-sn'])
|
||||
else:
|
||||
if core.SCODEC:
|
||||
sub_cmd.extend(['-c:s', core.SCODEC])
|
||||
if nzb2media.SCODEC:
|
||||
sub_cmd.extend(['-c:s', nzb2media.SCODEC])
|
||||
else:
|
||||
sub_cmd.extend(['-c:s', 'copy'])
|
||||
|
||||
|
@ -746,7 +746,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
|
|||
command.extend(other_cmd)
|
||||
command.append(newfile_path)
|
||||
if platform.system() != 'Windows':
|
||||
command = core.NICENESS + command
|
||||
command = nzb2media.NICENESS + command
|
||||
return command, new_file
|
||||
|
||||
|
||||
|
@ -771,8 +771,8 @@ def extract_subs(file, newfile_path, bitbucket):
|
|||
if not video_details:
|
||||
return
|
||||
|
||||
if core.SUBSDIR:
|
||||
subdir = core.SUBSDIR
|
||||
if nzb2media.SUBSDIR:
|
||||
subdir = nzb2media.SUBSDIR
|
||||
else:
|
||||
subdir = os.path.split(newfile_path)[0]
|
||||
name = os.path.splitext(os.path.split(newfile_path)[1])[0]
|
||||
|
@ -782,9 +782,9 @@ def extract_subs(file, newfile_path, bitbucket):
|
|||
item
|
||||
for item in video_details['streams']
|
||||
if item['codec_type'] == 'subtitle'
|
||||
and item['tags']['language'] in core.SLANGUAGES
|
||||
and item['codec_name'] != 'hdmv_pgs_subtitle'
|
||||
and item['codec_name'] != 'pgssub'
|
||||
and item['tags']['language'] in nzb2media.SLANGUAGES
|
||||
and item['codec_name'] != 'hdmv_pgs_subtitle'
|
||||
and item['codec_name'] != 'pgssub'
|
||||
]
|
||||
except Exception:
|
||||
sub_streams = [
|
||||
|
@ -810,7 +810,7 @@ def extract_subs(file, newfile_path, bitbucket):
|
|||
output_file = os.path.join(subdir, f'{name}.{lan}.{n}.srt')
|
||||
|
||||
command = [
|
||||
core.FFMPEG,
|
||||
nzb2media.FFMPEG,
|
||||
'-loglevel',
|
||||
'warning',
|
||||
'-i',
|
||||
|
@ -822,7 +822,7 @@ def extract_subs(file, newfile_path, bitbucket):
|
|||
output_file,
|
||||
]
|
||||
if platform.system() != 'Windows':
|
||||
command = core.NICENESS + command
|
||||
command = nzb2media.NICENESS + command
|
||||
|
||||
logger.info(f'Extracting {lan} subtitle from: {file}')
|
||||
print_cmd(command)
|
||||
|
@ -857,14 +857,14 @@ def process_list(it, new_dir, bitbucket):
|
|||
ext = os.path.splitext(item)[1].lower()
|
||||
if (
|
||||
ext in ['.iso', '.bin', '.img']
|
||||
and ext not in core.IGNOREEXTENSIONS
|
||||
and ext not in nzb2media.IGNOREEXTENSIONS
|
||||
):
|
||||
logger.debug(f'Attempting to rip disk image: {item}', 'TRANSCODER')
|
||||
new_list.extend(rip_iso(item, new_dir, bitbucket))
|
||||
rem_list.append(item)
|
||||
elif (
|
||||
re.match('.+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]', item)
|
||||
and '.vob' not in core.IGNOREEXTENSIONS
|
||||
re.match('.+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]', item)
|
||||
and '.vob' not in nzb2media.IGNOREEXTENSIONS
|
||||
):
|
||||
logger.debug(f'Found VIDEO_TS image file: {item}', 'TRANSCODER')
|
||||
if not vts_path:
|
||||
|
@ -874,8 +874,8 @@ def process_list(it, new_dir, bitbucket):
|
|||
vts_path = os.path.split(item)[0]
|
||||
rem_list.append(item)
|
||||
elif (
|
||||
re.match('.+BDMV[/\\]SOURCE[/\\][0-9]+[0-9].[Mm][Tt][Ss]', item)
|
||||
and '.mts' not in core.IGNOREEXTENSIONS
|
||||
re.match('.+BDMV[/\\]SOURCE[/\\][0-9]+[0-9].[Mm][Tt][Ss]', item)
|
||||
and '.mts' not in nzb2media.IGNOREEXTENSIONS
|
||||
):
|
||||
logger.debug(f'Found MTS image file: {item}', 'TRANSCODER')
|
||||
if not mts_path:
|
||||
|
@ -890,7 +890,7 @@ def process_list(it, new_dir, bitbucket):
|
|||
'.+VTS_[0-9][0-9]_[0-9].', item,
|
||||
):
|
||||
rem_list.append(item)
|
||||
elif core.CONCAT and re.match('.+[cC][dD][0-9].', item):
|
||||
elif nzb2media.CONCAT and re.match('.+[cC][dD][0-9].', item):
|
||||
rem_list.append(item)
|
||||
combine.append(item)
|
||||
else:
|
||||
|
@ -942,7 +942,7 @@ def mount_iso(
|
|||
print_cmd(cmd)
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
||||
out, err = proc.communicate()
|
||||
core.MOUNTED = (
|
||||
nzb2media.MOUNTED = (
|
||||
mount_point # Allows us to verify this has been done and then cleanup.
|
||||
)
|
||||
for root, dirs, files in os.walk(mount_point):
|
||||
|
@ -950,7 +950,7 @@ def mount_iso(
|
|||
full_path = os.path.join(root, file)
|
||||
if (
|
||||
re.match('.+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]', full_path)
|
||||
and '.vob' not in core.IGNOREEXTENSIONS
|
||||
and '.vob' not in nzb2media.IGNOREEXTENSIONS
|
||||
):
|
||||
logger.debug(
|
||||
f'Found VIDEO_TS image file: {full_path}', 'TRANSCODER',
|
||||
|
@ -961,8 +961,8 @@ def mount_iso(
|
|||
vts_path = os.path.split(full_path)[0]
|
||||
return combine_vts(vts_path)
|
||||
elif (
|
||||
re.match('.+BDMV[/\\]STREAM[/\\][0-9]+[0-9].[Mm]', full_path)
|
||||
and '.mts' not in core.IGNOREEXTENSIONS
|
||||
re.match('.+BDMV[/\\]STREAM[/\\][0-9]+[0-9].[Mm]', full_path)
|
||||
and '.mts' not in nzb2media.IGNOREEXTENSIONS
|
||||
):
|
||||
logger.debug(
|
||||
f'Found MTS image file: {full_path}', 'TRANSCODER',
|
||||
|
@ -985,7 +985,7 @@ def rip_iso(item, new_dir, bitbucket):
|
|||
new_files = []
|
||||
failure_dir = 'failure'
|
||||
# Mount the ISO in your OS and call combineVTS.
|
||||
if not core.SEVENZIP:
|
||||
if not nzb2media.SEVENZIP:
|
||||
logger.debug(
|
||||
f'No 7zip installed. Attempting to mount image file {item}',
|
||||
'TRANSCODER',
|
||||
|
@ -1001,7 +1001,7 @@ def rip_iso(item, new_dir, bitbucket):
|
|||
)
|
||||
new_files = [failure_dir]
|
||||
return new_files
|
||||
cmd = [core.SEVENZIP, 'l', item]
|
||||
cmd = [nzb2media.SEVENZIP, 'l', item]
|
||||
try:
|
||||
logger.debug(
|
||||
f'Attempting to extract .vob or .mts from image file {item}',
|
||||
|
@ -1035,7 +1035,7 @@ def rip_iso(item, new_dir, bitbucket):
|
|||
break
|
||||
if not concat:
|
||||
break
|
||||
if core.CONCAT:
|
||||
if nzb2media.CONCAT:
|
||||
combined.extend(concat)
|
||||
continue
|
||||
name = '{name}.cd{x}'.format(
|
||||
|
@ -1066,7 +1066,7 @@ def rip_iso(item, new_dir, bitbucket):
|
|||
concat = []
|
||||
n += 1
|
||||
concat.append(mts_name)
|
||||
if core.CONCAT:
|
||||
if nzb2media.CONCAT:
|
||||
combined.extend(concat)
|
||||
continue
|
||||
name = '{name}.cd{x}'.format(
|
||||
|
@ -1074,7 +1074,7 @@ def rip_iso(item, new_dir, bitbucket):
|
|||
x=n,
|
||||
)
|
||||
new_files.append({item: {'name': name, 'files': concat}})
|
||||
if core.CONCAT and combined:
|
||||
if nzb2media.CONCAT and combined:
|
||||
name = os.path.splitext(os.path.split(item)[1])[0]
|
||||
new_files.append({item: {'name': name, 'files': combined}})
|
||||
if not new_files:
|
||||
|
@ -1109,7 +1109,7 @@ def combine_vts(vts_path):
|
|||
break
|
||||
if not concat:
|
||||
break
|
||||
if core.CONCAT:
|
||||
if nzb2media.CONCAT:
|
||||
combined.extend(concat)
|
||||
continue
|
||||
name = '{name}.cd{x}'.format(
|
||||
|
@ -1117,7 +1117,7 @@ def combine_vts(vts_path):
|
|||
x=n + 1,
|
||||
)
|
||||
new_files.append({vts_path: {'name': name, 'files': concat}})
|
||||
if core.CONCAT:
|
||||
if nzb2media.CONCAT:
|
||||
new_files.append({vts_path: {'name': name, 'files': combined}})
|
||||
return new_files
|
||||
|
||||
|
@ -1143,7 +1143,7 @@ def combine_mts(mts_path):
|
|||
for mts_name in mts_list: # need to sort all files [1 - 998].mts in order
|
||||
concat = []
|
||||
concat.append(os.path.join(mts_path, mts_name))
|
||||
if core.CONCAT:
|
||||
if nzb2media.CONCAT:
|
||||
combined.extend(concat)
|
||||
continue
|
||||
name = '{name}.cd{x}'.format(
|
||||
|
@ -1152,7 +1152,7 @@ def combine_mts(mts_path):
|
|||
)
|
||||
new_files.append({mts_path: {'name': name, 'files': concat}})
|
||||
n += 1
|
||||
if core.CONCAT:
|
||||
if nzb2media.CONCAT:
|
||||
new_files.append({mts_path: {'name': name, 'files': combined}})
|
||||
return new_files
|
||||
|
||||
|
@ -1188,12 +1188,12 @@ def print_cmd(command):
|
|||
|
||||
|
||||
def transcode_directory(dir_name):
|
||||
if not core.FFMPEG:
|
||||
if not nzb2media.FFMPEG:
|
||||
return 1, dir_name
|
||||
logger.info('Checking for files to be transcoded')
|
||||
final_result = 0 # initialize as successful
|
||||
if core.OUTPUTVIDEOPATH:
|
||||
new_dir = core.OUTPUTVIDEOPATH
|
||||
if nzb2media.OUTPUTVIDEOPATH:
|
||||
new_dir = nzb2media.OUTPUTVIDEOPATH
|
||||
make_dir(new_dir)
|
||||
name = os.path.splitext(os.path.split(dir_name)[1])[0]
|
||||
new_dir = os.path.join(new_dir, name)
|
||||
|
@ -1205,7 +1205,7 @@ def transcode_directory(dir_name):
|
|||
else:
|
||||
bitbucket = open('/dev/null')
|
||||
movie_name = os.path.splitext(os.path.split(dir_name)[1])[0]
|
||||
file_list = core.list_media_files(
|
||||
file_list = nzb2media.list_media_files(
|
||||
dir_name, media=True, audio=False, meta=False, archives=False,
|
||||
)
|
||||
file_list, rem_list, new_list, success = process_list(
|
||||
|
@ -1218,14 +1218,14 @@ def transcode_directory(dir_name):
|
|||
for file in file_list:
|
||||
if (
|
||||
isinstance(file, str)
|
||||
and os.path.splitext(file)[1] in core.IGNOREEXTENSIONS
|
||||
and os.path.splitext(file)[1] in nzb2media.IGNOREEXTENSIONS
|
||||
):
|
||||
continue
|
||||
command, file = build_commands(file, new_dir, movie_name, bitbucket)
|
||||
newfile_path = command[-1]
|
||||
|
||||
# transcoding files may remove the original file, so make sure to extract subtitles first
|
||||
if core.SEXTRACT and isinstance(file, str):
|
||||
if nzb2media.SEXTRACT and isinstance(file, str):
|
||||
extract_subs(file, newfile_path, bitbucket)
|
||||
|
||||
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
|
||||
|
@ -1267,13 +1267,13 @@ def transcode_directory(dir_name):
|
|||
except Exception:
|
||||
logger.error(f'Transcoding of video {newfile_path} has failed')
|
||||
|
||||
if core.SUBSDIR and result == 0 and isinstance(file, str):
|
||||
if nzb2media.SUBSDIR and result == 0 and isinstance(file, str):
|
||||
for sub in get_subs(file):
|
||||
name = os.path.splitext(os.path.split(file)[1])[0]
|
||||
subname = os.path.split(sub)[1]
|
||||
newname = os.path.splitext(os.path.split(newfile_path)[1])[0]
|
||||
newpath = os.path.join(
|
||||
core.SUBSDIR, subname.replace(name, newname),
|
||||
nzb2media.SUBSDIR, subname.replace(name, newname),
|
||||
)
|
||||
if not os.path.isfile(newpath):
|
||||
os.rename(sub, newpath)
|
||||
|
@ -1285,7 +1285,7 @@ def transcode_directory(dir_name):
|
|||
pass
|
||||
logger.info(f'Transcoding of video to {newfile_path} succeeded')
|
||||
if os.path.isfile(newfile_path) and (
|
||||
file in new_list or not core.DUPLICATE
|
||||
file in new_list or not nzb2media.DUPLICATE
|
||||
):
|
||||
try:
|
||||
os.unlink(file)
|
||||
|
@ -1297,16 +1297,16 @@ def transcode_directory(dir_name):
|
|||
)
|
||||
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
|
||||
final_result = final_result + result
|
||||
if core.MOUNTED: # In case we mounted an .iso file, unmount here.
|
||||
if nzb2media.MOUNTED: # In case we mounted an .iso file, unmount here.
|
||||
time.sleep(5) # play it safe and avoid failing to unmount.
|
||||
cmd = ['umount', '-l', core.MOUNTED]
|
||||
cmd = ['umount', '-l', nzb2media.MOUNTED]
|
||||
print_cmd(cmd)
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
||||
out, err = proc.communicate()
|
||||
time.sleep(5)
|
||||
os.rmdir(core.MOUNTED)
|
||||
core.MOUNTED = None
|
||||
if final_result == 0 and not core.DUPLICATE:
|
||||
os.rmdir(nzb2media.MOUNTED)
|
||||
nzb2media.MOUNTED = None
|
||||
if final_result == 0 and not nzb2media.DUPLICATE:
|
||||
for file in rem_list:
|
||||
try:
|
||||
os.unlink(file)
|
||||
|
@ -1318,7 +1318,7 @@ def transcode_directory(dir_name):
|
|||
os.rmdir(new_dir)
|
||||
new_dir = dir_name
|
||||
if (
|
||||
not core.PROCESSOUTPUT and core.DUPLICATE
|
||||
not nzb2media.PROCESSOUTPUT and nzb2media.DUPLICATE
|
||||
): # We postprocess the original files to CP/SB
|
||||
new_dir = dir_name
|
||||
bitbucket.close()
|
|
@ -3,62 +3,62 @@ from __future__ import annotations
|
|||
import os
|
||||
from subprocess import Popen
|
||||
|
||||
import core
|
||||
from core import logger, transcoder
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.paths import remove_dir
|
||||
from core.auto_process.common import ProcessResult
|
||||
import nzb2media
|
||||
from nzb2media import logger, transcoder
|
||||
from nzb2media.plugins.subtitles import import_subs
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.paths import remove_dir
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
|
||||
|
||||
def external_script(output_destination, torrent_name, torrent_label, settings):
|
||||
final_result = 0 # start at 0.
|
||||
num_files = 0
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = settings.get(
|
||||
nzb2media.USER_SCRIPT_MEDIAEXTENSIONS = settings.get(
|
||||
'user_script_mediaExtensions', '',
|
||||
)
|
||||
try:
|
||||
if isinstance(core.USER_SCRIPT_MEDIAEXTENSIONS, str):
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = (
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS.lower().split(',')
|
||||
if isinstance(nzb2media.USER_SCRIPT_MEDIAEXTENSIONS, str):
|
||||
nzb2media.USER_SCRIPT_MEDIAEXTENSIONS = (
|
||||
nzb2media.USER_SCRIPT_MEDIAEXTENSIONS.lower().split(',')
|
||||
)
|
||||
except Exception:
|
||||
logger.error(
|
||||
'user_script_mediaExtensions could not be set', 'USERSCRIPT',
|
||||
)
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = []
|
||||
nzb2media.USER_SCRIPT_MEDIAEXTENSIONS = []
|
||||
|
||||
core.USER_SCRIPT = settings.get('user_script_path', '')
|
||||
nzb2media.USER_SCRIPT = settings.get('user_script_path', '')
|
||||
|
||||
if not core.USER_SCRIPT or core.USER_SCRIPT == 'None':
|
||||
if not nzb2media.USER_SCRIPT or nzb2media.USER_SCRIPT == 'None':
|
||||
# do nothing and return success. This allows the user an option to Link files only and not run a script.
|
||||
return ProcessResult(
|
||||
status_code=0,
|
||||
message='No user script defined',
|
||||
)
|
||||
|
||||
core.USER_SCRIPT_PARAM = settings.get('user_script_param', '')
|
||||
nzb2media.USER_SCRIPT_PARAM = settings.get('user_script_param', '')
|
||||
try:
|
||||
if isinstance(core.USER_SCRIPT_PARAM, str):
|
||||
core.USER_SCRIPT_PARAM = core.USER_SCRIPT_PARAM.split(',')
|
||||
if isinstance(nzb2media.USER_SCRIPT_PARAM, str):
|
||||
nzb2media.USER_SCRIPT_PARAM = nzb2media.USER_SCRIPT_PARAM.split(',')
|
||||
except Exception:
|
||||
logger.error('user_script_params could not be set', 'USERSCRIPT')
|
||||
core.USER_SCRIPT_PARAM = []
|
||||
nzb2media.USER_SCRIPT_PARAM = []
|
||||
|
||||
core.USER_SCRIPT_SUCCESSCODES = settings.get('user_script_successCodes', 0)
|
||||
nzb2media.USER_SCRIPT_SUCCESSCODES = settings.get('user_script_successCodes', 0)
|
||||
try:
|
||||
if isinstance(core.USER_SCRIPT_SUCCESSCODES, str):
|
||||
core.USER_SCRIPT_SUCCESSCODES = (
|
||||
core.USER_SCRIPT_SUCCESSCODES.split(',')
|
||||
if isinstance(nzb2media.USER_SCRIPT_SUCCESSCODES, str):
|
||||
nzb2media.USER_SCRIPT_SUCCESSCODES = (
|
||||
nzb2media.USER_SCRIPT_SUCCESSCODES.split(',')
|
||||
)
|
||||
except Exception:
|
||||
logger.error('user_script_successCodes could not be set', 'USERSCRIPT')
|
||||
core.USER_SCRIPT_SUCCESSCODES = 0
|
||||
nzb2media.USER_SCRIPT_SUCCESSCODES = 0
|
||||
|
||||
core.USER_SCRIPT_CLEAN = int(settings.get('user_script_clean', 1))
|
||||
core.USER_SCRIPT_RUNONCE = int(settings.get('user_script_runOnce', 1))
|
||||
nzb2media.USER_SCRIPT_CLEAN = int(settings.get('user_script_clean', 1))
|
||||
nzb2media.USER_SCRIPT_RUNONCE = int(settings.get('user_script_runOnce', 1))
|
||||
|
||||
if core.CHECK_MEDIA:
|
||||
if nzb2media.CHECK_MEDIA:
|
||||
for video in list_media_files(
|
||||
output_destination,
|
||||
media=True,
|
||||
|
@ -78,7 +78,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
for dirpath, _, filenames in os.walk(output_destination):
|
||||
for file in filenames:
|
||||
|
||||
file_path = core.os.path.join(dirpath, file)
|
||||
file_path = nzb2media.os.path.join(dirpath, file)
|
||||
file_name, file_extension = os.path.splitext(file)
|
||||
logger.debug(
|
||||
f'Checking file {file} to see if this should be processed.',
|
||||
|
@ -86,16 +86,16 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
)
|
||||
|
||||
if (
|
||||
file_extension in core.USER_SCRIPT_MEDIAEXTENSIONS
|
||||
or 'all' in core.USER_SCRIPT_MEDIAEXTENSIONS
|
||||
file_extension in nzb2media.USER_SCRIPT_MEDIAEXTENSIONS
|
||||
or 'all' in nzb2media.USER_SCRIPT_MEDIAEXTENSIONS
|
||||
):
|
||||
num_files += 1
|
||||
if (
|
||||
core.USER_SCRIPT_RUNONCE == 1 and num_files > 1
|
||||
nzb2media.USER_SCRIPT_RUNONCE == 1 and num_files > 1
|
||||
): # we have already run once, so just continue to get number of files.
|
||||
continue
|
||||
command = [core.USER_SCRIPT]
|
||||
for param in core.USER_SCRIPT_PARAM:
|
||||
command = [nzb2media.USER_SCRIPT]
|
||||
for param in nzb2media.USER_SCRIPT_PARAM:
|
||||
if param == 'FN':
|
||||
command.append(f'{file}')
|
||||
continue
|
||||
|
@ -109,7 +109,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
command.append(f'{torrent_label}')
|
||||
continue
|
||||
elif param == 'DN':
|
||||
if core.USER_SCRIPT_RUNONCE == 1:
|
||||
if nzb2media.USER_SCRIPT_RUNONCE == 1:
|
||||
command.append(f'{output_destination}')
|
||||
else:
|
||||
command.append(f'{dirpath}')
|
||||
|
@ -127,7 +127,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
p = Popen(command)
|
||||
res = p.wait()
|
||||
if (
|
||||
str(res) in core.USER_SCRIPT_SUCCESSCODES
|
||||
str(res) in nzb2media.USER_SCRIPT_SUCCESSCODES
|
||||
): # Linux returns 0 for successful.
|
||||
logger.info(f'UserScript {command[0]} was successfull')
|
||||
result = 0
|
||||
|
@ -154,13 +154,13 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
file_name, file_extension = os.path.splitext(file)
|
||||
|
||||
if (
|
||||
file_extension in core.USER_SCRIPT_MEDIAEXTENSIONS
|
||||
or core.USER_SCRIPT_MEDIAEXTENSIONS == 'ALL'
|
||||
file_extension in nzb2media.USER_SCRIPT_MEDIAEXTENSIONS
|
||||
or nzb2media.USER_SCRIPT_MEDIAEXTENSIONS == 'ALL'
|
||||
):
|
||||
num_files_new += 1
|
||||
|
||||
if (
|
||||
core.USER_SCRIPT_CLEAN == int(1)
|
||||
nzb2media.USER_SCRIPT_CLEAN == int(1)
|
||||
and num_files_new == 0
|
||||
and final_result == 0
|
||||
):
|
||||
|
@ -168,7 +168,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
f'All files have been processed. Cleaning outputDirectory {output_destination}',
|
||||
)
|
||||
remove_dir(output_destination)
|
||||
elif core.USER_SCRIPT_CLEAN == int(1) and num_files_new != 0:
|
||||
elif nzb2media.USER_SCRIPT_CLEAN == int(1) and num_files_new != 0:
|
||||
logger.info(
|
||||
f'{num_files} files were processed, but {num_files_new} still remain. outputDirectory will not be cleaned.',
|
||||
)
|
|
@ -4,12 +4,12 @@ import os.path
|
|||
import typing
|
||||
import urllib.parse
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.utils.files import list_media_files
|
||||
from core.utils.files import move_file
|
||||
from core.utils.paths import clean_directory
|
||||
from core.utils.paths import flatten_dir
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media.utils.files import list_media_files
|
||||
from nzb2media.utils.files import move_file
|
||||
from nzb2media.utils.paths import clean_directory
|
||||
from nzb2media.utils.paths import flatten_dir
|
||||
|
||||
|
||||
def flatten(output_destination):
|
||||
|
@ -19,7 +19,7 @@ def flatten(output_destination):
|
|||
|
||||
|
||||
def clean_dir(path, section, subsection):
|
||||
cfg = dict(core.CFG[section][subsection])
|
||||
cfg = dict(nzb2media.CFG[section][subsection])
|
||||
min_size = int(cfg.get('minSize', 0))
|
||||
delete_ignored = int(cfg.get('delete_ignored', 0))
|
||||
try:
|
||||
|
@ -92,7 +92,7 @@ def process_dir(path, link):
|
|||
def get_dirs(section, subsection, link='hard'):
|
||||
to_return = []
|
||||
|
||||
watch_directory = core.CFG[section][subsection]['watch_dir']
|
||||
watch_directory = nzb2media.CFG[section][subsection]['watch_dir']
|
||||
directory = os.path.join(watch_directory, subsection)
|
||||
|
||||
if not os.path.exists(directory):
|
||||
|
@ -105,14 +105,14 @@ def get_dirs(section, subsection, link='hard'):
|
|||
f'Failed to add directories from {watch_directory} for post-processing: {e}',
|
||||
)
|
||||
|
||||
if core.USE_LINK == 'move':
|
||||
if nzb2media.USE_LINK == 'move':
|
||||
try:
|
||||
output_directory = os.path.join(core.OUTPUT_DIRECTORY, subsection)
|
||||
output_directory = os.path.join(nzb2media.OUTPUT_DIRECTORY, subsection)
|
||||
if os.path.exists(output_directory):
|
||||
to_return.extend(process_dir(output_directory, link))
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f'Failed to add directories from {core.OUTPUT_DIRECTORY} for post-processing: {e}',
|
||||
f'Failed to add directories from {nzb2media.OUTPUT_DIRECTORY} for post-processing: {e}',
|
||||
)
|
||||
|
||||
if not to_return:
|
|
@ -2,8 +2,8 @@ from __future__ import annotations
|
|||
|
||||
import datetime
|
||||
|
||||
from core import logger
|
||||
from core import main_db
|
||||
from nzb2media import logger
|
||||
from nzb2media import main_db
|
||||
|
||||
database = main_db.DBConnection()
|
||||
|
|
@ -2,8 +2,8 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def char_replace(name_in):
|
||||
|
@ -55,7 +55,7 @@ def char_replace(name_in):
|
|||
|
||||
def convert_to_ascii(input_name, dir_name):
|
||||
|
||||
ascii_convert = int(core.CFG['ASCII']['convert'])
|
||||
ascii_convert = int(nzb2media.CFG['ASCII']['convert'])
|
||||
if (
|
||||
ascii_convert == 0 or os.name == 'nt'
|
||||
): # just return if we don't want to convert or on windows os and '\' is replaced!.
|
|
@ -9,14 +9,14 @@ import time
|
|||
import beets.mediafile
|
||||
import guessit
|
||||
|
||||
import core
|
||||
from core import extractor
|
||||
from core import logger
|
||||
from core.utils.links import copy_link
|
||||
from core.utils.naming import is_sample
|
||||
from core.utils.naming import sanitize_name
|
||||
from core.utils.paths import get_dir_size
|
||||
from core.utils.paths import make_dir
|
||||
import nzb2media
|
||||
from nzb2media import extractor
|
||||
from nzb2media import logger
|
||||
from nzb2media.utils.links import copy_link
|
||||
from nzb2media.utils.naming import is_sample
|
||||
from nzb2media.utils.naming import sanitize_name
|
||||
from nzb2media.utils.paths import get_dir_size
|
||||
from nzb2media.utils.paths import make_dir
|
||||
|
||||
|
||||
def move_file(mediafile, path, link):
|
||||
|
@ -26,7 +26,7 @@ def move_file(mediafile, path, link):
|
|||
new_path = None
|
||||
file_ext = os.path.splitext(mediafile)[1]
|
||||
try:
|
||||
if file_ext in core.AUDIO_CONTAINER:
|
||||
if file_ext in nzb2media.AUDIO_CONTAINER:
|
||||
f = beets.mediafile.MediaFile(mediafile)
|
||||
|
||||
# get artist and album info
|
||||
|
@ -37,7 +37,7 @@ def move_file(mediafile, path, link):
|
|||
new_path = os.path.join(
|
||||
path, f'{sanitize_name(artist)} - {sanitize_name(album)}',
|
||||
)
|
||||
elif file_ext in core.MEDIA_CONTAINER:
|
||||
elif file_ext in nzb2media.MEDIA_CONTAINER:
|
||||
f = guessit.guessit(mediafile)
|
||||
|
||||
# get title
|
||||
|
@ -58,7 +58,7 @@ def move_file(mediafile, path, link):
|
|||
|
||||
# # Removed as encoding of directory no-longer required
|
||||
# try:
|
||||
# new_path = new_path.encode(core.SYS_ENCODING)
|
||||
# new_path = new_path.encode(nzb2media.SYS_ENCODING)
|
||||
# except Exception:
|
||||
# pass
|
||||
|
||||
|
@ -78,7 +78,7 @@ def move_file(mediafile, path, link):
|
|||
new_path, sanitize_name(os.path.split(mediafile)[1]),
|
||||
)
|
||||
try:
|
||||
newfile = newfile.encode(core.SYS_ENCODING)
|
||||
newfile = newfile.encode(nzb2media.SYS_ENCODING)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
@ -91,7 +91,7 @@ def is_min_size(input_name, min_size):
|
|||
|
||||
# audio files we need to check directory size not file size
|
||||
input_size = os.path.getsize(input_name)
|
||||
if file_ext in core.AUDIO_CONTAINER:
|
||||
if file_ext in nzb2media.AUDIO_CONTAINER:
|
||||
try:
|
||||
input_size = get_dir_size(os.path.dirname(input_name))
|
||||
except Exception:
|
||||
|
@ -107,7 +107,7 @@ def is_min_size(input_name, min_size):
|
|||
|
||||
def is_archive_file(filename):
|
||||
"""Check if the filename is allowed for the Archive."""
|
||||
for regext in core.COMPRESSED_CONTAINER:
|
||||
for regext in nzb2media.COMPRESSED_CONTAINER:
|
||||
if regext.search(filename):
|
||||
return regext.split(filename)[0]
|
||||
return False
|
||||
|
@ -136,9 +136,9 @@ def is_media_file(
|
|||
|
||||
return any(
|
||||
[
|
||||
(media and file_ext.lower() in core.MEDIA_CONTAINER),
|
||||
(audio and file_ext.lower() in core.AUDIO_CONTAINER),
|
||||
(meta and file_ext.lower() in core.META_CONTAINER),
|
||||
(media and file_ext.lower() in nzb2media.MEDIA_CONTAINER),
|
||||
(audio and file_ext.lower() in nzb2media.AUDIO_CONTAINER),
|
||||
(meta and file_ext.lower() in nzb2media.META_CONTAINER),
|
||||
(archives and is_archive_file(mediafile)),
|
||||
(other and (file_ext.lower() in otherext or 'all' in otherext)),
|
||||
],
|
|
@ -6,8 +6,8 @@ import re
|
|||
import guessit
|
||||
import requests
|
||||
|
||||
from core import logger
|
||||
from core.utils.naming import sanitize_name
|
||||
from nzb2media import logger
|
||||
from nzb2media.utils.naming import sanitize_name
|
||||
|
||||
|
||||
def find_imdbid(dir_name, input_name, omdb_api_key):
|
|
@ -5,8 +5,8 @@ import shutil
|
|||
|
||||
import linktastic
|
||||
|
||||
from core import logger
|
||||
from core.utils.paths import make_dir
|
||||
from nzb2media import logger
|
||||
from nzb2media.utils.paths import make_dir
|
||||
|
||||
try:
|
||||
from jaraco.windows.filesystem import islink, readlink
|
|
@ -6,8 +6,8 @@ import time
|
|||
|
||||
import requests
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def make_wake_on_lan_packet(mac_address):
|
||||
|
@ -44,7 +44,7 @@ def test_connection(host, port):
|
|||
|
||||
|
||||
def wake_up():
|
||||
wol = core.CFG['WakeOnLan']
|
||||
wol = nzb2media.CFG['WakeOnLan']
|
||||
host = wol['host']
|
||||
port = int(wol['port'])
|
||||
mac = wol['mac']
|
||||
|
@ -82,12 +82,12 @@ def server_responding(base_url):
|
|||
def find_download(client_agent, download_id):
|
||||
logger.debug(f'Searching for Download on {client_agent} ...')
|
||||
if client_agent == 'utorrent':
|
||||
torrents = core.TORRENT_CLASS.list()[1]['torrents']
|
||||
torrents = nzb2media.TORRENT_CLASS.list()[1]['torrents']
|
||||
for torrent in torrents:
|
||||
if download_id in torrent:
|
||||
return True
|
||||
if client_agent == 'transmission':
|
||||
torrents = core.TORRENT_CLASS.get_torrents()
|
||||
torrents = nzb2media.TORRENT_CLASS.get_torrents()
|
||||
for torrent in torrents:
|
||||
torrent_hash = torrent.hashString
|
||||
if torrent_hash == download_id:
|
||||
|
@ -95,18 +95,18 @@ def find_download(client_agent, download_id):
|
|||
if client_agent == 'deluge':
|
||||
return False
|
||||
if client_agent == 'qbittorrent':
|
||||
torrents = core.TORRENT_CLASS.torrents()
|
||||
torrents = nzb2media.TORRENT_CLASS.torrents()
|
||||
for torrent in torrents:
|
||||
if torrent['hash'] == download_id:
|
||||
return True
|
||||
if client_agent == 'sabnzbd':
|
||||
if 'http' in core.SABNZBD_HOST:
|
||||
base_url = f'{core.SABNZBD_HOST}:{core.SABNZBD_PORT}/api'
|
||||
if 'http' in nzb2media.SABNZBD_HOST:
|
||||
base_url = f'{nzb2media.SABNZBD_HOST}:{nzb2media.SABNZBD_PORT}/api'
|
||||
else:
|
||||
base_url = f'http://{core.SABNZBD_HOST}:{core.SABNZBD_PORT}/api'
|
||||
base_url = f'http://{nzb2media.SABNZBD_HOST}:{nzb2media.SABNZBD_PORT}/api'
|
||||
url = base_url
|
||||
params = {
|
||||
'apikey': core.SABNZBD_APIKEY,
|
||||
'apikey': nzb2media.SABNZBD_APIKEY,
|
||||
'mode': 'get_files',
|
||||
'output': 'json',
|
||||
'value': download_id,
|
|
@ -2,8 +2,8 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def parse_other(args):
|
||||
|
@ -62,7 +62,7 @@ def parse_deluge(args):
|
|||
input_id = args[1]
|
||||
try:
|
||||
input_category = (
|
||||
core.TORRENT_CLASS.core.get_torrent_status(input_id, ['label'])
|
||||
nzb2media.TORRENT_CLASS.core.get_torrent_status(input_id, ['label'])
|
||||
.get(b'label')
|
||||
.decode()
|
||||
)
|
||||
|
@ -98,8 +98,8 @@ def parse_synods(args):
|
|||
)
|
||||
torrent_id = os.getenv('TR_TORRENT_ID')
|
||||
input_id = f'dbid_{torrent_id}'
|
||||
# res = core.TORRENT_CLASS.tasks_list(additional_param='detail')
|
||||
res = core.TORRENT_CLASS.tasks_info(input_id, additional_param='detail')
|
||||
# res = nzb2media.TORRENT_CLASS.tasks_list(additional_param='detail')
|
||||
res = nzb2media.TORRENT_CLASS.tasks_info(input_id, additional_param='detail')
|
||||
logger.debug(f'result from syno {res}')
|
||||
if res['success']:
|
||||
try:
|
|
@ -6,8 +6,8 @@ import shutil
|
|||
import stat
|
||||
from functools import partial
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
def onerror(func, path, exc_info):
|
||||
|
@ -47,9 +47,9 @@ def make_dir(path):
|
|||
|
||||
|
||||
def remote_dir(path):
|
||||
if not core.REMOTE_PATHS:
|
||||
if not nzb2media.REMOTE_PATHS:
|
||||
return path
|
||||
for local, remote in core.REMOTE_PATHS:
|
||||
for local, remote in nzb2media.REMOTE_PATHS:
|
||||
if local in path:
|
||||
base_dirs = path.replace(local, '').split(os.sep)
|
||||
if '/' in remote:
|
||||
|
@ -136,7 +136,7 @@ def clean_directory(path, files):
|
|||
)
|
||||
return
|
||||
|
||||
if core.FORCE_CLEAN and not core.FAILED:
|
||||
if nzb2media.FORCE_CLEAN and not nzb2media.FAILED:
|
||||
logger.info(f'Doing Forceful Clean of {path}', 'CLEANDIR')
|
||||
remove_dir(path)
|
||||
return
|
|
@ -6,11 +6,11 @@ import subprocess
|
|||
import sys
|
||||
import typing
|
||||
|
||||
import core
|
||||
from core import APP_FILENAME
|
||||
from core import logger
|
||||
from core import SYS_ARGV
|
||||
from core import version_check
|
||||
import nzb2media
|
||||
from nzb2media import APP_FILENAME
|
||||
from nzb2media import logger
|
||||
from nzb2media import SYS_ARGV
|
||||
from nzb2media import version_check
|
||||
|
||||
if os.name == 'nt':
|
||||
from win32event import CreateMutex
|
||||
|
@ -22,7 +22,7 @@ class WindowsProcess:
|
|||
def __init__(self):
|
||||
self.mutex = None
|
||||
# {D0E858DF-985E-4907-B7FB-8D732C3FC3B9}
|
||||
_path_str = os.fspath(core.PID_FILE).replace('\\', '/')
|
||||
_path_str = os.fspath(nzb2media.PID_FILE).replace('\\', '/')
|
||||
self.mutexname = f'nzbtomedia_{_path_str}'
|
||||
self.CreateMutex = CreateMutex
|
||||
self.CloseHandle = CloseHandle
|
||||
|
@ -45,7 +45,7 @@ class WindowsProcess:
|
|||
|
||||
class PosixProcess:
|
||||
def __init__(self):
|
||||
self.pidpath = core.PID_FILE
|
||||
self.pidpath = nzb2media.PID_FILE
|
||||
self.lock_socket = None
|
||||
|
||||
def alreadyrunning(self):
|
|
@ -13,9 +13,9 @@ import traceback
|
|||
from urllib.request import urlretrieve
|
||||
|
||||
import cleanup
|
||||
import core
|
||||
from core import github_api as github
|
||||
from core import logger
|
||||
import nzb2media
|
||||
from nzb2media import github_api as github
|
||||
from nzb2media import logger
|
||||
|
||||
|
||||
class CheckVersion:
|
||||
|
@ -46,7 +46,7 @@ class CheckVersion:
|
|||
'source': running from source without git
|
||||
"""
|
||||
# check if we're a windows build
|
||||
if os.path.exists(os.path.join(core.APP_ROOT, '.git')):
|
||||
if os.path.exists(os.path.join(nzb2media.APP_ROOT, '.git')):
|
||||
install_type = 'git'
|
||||
else:
|
||||
install_type = 'source'
|
||||
|
@ -61,7 +61,7 @@ class CheckVersion:
|
|||
|
||||
force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced
|
||||
"""
|
||||
if not core.VERSION_NOTIFY and not force:
|
||||
if not nzb2media.VERSION_NOTIFY and not force:
|
||||
logger.log(
|
||||
'Version checking is disabled, not checking for the newest version',
|
||||
)
|
||||
|
@ -69,7 +69,7 @@ class CheckVersion:
|
|||
|
||||
logger.log(f'Checking if {self.install_type} needs an update')
|
||||
if not self.updater.need_update():
|
||||
core.NEWEST_VERSION_STRING = None
|
||||
nzb2media.NEWEST_VERSION_STRING = None
|
||||
logger.log('No update needed')
|
||||
return False
|
||||
|
||||
|
@ -85,13 +85,13 @@ class CheckVersion:
|
|||
|
||||
class UpdateManager:
|
||||
def get_github_repo_user(self):
|
||||
return core.GIT_USER
|
||||
return nzb2media.GIT_USER
|
||||
|
||||
def get_github_repo(self):
|
||||
return core.GIT_REPO
|
||||
return nzb2media.GIT_REPO
|
||||
|
||||
def get_github_branch(self):
|
||||
return core.GIT_BRANCH
|
||||
return nzb2media.GIT_BRANCH
|
||||
|
||||
|
||||
class GitUpdateManager(UpdateManager):
|
||||
|
@ -114,8 +114,8 @@ class GitUpdateManager(UpdateManager):
|
|||
def _find_working_git(self):
|
||||
test_cmd = 'version'
|
||||
|
||||
if core.GIT_PATH:
|
||||
main_git = f'"{core.GIT_PATH}"'
|
||||
if nzb2media.GIT_PATH:
|
||||
main_git = f'"{nzb2media.GIT_PATH}"'
|
||||
else:
|
||||
main_git = 'git'
|
||||
|
||||
|
@ -189,7 +189,7 @@ class GitUpdateManager(UpdateManager):
|
|||
try:
|
||||
logger.log(
|
||||
'Executing {cmd} with your shell in {directory}'.format(
|
||||
cmd=cmd, directory=core.APP_ROOT,
|
||||
cmd=cmd, directory=nzb2media.APP_ROOT,
|
||||
),
|
||||
logger.DEBUG,
|
||||
)
|
||||
|
@ -199,7 +199,7 @@ class GitUpdateManager(UpdateManager):
|
|||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=True,
|
||||
cwd=core.APP_ROOT,
|
||||
cwd=nzb2media.APP_ROOT,
|
||||
)
|
||||
output, err = p.communicate()
|
||||
exit_status = p.returncode
|
||||
|
@ -208,7 +208,7 @@ class GitUpdateManager(UpdateManager):
|
|||
|
||||
if output:
|
||||
output = output.strip()
|
||||
if core.LOG_GIT:
|
||||
if nzb2media.LOG_GIT:
|
||||
logger.log(f'git output: {output}', logger.DEBUG)
|
||||
|
||||
except OSError:
|
||||
|
@ -219,13 +219,13 @@ class GitUpdateManager(UpdateManager):
|
|||
if exit_status == 0:
|
||||
logger.log(f'{cmd} : returned successful', logger.DEBUG)
|
||||
exit_status = 0
|
||||
elif core.LOG_GIT and exit_status in (1, 128):
|
||||
elif nzb2media.LOG_GIT and exit_status in (1, 128):
|
||||
logger.log(
|
||||
f'{cmd} returned : {output}',
|
||||
logger.DEBUG,
|
||||
)
|
||||
else:
|
||||
if core.LOG_GIT:
|
||||
if nzb2media.LOG_GIT:
|
||||
logger.log(
|
||||
'{cmd} returned : {output}, treat as error for now'.format(
|
||||
cmd=cmd, output=output,
|
||||
|
@ -258,22 +258,22 @@ class GitUpdateManager(UpdateManager):
|
|||
return False
|
||||
self._cur_commit_hash = cur_commit_hash
|
||||
if self._cur_commit_hash:
|
||||
core.NZBTOMEDIA_VERSION = self._cur_commit_hash
|
||||
nzb2media.NZBTOMEDIA_VERSION = self._cur_commit_hash
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _find_git_branch(self):
|
||||
core.NZBTOMEDIA_BRANCH = self.get_github_branch()
|
||||
nzb2media.NZBTOMEDIA_BRANCH = self.get_github_branch()
|
||||
branch_info, err, exit_status = self._run_git(
|
||||
self._git_path, 'symbolic-ref -q HEAD',
|
||||
) # @UnusedVariable
|
||||
if exit_status == 0 and branch_info:
|
||||
branch = branch_info.strip().replace('refs/heads/', '', 1)
|
||||
if branch:
|
||||
core.NZBTOMEDIA_BRANCH = branch
|
||||
core.GIT_BRANCH = branch
|
||||
return core.GIT_BRANCH
|
||||
nzb2media.NZBTOMEDIA_BRANCH = branch
|
||||
nzb2media.GIT_BRANCH = branch
|
||||
return nzb2media.GIT_BRANCH
|
||||
|
||||
def _check_github_for_update(self):
|
||||
"""
|
||||
|
@ -421,7 +421,7 @@ class SourceUpdateManager(UpdateManager):
|
|||
|
||||
def _find_installed_version(self):
|
||||
|
||||
version_file = os.path.join(core.APP_ROOT, 'version.txt')
|
||||
version_file = os.path.join(nzb2media.APP_ROOT, 'version.txt')
|
||||
|
||||
if not os.path.isfile(version_file):
|
||||
self._cur_commit_hash = None
|
||||
|
@ -438,7 +438,7 @@ class SourceUpdateManager(UpdateManager):
|
|||
if not self._cur_commit_hash:
|
||||
self._cur_commit_hash = None
|
||||
else:
|
||||
core.NZBTOMEDIA_VERSION = self._cur_commit_hash
|
||||
nzb2media.NZBTOMEDIA_VERSION = self._cur_commit_hash
|
||||
|
||||
def need_update(self):
|
||||
|
||||
|
@ -516,7 +516,7 @@ class SourceUpdateManager(UpdateManager):
|
|||
def set_newest_text(self):
|
||||
|
||||
# if we're up to date then don't set this
|
||||
core.NEWEST_VERSION_STRING = None
|
||||
nzb2media.NEWEST_VERSION_STRING = None
|
||||
|
||||
if not self._cur_commit_hash:
|
||||
logger.log(
|
||||
|
@ -543,11 +543,11 @@ class SourceUpdateManager(UpdateManager):
|
|||
branch=self.branch,
|
||||
)
|
||||
)
|
||||
version_path = os.path.join(core.APP_ROOT, 'version.txt')
|
||||
version_path = os.path.join(nzb2media.APP_ROOT, 'version.txt')
|
||||
|
||||
try:
|
||||
# prepare the update dir
|
||||
sb_update_dir = os.path.join(core.APP_ROOT, 'sb-update')
|
||||
sb_update_dir = os.path.join(nzb2media.APP_ROOT, 'sb-update')
|
||||
|
||||
if os.path.isdir(sb_update_dir):
|
||||
logger.log(
|
||||
|
@ -612,7 +612,7 @@ class SourceUpdateManager(UpdateManager):
|
|||
# walk temp folder and move files to main folder
|
||||
logger.log(
|
||||
'Moving files from {source} to {destination}'.format(
|
||||
source=content_dir, destination=core.APP_ROOT,
|
||||
source=content_dir, destination=nzb2media.APP_ROOT,
|
||||
),
|
||||
)
|
||||
for dirname, _, filenames in os.walk(
|
||||
|
@ -621,7 +621,7 @@ class SourceUpdateManager(UpdateManager):
|
|||
dirname = dirname[len(content_dir) + 1 :]
|
||||
for curfile in filenames:
|
||||
old_path = os.path.join(content_dir, dirname, curfile)
|
||||
new_path = os.path.join(core.APP_ROOT, dirname, curfile)
|
||||
new_path = os.path.join(nzb2media.APP_ROOT, dirname, curfile)
|
||||
|
||||
# Avoid DLL access problem on WIN32/64
|
||||
# These files needing to be updated manually
|
|
@ -7,16 +7,16 @@ import cleanup
|
|||
eol.check()
|
||||
cleanup.clean(cleanup.FOLDER_STRUCTURE)
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.processor import nzbget, sab, manual
|
||||
from core.processor.nzb import process
|
||||
from core.auto_process.common import ProcessResult
|
||||
import nzb2media
|
||||
from nzb2media import logger
|
||||
from nzb2media.processor import nzbget, sab, manual
|
||||
from nzb2media.processor.nzb import process
|
||||
from nzb2media.auto_process.common import ProcessResult
|
||||
|
||||
|
||||
def main(args, section=None):
|
||||
# Initialize the config
|
||||
core.initialize(section)
|
||||
nzb2media.initialize(section)
|
||||
|
||||
logger.info('#########################################################')
|
||||
logger.info(f'## ..::[{os.path.basename(__file__)}]::.. ##')
|
||||
|
@ -44,7 +44,7 @@ def main(args, section=None):
|
|||
elif len(args) > 5 and args[5] == 'generic':
|
||||
logger.info('Script triggered from generic program')
|
||||
result = process(args[1], input_name=args[2], input_category=args[3], download_id=args[4])
|
||||
elif core.NZB_NO_MANUAL:
|
||||
elif nzb2media.NZB_NO_MANUAL:
|
||||
logger.warning('Invalid number of arguments received from client, and no_manual set')
|
||||
else:
|
||||
manual.process()
|
||||
|
@ -54,16 +54,16 @@ def main(args, section=None):
|
|||
if result.message:
|
||||
print(result.message + '!')
|
||||
if 'NZBOP_SCRIPTDIR' in os.environ: # return code for nzbget v11
|
||||
del core.MYAPP
|
||||
return core.NZBGET_POSTPROCESS_SUCCESS
|
||||
del nzb2media.MYAPP
|
||||
return nzb2media.NZBGET_POSTPROCESS_SUCCESS
|
||||
else:
|
||||
logger.error(f'A problem was reported in the {args[0]} script.')
|
||||
if result.message:
|
||||
print(result.message + '!')
|
||||
if 'NZBOP_SCRIPTDIR' in os.environ: # return code for nzbget v11
|
||||
del core.MYAPP
|
||||
return core.NZBGET_POSTPROCESS_ERROR
|
||||
del core.MYAPP
|
||||
del nzb2media.MYAPP
|
||||
return nzb2media.NZBGET_POSTPROCESS_ERROR
|
||||
del nzb2media.MYAPP
|
||||
return result.status_code
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#! /usr/bin/env python
|
||||
from __future__ import annotations
|
||||
|
||||
import core
|
||||
import nzb2media
|
||||
|
||||
|
||||
def test_eol():
|
||||
|
@ -39,9 +39,9 @@ def test_import_core_utils():
|
|||
|
||||
|
||||
def test_initial():
|
||||
core.initialize()
|
||||
del core.MYAPP
|
||||
nzb2media.initialize()
|
||||
del nzb2media.MYAPP
|
||||
|
||||
|
||||
def test_core_parameters():
|
||||
assert core.CHECK_MEDIA == 1
|
||||
assert nzb2media.CHECK_MEDIA == 1
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#! /usr/bin/env python
|
||||
from __future__ import annotations
|
||||
|
||||
import core
|
||||
from core import transcoder
|
||||
import nzb2media
|
||||
from nzb2media import transcoder
|
||||
|
||||
|
||||
def test_transcoder_check():
|
||||
assert transcoder.is_video_good(core.TEST_FILE, 1) is True
|
||||
assert transcoder.is_video_good(nzb2media.TEST_FILE, 1) is True
|
||||
|
|
11
tox.ini
11
tox.ini
|
@ -85,11 +85,10 @@ per-file-ignores =
|
|||
; E402 module level import not at top of file
|
||||
nzbTo*.py: E265, E266, E402
|
||||
TorrentToMedia.py: E402
|
||||
core/__init__.py: E402, F401
|
||||
core/utils/__init__.py: F401
|
||||
core/plugins/downloaders/configuration.py: F401
|
||||
core/plugins/downloaders/utils.py: F401
|
||||
libs/custom/deluge_client/__init__.py: F401
|
||||
nzb2media/__init__.py: E402, F401
|
||||
nzb2media/utils/__init__.py: F401
|
||||
nzb2media/plugins/downloaders/configuration.py: F401
|
||||
nzb2media/plugins/downloaders/utils.py: F401
|
||||
|
||||
[testenv:check]
|
||||
deps =
|
||||
|
@ -120,8 +119,6 @@ commands =
|
|||
flake8 --select=B902,B903,E123,E226,E241,E242,E704,W504,W505
|
||||
|
||||
[coverage:run]
|
||||
omit =
|
||||
libs/*
|
||||
|
||||
[testenv:codecov]
|
||||
deps =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue