Skip to content

Commit

Permalink
[change] Update best_quality.py (#3959)
Browse files Browse the repository at this point in the history
* [change] best_quality: can now return multiple best entries

The best_quality plugin was just considering the first entry as the best quality, and that's not always true, many entries can have the same quality as the best.

using "single_best = no" to activates this new mode

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
diogosena and pre-commit-ci[bot] committed Apr 2, 2024
1 parent bc0c3a3 commit 3b74ed5
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions flexget/plugins/filter/best_quality.py
Expand Up @@ -25,6 +25,10 @@ class FilterBestQuality:
'enum': ['accept', 'reject', 'do_nothing'],
'default': 'reject',
},
'single_best': {
'type': 'boolean',
'default': True,
},
},
'additionalProperties': False,
}
Expand Down Expand Up @@ -53,15 +57,26 @@ def on_task_filter(self, task, config):
# Sort entities in order of quality and best proper
entries.sort(key=lambda e: (e['quality'], e.get('proper_count', 0)), reverse=True)

# First entry will be the best quality
best = entries.pop(0)
if config['single_best']:
# First entry will be the best quality
best = entries.pop(0)

if action_on_best:
action_on_best(best, 'has the best quality for identifier %s' % identifier)
if action_on_best:
action_on_best(best, 'has the best quality for identifier %s' % identifier)

if action_on_lower:
if action_on_lower:
for entry in entries:
action_on_lower(entry, 'lower quality for identifier %s' % identifier)
else:
# Store the best quality for comparison
best_quality = entries[0]['quality']
for entry in entries:
action_on_lower(entry, 'lower quality for identifier %s' % identifier)
if action_on_best and entry['quality'] == best_quality:
action_on_best(
entry, 'has the best quality for identifier %s' % identifier
)
if action_on_lower and entry['quality'] < best_quality:
action_on_lower(entry, 'lower quality for identifier %s' % identifier)


@event('plugin.register')
Expand Down

0 comments on commit 3b74ed5

Please sign in to comment.