Implement hybrid quality definition logic

The hybrid quality is auto-generated and takes values between the anime
and non-anime tables in the following way:

* The lowest minimum and highest maximum between the non-anime and anime
  tables are used as the min/max for each quality in the generated
  hybrid table.
* Only 720/1080 qualities are "combined". Qualities outside of this,
  such as 2160, use the non-anime min/max values.
pull/5/head
Robert Dailey 3 years ago
parent c5cc2035a8
commit 607d2a8f6f

@ -132,8 +132,8 @@ class Sonarr(Server):
self.request('put', '/qualityDefinition/update', new_definition)
# --------------------------------------------------------------------------------------------------
def find_quality_definition_entry(self, new_definition, quality):
for entry in new_definition:
def find_quality_definition_entry(self, definition, quality):
for entry in definition:
if entry.get('quality').get('name') == quality:
return entry

@ -44,10 +44,11 @@ def find_existing_profile(profile_name, existing_profiles):
return None
# --------------------------------------------------------------------------------------------------
def quality_preview(name, definition):
print(name)
formats = ' {:<20} {:<10} {:<10}'
def quality_preview(definition):
print('')
formats = '{:<20} {:<10} {:<10}'
print(formats.format('Quality', 'Min', 'Max'))
print(formats.format('-------', '---', '---'))
for (quality, min, max) in definition:
print(formats.format(quality, min, max))
print('')

@ -1,4 +1,5 @@
import requests
import re
from app import guide
from app.api.sonarr import Sonarr
@ -43,22 +44,47 @@ def process_sonarr_profile(args, logger):
profile_to_update = guide.utils.find_existing_profile(new_profile_name, existing_profiles)
if profile_to_update:
print(f'Updating existing profile: {new_profile_name}')
logger.info(f'Updating existing profile: {new_profile_name}')
sonarr.update_existing_profile(profile_to_update, profile, tag_ids)
else:
print(f'Creating new profile: {new_profile_name}')
logger.info(f'Creating new profile: {new_profile_name}')
sonarr.create_release_profile(new_profile_name, profile, tag_ids)
def process_sonarr_quality(args, logger):
guide_definitions = quality.parse_markdown(logger, quality.get_markdown())
if args.type == 'sonarr:hybrid':
raise ValueError('Hybrid profile not implemented yet')
hybrid_quality_regex = re.compile(r'720|1080')
anime = guide_definitions.get('sonarr:anime')
nonanime = guide_definitions.get('sonarr:non-anime')
if len(anime) != len(nonanime):
raise RuntimeError('For some reason the anime and non-anime quality definitions are not the same length')
logger.info('Notice: Hybrid only functions on 720/1080 qualities and uses non-anime values for the rest (e.g. 2160)')
hybrid = []
for i in range(len(nonanime)):
left = nonanime[i]
if not hybrid_quality_regex.search(left[0]):
logger.debug('Ignored Quality: ' + left[0])
hybrid.append(left)
else:
right = None
for r in anime:
if r[0] == left[0]:
right = r
if right is None:
raise RuntimeError(f'Could not find matching anime quality for non-anime quality named: {left[0]}')
hybrid.append((left[0], min(left[1], right[1]), max(left[2], right[2])))
guide_definitions['sonarr:hybrid'] = hybrid
selected_definition = guide_definitions.get(args.type)
if args.preview:
utils.quality_preview(args.type, selected_definition)
utils.quality_preview(selected_definition)
exit(0)
print(f'Updating quality definition using {args.type}')

Loading…
Cancel
Save