-
Notifications
You must be signed in to change notification settings - Fork 472
/
metainfo_movie.py
56 lines (46 loc) · 1.76 KB
/
metainfo_movie.py
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
46
47
48
49
50
51
52
53
54
55
56
from loguru import logger
from flexget import plugin
from flexget.event import event
try:
# NOTE: Importing other plugins is discouraged!
from flexget.components.parsing.parsers import parser_common as plugin_parser_common
except ImportError:
raise plugin.DependencyError(issued_by=__name__, missing='parser_common')
logger = logger.bind(name='metainfo_movie')
class MetainfoMovie:
"""
Check if entry appears to be a movie, and populate movie info if so.
"""
schema = {'type': 'boolean'}
def on_task_metainfo(self, task, config):
# Don't run if we are disabled
if config is False:
return
for entry in task.entries:
# If movie parser already parsed this, don't touch it.
if entry.get('movie_name'):
continue
self.guess_entry(entry)
@staticmethod
def guess_entry(entry):
"""
Populates movie_* fields for entries that are successfully parsed.
:param entry: Entry that's being processed
:return: True for successful parse
"""
if entry.get('movie_guessed'):
# Return true if we already parsed this
return True
parser = plugin.get('parsing', 'metainfo_movie').parse_movie(data=entry['title'])
if parser and parser.valid:
parser.name = plugin_parser_common.normalize_name(
plugin_parser_common.remove_dirt(parser.name)
)
for field, value in parser.fields.items():
if not entry.is_lazy(field) and not entry.get(field):
entry[field] = value
return True
return False
@event('plugin.register')
def register_plugin():
plugin.register(MetainfoMovie, 'metainfo_movie', api_ver=2)