Repository: Flexget/Flexget

Issue:
Add Scene group name as field for movies
Currently guessit can pick the release group name very easily. Here are some examples.

```
root@nb:/media/7283242e-cb09-40ea-a27e-a91e58cd3dc6/videos/peliculas # guessit The.Master.2012.DVDRiP.AC3-5.1.XviD-AXED/
For: The.Master.2012.DVDRiP.AC3-5.1.XviD-AXED/
GuessIt found: {
    "title": "The Master", 
    "year": 2012, 
    "format": "DVD", 
    "audio_codec": "AC3", 
    "audio_channels": "5.1", 
    "video_codec": "XviD", 
    "release_group": "AXED", 
    "type": "movie"
}
root@nb:/media/7283242e-cb09-40ea-a27e-a91e58cd3dc6/videos/peliculas # guessit Kingsman.The.Secret.Service.2014.HC.HDRiip.XviD.AC3-EVO
For: Kingsman.The.Secret.Service.2014.HC.HDRiip.XviD.AC3-EVO
GuessIt found: {
    "title": "Kingsman The Secret Service", 
    "year": 2014, 
    "episode_title": "HC HDRiip", 
    "video_codec": "XviD", 
    "audio_codec": "AC3", 
    "release_group": "EVO", 
    "type": "movie"
}
root@nb:/media/7283242e-cb09-40ea-a27e-a91e58cd3dc6/videos/peliculas # guessit What.We.Did.on.Our.Holiday.2014.BDRip.X264-AMIABLE
For: What.We.Did.on.Our.Holiday.2014.BDRip.X264-AMIABLE
GuessIt found: {
    "title": "What We Did on Our Holiday", 
    "year": 2014, 
    "format": "BluRay", 
    "video_codec": "h264", 
    "release_group": "AMIABLE", 
    "type": "movie"
}
```

Would it be possible to add this field in an entry so it can be used in jinja2 templates for renaming?



Discussion:
Set the parser to guessit and it will be available in `{{ release_group }}`.

```
parsing:
  series: guessit
  movie: guessit
```

Sorry for opening again but at a quick look this appears to only work for series 

This is the task

```
  sort-movies:
    parsing:
      movie: guessit
    imdb_lookup: yes
    manual: yes
    filesystem:
      path: /movies_incoming
      recursive: true
      mask: '*.mkv'
    accept_all: yes 
    move:
      to: "/test/{{movie_name}} ({{movie_year}})"
      allow_dir: yes
      keep_extension: yes
      filename: '{{movie_name}} {{movie_year}} {{ quality|replace("h264","x264") }} {{ release_group }}'
      along:
        - sub
        - srt
      clean_source: 500
```

This is the output in test mode

http://hastebin.com/aramusefiq.rb

Only series has the field `release_group` it seems.


Resolving patch:
diff --git a/flexget/plugins/metainfo/metainfo_movie.py b/flexget/plugins/metainfo/metainfo_movie.py
new file mode 100644
--- /dev/null
+++ b/flexget/plugins/metainfo/metainfo_movie.py
@@ -0,0 +1,51 @@
+from __future__ import unicode_literals, division, absolute_import
+from builtins import *  # pylint: disable=unused-import, redefined-builtin
+
+import logging
+
+from flexget.plugins.parsers.parser_common import normalize_name, remove_dirt
+from flexget import plugin
+from flexget.event import event
+from flexget.plugin import get_plugin_by_name
+
+log = logging.getLogger('metainfo_movie')
+
+
+class MetainfoMovie(object):
+    """
+    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 = get_plugin_by_name('parsing').instance.parse_movie(data=entry['title'])
+        if parser and parser.valid:
+            parser.name = normalize_name(remove_dirt(parser.name))
+            parser.populate_entry_fields(entry)
+            return True
+        return False
+
+
+@event('plugin.register')
+def register_plugin():
+    plugin.register(MetainfoMovie, 'metainfo_movie', api_ver=2)
diff --git a/flexget/plugins/parsers/parser_guessit.py b/flexget/plugins/parsers/parser_guessit.py
--- a/flexget/plugins/parsers/parser_guessit.py
+++ b/flexget/plugins/parsers/parser_guessit.py
@@ -18,7 +18,6 @@
 from .parser_common import old_assume_quality
 from .parser_common import ParsedEntry, ParsedVideoQuality, ParsedVideo, ParsedSerie, ParsedMovie
 
-
 log = logging.getLogger('parser_guessit')
 
 logging.getLogger('rebulk').setLevel(logging.WARNING)
@@ -177,6 +176,25 @@ def __init__(self, data, name, guess_result, **kwargs):
     def title(self):
         return self._guess_result.get('title')
 
+    def populate_entry_fields(self, entry):
+        """ Populates entry fields based on parser data"""
+        entry['movie_parser'] = self
+        entry['movie_name'] = self.name
+        entry['movie_year'] = self.year
+        entry['proper'] = self.proper
+        entry['proper_count'] = self.proper_count
+        entry['release_group'] = self.parsed_group
+        entry['is_3d'] = self.is_3d
+        entry['subtitle_languages'] = self.subtitle_languages
+        entry['languages'] = self.languages
+        entry['video_codec'] = self.quality2.video_codec
+        entry['format'] = self.quality2.format
+        entry['audio_codec'] = self.quality2.audio_codec
+        entry['video_profile'] = self.quality2.video_profile
+        entry['screen_size'] = self.quality2.screen_size
+        entry['audio_channels'] = self.quality2.audio_channels
+        entry['audio_profile'] = self.quality2.audio_profile
+
 
 class GuessitParsedSerie(GuessitParsedVideo, ParsedSerie):
     part_re = re.compile('part\\s?(\\d+)', re.IGNORECASE)
@@ -260,6 +278,7 @@ def parsed_season(self):
     def valid_strict(self):
         return True
 
+
 def _id_regexps_function(input_string, context):
     ret = []
     for regexp in context.get('id_regexps'):
@@ -267,10 +286,13 @@ def _id_regexps_function(input_string, context):
             ret.append(match.span)
     return ret
 
-_id_regexps = Rebulk().functional(_id_regexps_function, name='regexpId', disabled=lambda context: not context.get('id_regexps'))
+
+_id_regexps = Rebulk().functional(_id_regexps_function, name='regexpId',
+                                  disabled=lambda context: not context.get('id_regexps'))
 
 guessit_api = GuessItApi(rebulk_builder().rebulk(_id_regexps))
 
+
 class ParserGuessit(object):
     def _guessit_options(self, options):
         settings = {'name_only': True, 'allowed_languages': ['en', 'fr'], 'allowed_countries': ['us', 'uk', 'gb']}
diff --git a/flexget/utils/titles/movie.py b/flexget/utils/titles/movie.py
--- a/flexget/utils/titles/movie.py
+++ b/flexget/utils/titles/movie.py
@@ -26,6 +26,14 @@ def __init__(self):
         self.reset()
         TitleParser.__init__(self)
 
+    def populate_entry_fields(self, entry):
+        """ Populates entry fields based on parser data"""
+        entry['movie_parser'] = self
+        entry['movie_name'] = self.name
+        entry['movie_year'] = self.year
+        entry['proper'] = self.proper
+        entry['proper_count'] = self.proper_count
+
     @property
     def valid(self):
         return True


Test patch:
diff --git a/tests/test_metainfo.py b/tests/test_metainfo.py
--- a/tests/test_metainfo.py
+++ b/tests/test_metainfo.py
@@ -5,7 +5,6 @@
 
 
 class TestMetainfo(object):
-
     config = """
         tasks:
           test_content_size:
