We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[subliminal] Support downloading subtitles to different directory
Already supported by the subliminal API, patch just adds a config option for it.

```
--- subtitles_subliminal.py.orig    2016-04-20 06:07:33.873933998 -0300
+++ subtitles_subliminal.py 2016-04-20 06:12:29.070504077 -0300
@@ -42,6 +42,7 @@
           exact_match: no
           providers: addic7ed, opensubtitles
           single: no
+          directory: /disk/subtitles
     """

     schema = {
@@ -52,6 +53,7 @@
             'exact_match': {'type': 'boolean', 'default': True},
             'providers': {'type': 'array', 'items': {'type': 'string', 'enum': PROVIDERS}},
             'single': {'type': 'boolean', 'default': True},
+            'directory': {'type:': 'string'},
         },
         'required': ['languages'],
         'additionalProperties': False
@@ -80,6 +82,7 @@
                 exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.
                 providers: List of providers from where to download subtitles.
                 single: Download subtitles in single mode (no language code added to subtitle filename).
+                directory: Path to directory where to save the subtitles, default is next to the video.
         """
         if not task.accepted:
             log.debug('nothing accepted, aborting')
@@ -163,7 +166,7 @@
             # save subtitles to disk
             for video, subtitle in downloaded_subtitles.items():
                 if subtitle:
-                    subliminal.save_subtitles(video, subtitle, single=single_mode)
+                    subliminal.save_subtitles(video, subtitle, single=single_mode, directory=config.get('directory', None))


 @event('plugin.register')
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `flexget/plugins/output/subtitles_subliminal.py`
Content:
```
1 from __future__ import unicode_literals, division, absolute_import
2 from builtins import *
3 
4 import collections
5 import logging
6 import os
7 import sys
8 import tempfile
9 
10 from flexget import plugin
11 from flexget.event import event
12 
13 log = logging.getLogger('subtitles')
14 
15 PROVIDERS = [
16     'opensubtitles',
17     'thesubdb',
18     'podnapisi',
19     'addic7ed',
20     'tvsubtitles'
21 ]
22 
23 
24 class PluginSubliminal(object):
25     """
26     Search and download subtitles using Subliminal by Antoine Bertin
27     (https://pypi.python.org/pypi/subliminal).
28     
29     Example (complete task)::
30 
31       subs:
32         find:
33           path: 
34             - d:\media\incoming
35           regexp: '.*\.(avi|mkv|mp4)$'
36           recursive: yes
37         accept_all: yes
38         subliminal:
39           languages:
40             - ita
41           alternatives:
42             - eng
43           exact_match: no
44           providers: addic7ed, opensubtitles
45           single: no
46     """
47     
48     schema = {
49         'type': 'object',
50         'properties': {
51             'languages': {'type': 'array', 'items': {'type': 'string'}, 'minItems': 1},
52             'alternatives': {'type': 'array', 'items': {'type': 'string'}},
53             'exact_match': {'type': 'boolean', 'default': True},
54             'providers': {'type': 'array', 'items': {'type': 'string', 'enum': PROVIDERS}},
55             'single': {'type': 'boolean', 'default': True},
56         },
57         'required': ['languages'],
58         'additionalProperties': False
59     }
60 
61     def on_task_start(self, task, config):
62         if list(sys.version_info) < [2, 7]:
63             raise plugin.DependencyError('subliminal', 'Python 2.7', 'Subliminal plugin requires python 2.7.')
64         try:
65             import babelfish
66         except ImportError as e:
67             log.debug('Error importing Babelfish: %s', e)
68             raise plugin.DependencyError('subliminal', 'babelfish', 'Babelfish module required. ImportError: %s', e)
69         try:
70             import subliminal
71         except ImportError as e:
72             log.debug('Error importing Subliminal: %s', e)
73             raise plugin.DependencyError('subliminal', 'subliminal', 'Subliminal module required. ImportError: %s', e)
74     
75     def on_task_output(self, task, config):
76         """
77         Configuration::
78             subliminal:
79                 languages: List of languages (as IETF codes) in order of preference. At least one is required.
80                 alternatives: List of second-choice languages; subs will be downloaded but entries rejected.
81                 exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.
82                 providers: List of providers from where to download subtitles.
83                 single: Download subtitles in single mode (no language code added to subtitle filename).
84         """
85         if not task.accepted:
86             log.debug('nothing accepted, aborting')
87             return
88         from babelfish import Language
89         from dogpile.cache.exception import RegionAlreadyConfigured
90         import subliminal
91         from subliminal.cli import MutexLock
92         from subliminal.score import episode_scores, movie_scores
93         try:
94             subliminal.region.configure('dogpile.cache.dbm',
95                                         arguments={
96                                             'filename': os.path.join(tempfile.gettempdir(), 'cachefile.dbm'),
97                                             'lock_factory': MutexLock,
98                                         })
99         except RegionAlreadyConfigured:
100             pass
101         logging.getLogger("subliminal").setLevel(logging.CRITICAL)
102         logging.getLogger("enzyme").setLevel(logging.WARNING)
103         languages = set([Language.fromietf(s) for s in config.get('languages', [])])
104         alternative_languages = set([Language.fromietf(s) for s in config.get('alternatives', [])])
105         # keep all downloaded subtitles and save to disk when done (no need to write every time)
106         downloaded_subtitles = collections.defaultdict(list)
107         providers_list = config.get('providers', None)
108         # test if only one language was provided, if so we will download in single mode
109         # (aka no language code added to subtitle filename)
110         # unless we are forced not to by configuration
111         # if we pass 'yes' for single in configuration but choose more than one language
112         # we ignore the configuration and add the language code to the
113         # potentially downloaded files
114         single_mode = config.get('single', '') and len(languages | alternative_languages) <= 1
115         for entry in task.accepted:
116             if 'location' not in entry:
117                 log.warning('Cannot act on entries that do not represent a local file.')
118             elif not os.path.exists(entry['location']):
119                 entry.fail('file not found: %s' % entry['location'])
120             elif '$RECYCLE.BIN' not in entry['location']:  # ignore deleted files in Windows shares
121                 try:
122                     entry_languages = entry.get('subtitle_languages') or languages
123 
124                     video = subliminal.scan_video(entry['location'])
125                     existing_subtitles = set(subliminal.core.search_external_subtitles(entry['location']).values())
126                     video.subtitle_languages = existing_subtitles
127                     if isinstance(video, subliminal.Episode):
128                         title = video.series
129                         hash_scores = episode_scores['hash']
130                     else:
131                         title = video.title
132                         hash_scores = movie_scores['hash']
133                     log.info('Name computed for %s was %s', entry['location'], title)
134                     msc = hash_scores if config['exact_match'] else 0
135                     if entry_languages & existing_subtitles:
136                         log.debug('All preferred languages already exist for "%s"', entry['title'])
137                         entry['subtitles_missing'] = set()
138                         continue  # subs for preferred lang(s) already exists
139                     else:
140                         subtitle = subliminal.download_best_subtitles([video], entry_languages,
141                                                                       providers=providers_list, min_score=msc)
142                         if subtitle and any(subtitle.values()):
143                             downloaded_subtitles.update(subtitle)
144                             log.info('Subtitles found for %s', entry['location'])
145                         else:
146                             # only try to download for alternatives that aren't alread downloaded
147                             subtitle = subliminal.download_best_subtitles([video], alternative_languages,
148                                                                           providers=providers_list, min_score=msc)
149 
150                             if subtitle and any(subtitle.values()):
151                                 downloaded_subtitles.update(subtitle)
152                                 entry.fail('subtitles found for a second-choice language.')
153                             else:
154                                 entry.fail('cannot find any subtitles for now.')
155                         downloaded_languages = set([Language.fromietf(str(l.language))
156                                                     for l in subtitle[video]])
157                         if entry_languages:
158                             entry['subtitles_missing'] = entry_languages - downloaded_languages
159                 except ValueError as e:
160                     log.error('subliminal error: %s', e)
161                     entry.fail()
162 
163         if downloaded_subtitles:
164             # save subtitles to disk
165             for video, subtitle in downloaded_subtitles.items():
166                 if subtitle:
167                     subliminal.save_subtitles(video, subtitle, single=single_mode)
168 
169 
170 @event('plugin.register')
171 def register_plugin():
172     plugin.register(PluginSubliminal, 'subliminal', api_ver=2)
173
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/flexget/plugins/output/subtitles_subliminal.py b/flexget/plugins/output/subtitles_subliminal.py
--- a/flexget/plugins/output/subtitles_subliminal.py
+++ b/flexget/plugins/output/subtitles_subliminal.py
@@ -43,6 +43,7 @@
           exact_match: no
           providers: addic7ed, opensubtitles
           single: no
