Generic upgrade and timeframe plugins#2036
Conversation
flexget/plugins/filter/upgrade.py
Outdated
|
|
||
| def prepare_config(self, config): | ||
| if not config or isinstance(config, bool): | ||
| return {'identified_by': 'auto', 'on_lower': 'skip', 'tracking': True} |
There was a problem hiding this comment.
I'd rather the defaults were set only in prepare_config with dict.setdefault(). We don't really want to maintain the default values in two places
There was a problem hiding this comment.
I wish there was a better way.. I wish we didn't near prepare_config at all. But we need it because it's oneOf
flexget/plugins/filter/upgrade.py
Outdated
|
|
||
| # Action lower qualities | ||
| if config['on_lower'] != 'skip': | ||
| entry_actions = { |
There was a problem hiding this comment.
Minor thing: You're recreating this dict for every identifier.
There was a problem hiding this comment.
moved to module level
flexget/plugins/filter/upgrade.py
Outdated
| # Group by Identifier | ||
| for entry in entries: | ||
| identifier = entry.get('id') if identified_by == 'auto' else entry.render(identified_by) | ||
| if identifier: |
There was a problem hiding this comment.
Just my personal preference, I prefer to keep the flow control leaner:
if not identifier:
log.debug('No identifier found for', entry['title'])
continue
grouped_entries[identifier.lower()].append(entry)just a suggestion obviously
flexget/plugins/filter/upgrade.py
Outdated
| target_downloaded = False | ||
|
|
||
| if config['target']: | ||
| target_quality = qualities.Quality(config['target']) |
There was a problem hiding this comment.
what is returned if the user inserted a quality requirement and not a quality?
There was a problem hiding this comment.
based on my tests it returns the highest quality
flexget/plugins/filter/upgrade.py
Outdated
| target_quality = qualities.Quality(config['target']) | ||
| target_requirement = qualities.Requirements(config['target']) | ||
| # Filter out entries within target | ||
| entries = list(filter(lambda e: target_requirement.allows(e['quality']), entries)) |
There was a problem hiding this comment.
i like list comprehension here better too...
entries = [e if target_requirement.allows(e['quality']) for e in entries]There was a problem hiding this comment.
but it should filter out ones that don't match? that will just include them all again.. you are missing the else part..
There was a problem hiding this comment.
since it runs on the same variable it'll just recreate it with those matching the statement. no need for else in list comprehension
There was a problem hiding this comment.
entries = [e if target_requirement.allows(e['quality']) for e in entries] is not valid tho? You need an else after the if?
There was a problem hiding this comment.
oops sorry:
entries = [e for e in entries if target_requirement.allows(e['quality'])]
flexget/plugins/filter/upgrade.py
Outdated
| continue | ||
|
|
||
| # We may have no entries within target | ||
| if len(entries) == 0: |
There was a problem hiding this comment.
more pythonic to write if not entries
There was a problem hiding this comment.
already fixed this, will push later
flexget/plugins/filter/upgrade.py
Outdated
|
|
||
| # Action lower qualities | ||
| if config['on_lower'] != 'skip': | ||
| for entry in entries: |
There was a problem hiding this comment.
shouldnt you pop the first entry to not iterate over it twice?
There was a problem hiding this comment.
not sure it really matters?
There was a problem hiding this comment.
well i think itll try to accept it twice, not sure if that's an issue or not
flexget/plugins/filter/upgrade.py
Outdated
| _quality = Column('quality', String) | ||
| quality = quality_property('_quality') | ||
| proper = Column(Boolean) | ||
| added = Column(DateTime, index=True) |
There was a problem hiding this comment.
you can set default=datetime.now() here and not handle in via the plugin
flexget/plugins/filter/upgrade.py
Outdated
| existing = EntryUpgrade() | ||
| existing.id = identifier | ||
| session.add(existing) | ||
| else: |
flexget/plugins/filter/upgrade.py
Outdated
| for entry in entries: | ||
| action = entry_actions[config['on_lower']] | ||
| if entry['quality'] > existing.quality and target_downloaded: | ||
| msg = 'on_lower %s because already at target quality' % config['on_lower'] |
There was a problem hiding this comment.
These messages sound weird. Maybe create a mapping between the config values and the proper tense. And remove the on_lower portion.
Secondly, I think it would be better to change the if-blocks to
if something:
do stuff
elif other something:
do other stuff
elif third something:
do third stuff
else:
continue
action(entry, msg)
flexget/plugins/filter/upgrade.py
Outdated
| # No existing, skip | ||
| continue | ||
|
|
||
| target_downloaded = False |
There was a problem hiding this comment.
I'm assuming this will be used somehow later, so this is just a reminder that this variable is currently never True.
There was a problem hiding this comment.
yeah for later use, still wip
flexget/plugins/filter/upgrade.py
Outdated
| # Action lower qualities | ||
| if config['on_lower'] != 'skip': | ||
| for entry in entries: | ||
| if entry == best: |
There was a problem hiding this comment.
No need for this since you used pop
…oosely (ignore fields that are set by other plugins such as movie_name from imdb_lookup)
flexget/plugins/filter/timeframe.py
Outdated
| proper_count = Column(Integer, default=0) | ||
|
|
||
| def __init__(self): | ||
| self.first_seen = datetime.now() |
There was a problem hiding this comment.
no need for this, you init it in the column declaration
flexget/plugins/filter/timeframe.py
Outdated
|
|
||
| def __init__(self): | ||
| self.first_seen = datetime.now() | ||
| self.updated = datetime.now() |
There was a problem hiding this comment.
you didn't create a corresponding column for updated
| try: | ||
| self.backlog = plugin.get_plugin_by_name('backlog') | ||
| except plugin.DependencyError: | ||
| log.warning('Unable to utilize backlog plugin, so episodes may slip through timeframe.') |
There was a problem hiding this comment.
add self.backlog = None or it will crash later on
flexget/plugins/filter/timeframe.py
Outdated
| identified_by = '{{ id }}' if config['identified_by'] == 'auto' else config['identified_by'] | ||
|
|
||
| grouped_entries = group_entries(task.accepted + task.undecided, identified_by) | ||
| if len(grouped_entries) == 0: |
There was a problem hiding this comment.
if not grouped_entries: is more pythonic
flexget/plugins/filter/timeframe.py
Outdated
|
|
||
| id_timeframe.title = best_entry['title'] | ||
| id_timeframe.quality = best_entry['quality'] | ||
| id_timeframe.title = best_entry.get('proper_count', 0) |
There was a problem hiding this comment.
you probably meant id_timeframe.proper_count here
flexget/plugins/filter/timeframe.py
Outdated
| identified_by = '{{ id }}' if config['identified_by'] == 'auto' else config['identified_by'] | ||
|
|
||
| grouped_entries = group_entries(task.accepted, identified_by) | ||
| if len(grouped_entries) == 0: |
flexget/plugins/filter/upgrade.py
Outdated
| first_seen = Column(DateTime, default=datetime.now) | ||
| updated = Column(DateTime, index=True, default=datetime.now) | ||
|
|
||
| def __init__(self): |
There was a problem hiding this comment.
no need to init, you declared the defaults already
flexget/plugins/filter/upgrade.py
Outdated
| } | ||
|
|
||
| def prepare_config(self, config): | ||
| if config is None or config is False: |
flexget/plugins/filter/upgrade.py
Outdated
| identified_by = '{{ id }}' if config['identified_by'] == 'auto' else config['identified_by'] | ||
|
|
||
| grouped_entries = group_entries(task.accepted + task.undecided, identified_by) | ||
| if len(grouped_entries) == 0: |
flexget/plugins/filter/upgrade.py
Outdated
| identified_by = '{{ id }}' if config['identified_by'] == 'auto' else config['identified_by'] | ||
|
|
||
| grouped_entries = group_entries(task.accepted, identified_by) | ||
| if len(grouped_entries) == 0: |
|
Reviewed by @liiight |
Motivation for changes:
Currently, flexget does not support the concept of movie upgrade/timeframes. Series upgrades/timeframe are possible but the code is messy. There is no easy/generic way to upgrade entry qualities or wait for a timeframe before accepting the best quality.
Detailed changes:
The following plugins are meant to support generic timeframes/upgrades by tracking new field
id. This field is set by metainfo plugins.