@@ -24,7 +23,6 @@ def test_content_size(self, execute_task):
 
 
 class TestMetainfoImdb(object):
-
     config = """
         tasks:
           test:
@@ -49,7 +47,6 @@ def test_imdb(self, execute_task):
 
 
 class TestMetainfoQuality(object):
-
     config = """
         tasks:
           test:
@@ -141,3 +138,69 @@ def test_false_positives(self, execute_task):
             assert 'series_name' not in entry, error
             assert 'series_guessed' not in entry, error
             assert 'series_parser' not in entry, error
+
+
+class TestMetainfoMovie(object):
+    config = """
+        templates:
+          global:
+            metainfo_movie: yes
+        tasks:
+          test:
+            mock:
+              - {title: 'FlexGet.720p.HDTV.xvid-TheName'}
+              - {title: 'FlexGet2 (1999).720p.HDTV.xvid-TheName'}
+              - {title: 'FlexGet3 (2004).PROPER.1080p.BluRay.xvid-TheName'}
+          test_guessit:
+            parsing:
+              movie: guessit
+            mock:
+              - {title: 'FlexGet.720p.HDTV.xvid-TheName'}
+              - {title: 'FlexGet3 (2004).PROPER.1080p.BluRay.xvid-TheName'}
+              - {title: 'The.Flexget.2000.BluRay.Remux.1080p.AVC.TrueHD.5.1-FQ'}
+              - {title: 'The.Flexget.Winters.War.2016.1080p.WEB-DL.H264.AC3-FlexO'}
+    """
+
+    def test_metainfo_movie(self, execute_task):
+        task = execute_task('test')
+        assert task.find_entry(movie_name='Flexget',
+                               quality='720p hdtv xvid')
+        assert task.find_entry(movie_name='Flexget2',
+                               movie_year=1999,
+                               quality='720p hdtv xvid')
+        assert task.find_entry(movie_name='Flexget3',
+                               movie_year=2004,
+                               proper=True,
+                               quality='1080p BluRay xvid')
+
+    def test_metainfo_movie_with_guessit(self, execute_task):
+        task = execute_task('test_guessit')
+        assert task.find_entry(movie_name='Flexget',
+                               format='HDTV',
+                               screen_size='720p',
+                               video_codec='XviD',
+                               release_group='TheName')
+
+        assert task.find_entry(movie_name='Flexget3',
+                               movie_year=2004,
+                               proper=True,
+                               format='BluRay',
+                               screen_size='1080p',
+                               video_codec='XviD',
+                               release_group='TheName')
+
+        assert task.find_entry(movie_name='The Flexget',
+                               audio_channels='5.1',
+                               audio_codec='TrueHD',
+                               movie_year=2000,
+                               format='BluRay',
+                               screen_size='1080p',
+                               release_group='FQ')
+
+        assert task.find_entry(movie_name='The Flexget Winters War',
+                               audio_codec='AC3',
+                               movie_year=2016,
+                               format='WEB-DL',
+                               screen_size='1080p',
+                               video_codec='h264',
+                               release_group='FlexO')