+          directory: /disk/subtitles
     """
     
     schema = {
@@ -53,6 +54,7 @@
             'exact_match': {'type': 'boolean', 'default': True},
             'providers': {'type': 'array', 'items': {'type': 'string', 'enum': PROVIDERS}},
             'single': {'type': 'boolean', 'default': True},
+            'directory': {'type:': 'string'},
         },
         'required': ['languages'],
         'additionalProperties': False
@@ -81,6 +83,7 @@
                 exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.
                 providers: List of providers from where to download subtitles.
                 single: Download subtitles in single mode (no language code added to subtitle filename).
+                directory: Path to directory where to save the subtitles, default is next to the video.
         """
         if not task.accepted:
             log.debug('nothing accepted, aborting')
@@ -164,7 +167,10 @@
             # save subtitles to disk
             for video, subtitle in downloaded_subtitles.items():
                 if subtitle:
-                    subliminal.save_subtitles(video, subtitle, single=single_mode)
+                    _directory = config.get('directory', None)
+                    if _directory:
+                        _directory = os.path.expanduser(_directory)
+                    subliminal.save_subtitles(video, subtitle, single=single_mode, directory=_directory)
 
 
 @event('plugin.register')

{"golden_diff": "diff --git a/flexget/plugins/output/subtitles_subliminal.py b/flexget/plugins/output/subtitles_subliminal.py\n--- a/flexget/plugins/output/subtitles_subliminal.py\n+++ b/flexget/plugins/output/subtitles_subliminal.py\n@@ -43,6 +43,7 @@\n           exact_match: no\n           providers: addic7ed, opensubtitles\n           single: no\n+          directory: /disk/subtitles\n     \"\"\"\n     \n     schema = {\n@@ -53,6 +54,7 @@\n             'exact_match': {'type': 'boolean', 'default': True},\n             'providers': {'type': 'array', 'items': {'type': 'string', 'enum': PROVIDERS}},\n             'single': {'type': 'boolean', 'default': True},\n+            'directory': {'type:': 'string'},\n         },\n         'required': ['languages'],\n         'additionalProperties': False\n@@ -81,6 +83,7 @@\n                 exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.\n                 providers: List of providers from where to download subtitles.\n                 single: Download subtitles in single mode (no language code added to subtitle filename).\n+                directory: Path to directory where to save the subtitles, default is next to the video.\n         \"\"\"\n         if not task.accepted:\n             log.debug('nothing accepted, aborting')\n@@ -164,7 +167,10 @@\n             # save subtitles to disk\n             for video, subtitle in downloaded_subtitles.items():\n                 if subtitle:\n-                    subliminal.save_subtitles(video, subtitle, single=single_mode)\n+                    _directory = config.get('directory', None)\n+                    if _directory:\n+                        _directory = os.path.expanduser(_directory)\n+                    subliminal.save_subtitles(video, subtitle, single=single_mode, directory=_directory)\n \n \n @event('plugin.register')\n", "issue": "[subliminal] Support downloading subtitles to different directory\nAlready supported by the subliminal API, patch just adds a config option for it.\n\n```\n--- subtitles_subliminal.py.orig    2016-04-20 06:07:33.873933998 -0300\n+++ subtitles_subliminal.py 2016-04-20 06:12:29.070504077 -0300\n@@ -42,6 +42,7 @@\n           exact_match: no\n           providers: addic7ed, opensubtitles\n           single: no\n+          directory: /disk/subtitles\n     \"\"\"\n\n     schema = {\n@@ -52,6 +53,7 @@\n             'exact_match': {'type': 'boolean', 'default': True},\n             'providers': {'type': 'array', 'items': {'type': 'string', 'enum': PROVIDERS}},\n             'single': {'type': 'boolean', 'default': True},\n+            'directory': {'type:': 'string'},\n         },\n         'required': ['languages'],\n         'additionalProperties': False\n@@ -80,6 +82,7 @@\n                 exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.\n                 providers: List of providers from where to download subtitles.\n                 single: Download subtitles in single mode (no language code added to subtitle filename).\n+                directory: Path to directory where to save the subtitles, default is next to the video.\n         \"\"\"\n         if not task.accepted:\n             log.debug('nothing accepted, aborting')\n@@ -163,7 +166,7 @@\n             # save subtitles to disk\n             for video, subtitle in downloaded_subtitles.items():\n                 if subtitle:\n-                    subliminal.save_subtitles(video, subtitle, single=single_mode)\n+                    subliminal.save_subtitles(video, subtitle, single=single_mode, directory=config.get('directory', None))\n\n\n @event('plugin.register')\n```\n\n", "before_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nfrom builtins import *\n\nimport collections\nimport logging\nimport os\nimport sys\nimport tempfile\n\nfrom flexget import plugin\nfrom flexget.event import event\n\nlog = logging.getLogger('subtitles')\n\nPROVIDERS = [\n    'opensubtitles',\n    'thesubdb',\n    'podnapisi',\n    'addic7ed',\n    'tvsubtitles'\n]\n\n\nclass PluginSubliminal(object):\n    \"\"\"\n    Search and download subtitles using Subliminal by Antoine Bertin\n    (https://pypi.python.org/pypi/subliminal).\n    \n    Example (complete task)::\n\n      subs:\n        find:\n          path: \n            - d:\\media\\incoming\n          regexp: '.*\\.(avi|mkv|mp4)$'\n          recursive: yes\n        accept_all: yes\n        subliminal:\n          languages:\n            - ita\n          alternatives:\n            - eng\n          exact_match: no\n          providers: addic7ed, opensubtitles\n          single: no\n    \"\"\"\n    \n    schema = {\n        'type': 'object',\n        'properties': {\n            'languages': {'type': 'array', 'items': {'type': 'string'}, 'minItems': 1},\n            'alternatives': {'type': 'array', 'items': {'type': 'string'}},\n            'exact_match': {'type': 'boolean', 'default': True},\n            'providers': {'type': 'array', 'items': {'type': 'string', 'enum': PROVIDERS}},\n            'single': {'type': 'boolean', 'default': True},\n        },\n        'required': ['languages'],\n        'additionalProperties': False\n    }\n\n    def on_task_start(self, task, config):\n        if list(sys.version_info) < [2, 7]:\n            raise plugin.DependencyError('subliminal', 'Python 2.7', 'Subliminal plugin requires python 2.7.')\n        try:\n            import babelfish\n        except ImportError as e:\n            log.debug('Error importing Babelfish: %s', e)\n            raise plugin.DependencyError('subliminal', 'babelfish', 'Babelfish module required. ImportError: %s', e)\n        try:\n            import subliminal\n        except ImportError as e:\n            log.debug('Error importing Subliminal: %s', e)\n            raise plugin.DependencyError('subliminal', 'subliminal', 'Subliminal module required. ImportError: %s', e)\n    \n    def on_task_output(self, task, config):\n        \"\"\"\n        Configuration::\n            subliminal:\n                languages: List of languages (as IETF codes) in order of preference. At least one is required.\n                alternatives: List of second-choice languages; subs will be downloaded but entries rejected.\n                exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.\n                providers: List of providers from where to download subtitles.\n                single: Download subtitles in single mode (no language code added to subtitle filename).\n        \"\"\"\n        if not task.accepted:\n            log.debug('nothing accepted, aborting')\n            return\n        from babelfish import Language\n        from dogpile.cache.exception import RegionAlreadyConfigured\n        import subliminal\n        from subliminal.cli import MutexLock\n        from subliminal.score import episode_scores, movie_scores\n        try:\n            subliminal.region.configure('dogpile.cache.dbm',\n                                        arguments={\n                                            'filename': os.path.join(tempfile.gettempdir(), 'cachefile.dbm'),\n                                            'lock_factory': MutexLock,\n                                        })\n        except RegionAlreadyConfigured:\n            pass\n        logging.getLogger(\"subliminal\").setLevel(logging.CRITICAL)\n        logging.getLogger(\"enzyme\").setLevel(logging.WARNING)\n        languages = set([Language.fromietf(s) for s in config.get('languages', [])])\n        alternative_languages = set([Language.fromietf(s) for s in config.get('alternatives', [])])\n        # keep all downloaded subtitles and save to disk when done (no need to write every time)\n        downloaded_subtitles = collections.defaultdict(list)\n        providers_list = config.get('providers', None)\n        # test if only one language was provided, if so we will download in single mode\n        # (aka no language code added to subtitle filename)\n        # unless we are forced not to by configuration\n        # if we pass 'yes' for single in configuration but choose more than one language\n        # we ignore the configuration and add the language code to the\n        # potentially downloaded files\n        single_mode = config.get('single', '') and len(languages | alternative_languages) <= 1\n        for entry in task.accepted:\n            if 'location' not in entry:\n                log.warning('Cannot act on entries that do not represent a local file.')\n            elif not os.path.exists(entry['location']):\n                entry.fail('file not found: %s' % entry['location'])\n            elif '$RECYCLE.BIN' not in entry['location']:  # ignore deleted files in Windows shares\n                try:\n                    entry_languages = entry.get('subtitle_languages') or languages\n\n                    video = subliminal.scan_video(entry['location'])\n                    existing_subtitles = set(subliminal.core.search_external_subtitles(entry['location']).values())\n                    video.subtitle_languages = existing_subtitles\n                    if isinstance(video, subliminal.Episode):\n                        title = video.series\n                        hash_scores = episode_scores['hash']\n                    else:\n                        title = video.title\n                        hash_scores = movie_scores['hash']\n                    log.info('Name computed for %s was %s', entry['location'], title)\n                    msc = hash_scores if config['exact_match'] else 0\n                    if entry_languages & existing_subtitles:\n                        log.debug('All preferred languages already exist for \"%s\"', entry['title'])\n                        entry['subtitles_missing'] = set()\n                        continue  # subs for preferred lang(s) already exists\n                    else:\n                        subtitle = subliminal.download_best_subtitles([video], entry_languages,\n                                                                      providers=providers_list, min_score=msc)\n                        if subtitle and any(subtitle.values()):\n                            downloaded_subtitles.update(subtitle)\n                            log.info('Subtitles found for %s', entry['location'])\n                        else:\n                            # only try to download for alternatives that aren't alread downloaded\n                            subtitle = subliminal.download_best_subtitles([video], alternative_languages,\n                                                                          providers=providers_list, min_score=msc)\n\n                            if subtitle and any(subtitle.values()):\n                                downloaded_subtitles.update(subtitle)\n                                entry.fail('subtitles found for a second-choice language.')\n                            else:\n                                entry.fail('cannot find any subtitles for now.')\n                        downloaded_languages = set([Language.fromietf(str(l.language))\n                                                    for l in subtitle[video]])\n                        if entry_languages:\n                            entry['subtitles_missing'] = entry_languages - downloaded_languages\n                except ValueError as e:\n                    log.error('subliminal error: %s', e)\n                    entry.fail()\n\n        if downloaded_subtitles:\n            # save subtitles to disk\n            for video, subtitle in downloaded_subtitles.items():\n                if subtitle:\n                    subliminal.save_subtitles(video, subtitle, single=single_mode)\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(PluginSubliminal, 'subliminal', api_ver=2)\n", "path": "flexget/plugins/output/subtitles_subliminal.py"}], "after_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nfrom builtins import *\n\nimport collections\nimport logging\nimport os\nimport sys\nimport tempfile\n\nfrom flexget import plugin\nfrom flexget.event import event\n\nlog = logging.getLogger('subtitles')\n\nPROVIDERS = [\n    'opensubtitles',\n    'thesubdb',\n    'podnapisi',\n    'addic7ed',\n    'tvsubtitles'\n]\n\n\nclass PluginSubliminal(object):\n    \"\"\"\n    Search and download subtitles using Subliminal by Antoine Bertin\n    (https://pypi.python.org/pypi/subliminal).\n    \n    Example (complete task)::\n\n      subs:\n        find:\n          path: \n            - d:\\media\\incoming\n          regexp: '.*\\.(avi|mkv|mp4)$'\n          recursive: yes\n        accept_all: yes\n        subliminal:\n          languages:\n            - ita\n          alternatives:\n            - eng\n          exact_match: no\n          providers: addic7ed, opensubtitles\n          single: no\n          directory: /disk/subtitles\n    \"\"\"\n    \n    schema = {\n        'type': 'object',\n        'properties': {\n            'languages': {'type': 'array', 'items': {'type': 'string'}, 'minItems': 1},\n            'alternatives': {'type': 'array', 'items': {'type': 'string'}},\n            'exact_match': {'type': 'boolean', 'default': True},\n            'providers': {'type': 'array', 'items': {'type': 'string', 'enum': PROVIDERS}},\n            'single': {'type': 'boolean', 'default': True},\n            'directory': {'type:': 'string'},\n        },\n        'required': ['languages'],\n        'additionalProperties': False\n    }\n\n    def on_task_start(self, task, config):\n        if list(sys.version_info) < [2, 7]:\n            raise plugin.DependencyError('subliminal', 'Python 2.7', 'Subliminal plugin requires python 2.7.')\n        try:\n            import babelfish\n        except ImportError as e:\n            log.debug('Error importing Babelfish: %s', e)\n            raise plugin.DependencyError('subliminal', 'babelfish', 'Babelfish module required. ImportError: %s', e)\n        try:\n            import subliminal\n        except ImportError as e:\n            log.debug('Error importing Subliminal: %s', e)\n            raise plugin.DependencyError('subliminal', 'subliminal', 'Subliminal module required. ImportError: %s', e)\n    \n    def on_task_output(self, task, config):\n        \"\"\"\n        Configuration::\n            subliminal:\n                languages: List of languages (as IETF codes) in order of preference. At least one is required.\n                alternatives: List of second-choice languages; subs will be downloaded but entries rejected.\n                exact_match: Use file hash only to search for subs, otherwise Subliminal will try to guess by filename.\n                providers: List of providers from where to download subtitles.\n                single: Download subtitles in single mode (no language code added to subtitle filename).\n                directory: Path to directory where to save the subtitles, default is next to the video.\n        \"\"\"\n        if not task.accepted:\n            log.debug('nothing accepted, aborting')\n            return\n        from babelfish import Language\n        from dogpile.cache.exception import RegionAlreadyConfigured\n        import subliminal\n        from subliminal.cli import MutexLock\n        from subliminal.score import episode_scores, movie_scores\n        try:\n            subliminal.region.configure('dogpile.cache.dbm',\n                                        arguments={\n                                            'filename': os.path.join(tempfile.gettempdir(), 'cachefile.dbm'),\n                                            'lock_factory': MutexLock,\n                                        })\n        except RegionAlreadyConfigured:\n            pass\n        logging.getLogger(\"subliminal\").setLevel(logging.CRITICAL)\n        logging.getLogger(\"enzyme\").setLevel(logging.WARNING)\n        languages = set([Language.fromietf(s) for s in config.get('languages', [])])\n        alternative_languages = set([Language.fromietf(s) for s in config.get('alternatives', [])])\n        # keep all downloaded subtitles and save to disk when done (no need to write every time)\n        downloaded_subtitles = collections.defaultdict(list)\n        providers_list = config.get('providers', None)\n        # test if only one language was provided, if so we will download in single mode\n        # (aka no language code added to subtitle filename)\n        # unless we are forced not to by configuration\n        # if we pass 'yes' for single in configuration but choose more than one language\n        # we ignore the configuration and add the language code to the\n        # potentially downloaded files\n        single_mode = config.get('single', '') and len(languages | alternative_languages) <= 1\n        for entry in task.accepted:\n            if 'location' not in entry:\n                log.warning('Cannot act on entries that do not represent a local file.')\n            elif not os.path.exists(entry['location']):\n                entry.fail('file not found: %s' % entry['location'])\n            elif '$RECYCLE.BIN' not in entry['location']:  # ignore deleted files in Windows shares\n                try:\n                    entry_languages = entry.get('subtitle_languages') or languages\n\n                    video = subliminal.scan_video(entry['location'])\n                    existing_subtitles = set(subliminal.core.search_external_subtitles(entry['location']).values())\n                    video.subtitle_languages = existing_subtitles\n                    if isinstance(video, subliminal.Episode):\n                        title = video.series\n                        hash_scores = episode_scores['hash']\n                    else:\n                        title = video.title\n                        hash_scores = movie_scores['hash']\n                    log.info('Name computed for %s was %s', entry['location'], title)\n                    msc = hash_scores if config['exact_match'] else 0\n                    if entry_languages & existing_subtitles:\n                        log.debug('All preferred languages already exist for \"%s\"', entry['title'])\n                        entry['subtitles_missing'] = set()\n                        continue  # subs for preferred lang(s) already exists\n                    else:\n                        subtitle = subliminal.download_best_subtitles([video], entry_languages,\n                                                                      providers=providers_list, min_score=msc)\n                        if subtitle and any(subtitle.values()):\n                            downloaded_subtitles.update(subtitle)\n                            log.info('Subtitles found for %s', entry['location'])\n                        else:\n                            # only try to download for alternatives that aren't alread downloaded\n                            subtitle = subliminal.download_best_subtitles([video], alternative_languages,\n                                                                          providers=providers_list, min_score=msc)\n\n                            if subtitle and any(subtitle.values()):\n                                downloaded_subtitles.update(subtitle)\n                                entry.fail('subtitles found for a second-choice language.')\n                            else:\n                                entry.fail('cannot find any subtitles for now.')\n                        downloaded_languages = set([Language.fromietf(str(l.language))\n                                                    for l in subtitle[video]])\n                        if entry_languages:\n                            entry['subtitles_missing'] = entry_languages - downloaded_languages\n                except ValueError as e:\n                    log.error('subliminal error: %s', e)\n                    entry.fail()\n\n        if downloaded_subtitles:\n            # save subtitles to disk\n            for video, subtitle in downloaded_subtitles.items():\n                if subtitle:\n                    _directory = config.get('directory', None)\n                    if _directory:\n                        _directory = os.path.expanduser(_directory)\n                    subliminal.save_subtitles(video, subtitle, single=single_mode, directory=_directory)\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(PluginSubliminal, 'subliminal', api_ver=2)\n", "path": "flexget/plugins/output/subtitles_subliminal.py"}]}