-
Notifications
You must be signed in to change notification settings - Fork 483
Expand file tree
/
Copy pathduplicates.py
More file actions
45 lines (35 loc) · 1.28 KB
/
duplicates.py
File metadata and controls
45 lines (35 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from loguru import logger
from flexget import plugin
from flexget.event import event
logger = logger.bind(name='duplicates')
class Duplicates:
"""Take action on entries with duplicate field values.
Example::
duplicates:
field: <field name>
action: [accept|reject]
"""
schema = {
'type': 'object',
'properties': {'field': {'type': 'string'}, 'action': {'enum': ['accept', 'reject']}},
'required': ['field', 'action'],
'additionalProperties': False,
}
def on_task_filter(self, task, config):
field = config['field']
action = config['action']
for entry in task.entries:
for prospect in task.entries:
if entry == prospect:
continue
if entry.get(field) is not None and entry[field] == prospect.get(field):
msg = 'Field {} value {} equals on {} and {}'.format(
field, entry[field], entry['title'], prospect['title']
)
if action == 'accept':
entry.accept(msg)
else:
entry.reject(msg)
@event('plugin.register')
def register_plugin():
plugin.register(Duplicates, 'duplicates', api_ver=2)