We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unhandled error in plugin argenteam
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions
- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon
- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues
- Did you fill out the issue template as completely as possible?

The issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!
--->
### Expected behavior:
<!---
Get list of shows from Trakt and download needed shows,
--->

### Actual behavior:
It gets the list of shows from Trakt and starts searching for each show using the plug-ins. It then crashes.
### Steps to reproduce:
- Step 1: It happens every time it runs.

#### Config:
```
variables: secrets.yml

templates:


  tv:
    configure_series:
      settings:
        quality: 720p+
        identified_by: ep
      from:
        trakt_list:
          account: "{? trakt.account ?}"
          list: "{? trakt.series ?}"
          type: shows



  reject:
    regexp:
      reject:
        - \b(s|d)ub(s|bed|lado|titulado)?\b
        - \bhc\b
        - \bdual\b
        - \b3d\b
        - \bfre(nch)?\b
        - \bita(lian)?\b
        - \bspa(nish)?\b
        - \bger(man)?\b
        - \bcastellano\b
        - \brus(sian)?\b
        - \btamil\b
        - \bhindi\b
        - \bh265\b
        - \bx265\b
    content_filter:
      reject:
        - '*.rar'
        - '*.zip'
        - '*.exe'



  place_torrent:
    utorrent:
      url: "{? utorrent.url ?}"
      username: "{? utorrent.user ?}"
      password: "{? utorrent.pass ?}"
      path: "{? utorrent.path ?}"



  pushbullet:
    notify:
      entries:
        title: "[flexget] Downloading"
        message: "{{title}}"
        via:
          - pushbullet:
              api_key: "{? pushbullet.api ?}"





tasks:


  follow show from ep:
    seen: local
    trakt_list:
      account: "{? trakt.account ?}"
      list: "{? trakt.series ?}"
      type: episodes
    accept_all: yes
    set_series_begin: yes
    list_remove:
      - trakt_list:
          account: "{? trakt.account ?}"
          list: "{? trakt.series ?}"
          type: episodes
    list_add:
      - trakt_list:
          account: "{? trakt.account ?}"
          list: "{? trakt.series ?}"
          type: shows



  get shows:
    template:
      - tv
      - reject
      - place_torrent
      - pushbullet
    discover:
      what:
        - next_series_episodes:
            from_start: yes
      from:
        - piratebay:
            category: highres tv
        - limetorrents:
            category: tv
        - rarbg:
            category: [1, 18, 41, 49]
        - argenteam:
            force_subtitles: no
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>


Debug Log - https://pastebin.com/bTr4qX6a
```
2019-03-16 05:40 VERBOSE  trakt_list    get shows       Retrieving `shows` list `720p_list`
2019-03-16 05:40 VERBOSE  discover      get shows       Discovering 26 titles ...
2019-03-16 05:40 INFO     discover      get shows       Ignoring interval because of --discover-now
2019-03-16 05:40 INFO     task          get shows       Plugin next_series_episodes has requested task to be ran again after execution has completed. Reason: Look for next season
2019-03-16 05:40 VERBOSE  discover      get shows       The Big Bang Theory (2007) S12E18 hasn't been released yet (Expected: 2019-04-04 00:00:00)
2019-03-16 05:40 VERBOSE  discover      get shows       Modern Family (2009) S10E18 hasn't been released yet (Expected: 2019-03-20 00:00:00)
2019-03-16 05:40 VERBOSE  discover      get shows       Game of Thrones (2011) S08E01 hasn't been released yet (Expected: 2019-04-14 00:00:00)
2019-03-16 05:40 VERBOSE  discover      get shows       The Goldbergs (2013) S06E19 hasn't been released yet (Expected: 2019-03-20 00:00:00)
2019-03-16 05:40 VERBOSE  discover      get shows       Schooled (2019) S01E09 hasn't been released yet (Expected: 2019-03-20 00:00:00)
2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `piratebay` (1 of 10)
2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `limetorrents` (1 of 10)
2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `rarbg` (1 of 10)
2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `argenteam` (1 of 10)
2019-03-16 05:41 CRITICAL task          get shows       BUG: Unhandled error in plugin discover: list index out of range
2019-03-16 05:41 CRITICAL manager       get shows       An unexpected crash has occurred. Writing crash report to C:\Users\Amishman\flexget\crash_report.2019.03.16.054135803000.log. Please verify you are running the latest version of flexget by using "flexget -V" from CLI or by using version_checker plugin at http://flexget.com/wiki/Plugins/version_checker. You are currently using version 2.20.12
2019-03-16 05:41 WARNING  task          get shows       Aborting task (plugin: discover)
```
</details>

### Additional information:

- FlexGet version: 2.20.12
- Python version: 2.7.13
- Installation method: pip
- Using daemon (yes/no): no
- OS and version: Windows 7 Pro
- Link to crash log:
[crash_report.2019.03.16.054135803000.log](https://github.com/Flexget/Flexget/files/2973746/crash_report.2019.03.16.054135803000.log)


<!---
In config and debug/crash logs, remember to redact any personal or sensitive information such as passwords, API keys, private URLs and so on.

Please verify that the following data is present before submitting your issue:

- Link to a paste service or paste above the relevant config (preferably full config, including templates if present). Please make sure the paste does not expire, if possible.
- Link to a paste service or paste above debug-level logs of the relevant task/s (use `flexget -L debug execute --tasks <Task_name>`).
- FlexGet version (use `flexget -V` to get it).
- Full Python version, for example `2.7.11` (use `python -V` to get it). Note that FlexGet is not supported for use with Python v3.0, 3.1, 3.2 or 3.6.
- Installation method (pip, git install, etc).
- Whether or not you're running FlexGet as a daemon.
- OS and version.
- Attach crash log if one was generated, in addition to the debug-level log. It can be found in the directory with your config file.
--->


--- 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/components/sites/sites/argenteam.py`
Content:
```
1 from __future__ import unicode_literals, division, absolute_import
2 from builtins import *  # noqa pylint: disable=unused-import, redefined-builtin
3 
4 import logging
5 
6 from requests import RequestException
7 
8 from flexget import plugin
9 from flexget.entry import Entry
10 from flexget.event import event
11 from flexget.components.sites.utils import normalize_scene
12 
13 log = logging.getLogger('argenteam')
14 
15 
16 class SearchArgenteam(object):
17     """ Argenteam
18     Search plugin which gives results from www.argenteam.net, latin american (Argentina) web.
19 
20     Configuration:
21       - force_subtitles: [yes/no] #Force download release with subtitles made by aRGENTeaM. Default is yes
22 
23     Example
24       argenteam:
25         force_subtitles: yes
26     """
27 
28     schema = {
29         'type': 'object',
30         'properties': {'force_subtitles': {'type': 'boolean', 'default': True}},
31         "additionalProperties": False,
32     }
33 
34     base_url = 'http://www.argenteam.net/api/v1/'
35 
36     @plugin.internet(log)
37     def search(self, task, entry, config):
38         """
39             Search for releases
40         """
41 
42         entries = set()
43 
44         for search_string in entry.get('search_strings', [entry['title']]):
45 
46             try:
47                 params = {'q': normalize_scene(search_string)}
48                 resp = task.requests.get(self.base_url + 'search', params=params)
49                 log.debug('Requesting: %s', resp.url)
50                 response = resp.json()
51             except RequestException as e:
52                 log.error('Argenteam request failed: %s', e)
53                 return
54 
55             if not response:
56                 log.debug('Empty response from Argenteam')
57                 continue
58 
59             if not response.get('total'):
60                 log.debug('No results found for %s', search_string)
61                 continue
62 
63             results = response.get('results')
64             if results[0]['type'] == 'tvshow':
65                 log.error('Argenteam type tvshow not supported yet.')
66                 continue
67 
68             url = '{}{}?id={}'.format(self.base_url, results[0]['type'], results[0]['id'])
69             try:
70                 resp = task.requests.get(url)
71                 log.debug('Requesting releases for: %s', url)
72                 response = resp.json()
73             except RequestException as e:
74                 log.error('Argenteam request failed: %s', e)
75                 return
76 
77             for release in response['releases']:
78                 for torrent in release['torrents']:
79                     if (
80                         config.get('force_subtitles')
81                         and release['subtitles']
82                         or not config.get('force_subtitles')
83                     ):
84                         e = Entry()
85 
86                         e['title'] = ' '.join(
87                             (
88                                 search_string,
89                                 release['source'],
90                                 release['codec'],
91                                 release['team'],
92                                 release['tags'],
93                             )
94                         )
95                         e['url'] = torrent['uri']
96 
97                         # Save aRGENTeaM subtitle URL for this release
98                         if 'subtitles' in release:
99                             e['argenteam_subtitle'] = release['subtitles'][0]['uri']
100                             log.debug('Argenteam subtitle found: %s', e['argenteam_subtitle'])
101 
102                         if 'tvdb' in response:
103                             e['tvdb_id'] = response['tvdb']
104                         if 'info' in response and 'imdb' in response['info']:
105                             e['imdb_id'] = response['info']['imdb']
106 
107                         entries.add(e)
108 
109         return entries
110 
111 
112 @event('plugin.register')
113 def register_plugin():
114     plugin.register(SearchArgenteam, 'argenteam', interfaces=['search'], api_ver=2)
115
```
--- 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/components/sites/sites/argenteam.py b/flexget/components/sites/sites/argenteam.py
--- a/flexget/components/sites/sites/argenteam.py
+++ b/flexget/components/sites/sites/argenteam.py
@@ -74,6 +74,7 @@
                 log.error('Argenteam request failed: %s', e)
                 return
 
+            log.debug('%s releases found.', len(response['releases']))
             for release in response['releases']:
                 for torrent in release['torrents']:
                     if (
@@ -95,7 +96,7 @@
                         e['url'] = torrent['uri']
 
                         # Save aRGENTeaM subtitle URL for this release
-                        if 'subtitles' in release:
+                        if 'subtitles' in release and len(release['subtitles']) > 0:
                             e['argenteam_subtitle'] = release['subtitles'][0]['uri']
                             log.debug('Argenteam subtitle found: %s', e['argenteam_subtitle'])

{"golden_diff": "diff --git a/flexget/components/sites/sites/argenteam.py b/flexget/components/sites/sites/argenteam.py\n--- a/flexget/components/sites/sites/argenteam.py\n+++ b/flexget/components/sites/sites/argenteam.py\n@@ -74,6 +74,7 @@\n                 log.error('Argenteam request failed: %s', e)\n                 return\n \n+            log.debug('%s releases found.', len(response['releases']))\n             for release in response['releases']:\n                 for torrent in release['torrents']:\n                     if (\n@@ -95,7 +96,7 @@\n                         e['url'] = torrent['uri']\n \n                         # Save aRGENTeaM subtitle URL for this release\n-                        if 'subtitles' in release:\n+                        if 'subtitles' in release and len(release['subtitles']) > 0:\n                             e['argenteam_subtitle'] = release['subtitles'][0]['uri']\n                             log.debug('Argenteam subtitle found: %s', e['argenteam_subtitle'])\n", "issue": "Unhandled error in plugin argenteam\n<!---\r\nBefore opening an issue, verify:\r\n\r\n- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget\r\n- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions\r\n- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon\r\n- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues\r\n- Did you fill out the issue template as completely as possible?\r\n\r\nThe issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!\r\n--->\r\n### Expected behavior:\r\n<!---\r\nGet list of shows from Trakt and download needed shows,\r\n--->\r\n\r\n### Actual behavior:\r\nIt gets the list of shows from Trakt and starts searching for each show using the plug-ins. It then crashes.\r\n### Steps to reproduce:\r\n- Step 1: It happens every time it runs.\r\n\r\n#### Config:\r\n```\r\nvariables: secrets.yml\r\n\r\ntemplates:\r\n\r\n\r\n  tv:\r\n    configure_series:\r\n      settings:\r\n        quality: 720p+\r\n        identified_by: ep\r\n      from:\r\n        trakt_list:\r\n          account: \"{? trakt.account ?}\"\r\n          list: \"{? trakt.series ?}\"\r\n          type: shows\r\n\r\n\r\n\r\n  reject:\r\n    regexp:\r\n      reject:\r\n        - \\b(s|d)ub(s|bed|lado|titulado)?\\b\r\n        - \\bhc\\b\r\n        - \\bdual\\b\r\n        - \\b3d\\b\r\n        - \\bfre(nch)?\\b\r\n        - \\bita(lian)?\\b\r\n        - \\bspa(nish)?\\b\r\n        - \\bger(man)?\\b\r\n        - \\bcastellano\\b\r\n        - \\brus(sian)?\\b\r\n        - \\btamil\\b\r\n        - \\bhindi\\b\r\n        - \\bh265\\b\r\n        - \\bx265\\b\r\n    content_filter:\r\n      reject:\r\n        - '*.rar'\r\n        - '*.zip'\r\n        - '*.exe'\r\n\r\n\r\n\r\n  place_torrent:\r\n    utorrent:\r\n      url: \"{? utorrent.url ?}\"\r\n      username: \"{? utorrent.user ?}\"\r\n      password: \"{? utorrent.pass ?}\"\r\n      path: \"{? utorrent.path ?}\"\r\n\r\n\r\n\r\n  pushbullet:\r\n    notify:\r\n      entries:\r\n        title: \"[flexget] Downloading\"\r\n        message: \"{{title}}\"\r\n        via:\r\n          - pushbullet:\r\n              api_key: \"{? pushbullet.api ?}\"\r\n\r\n\r\n\r\n\r\n\r\ntasks:\r\n\r\n\r\n  follow show from ep:\r\n    seen: local\r\n    trakt_list:\r\n      account: \"{? trakt.account ?}\"\r\n      list: \"{? trakt.series ?}\"\r\n      type: episodes\r\n    accept_all: yes\r\n    set_series_begin: yes\r\n    list_remove:\r\n      - trakt_list:\r\n          account: \"{? trakt.account ?}\"\r\n          list: \"{? trakt.series ?}\"\r\n          type: episodes\r\n    list_add:\r\n      - trakt_list:\r\n          account: \"{? trakt.account ?}\"\r\n          list: \"{? trakt.series ?}\"\r\n          type: shows\r\n\r\n\r\n\r\n  get shows:\r\n    template:\r\n      - tv\r\n      - reject\r\n      - place_torrent\r\n      - pushbullet\r\n    discover:\r\n      what:\r\n        - next_series_episodes:\r\n            from_start: yes\r\n      from:\r\n        - piratebay:\r\n            category: highres tv\r\n        - limetorrents:\r\n            category: tv\r\n        - rarbg:\r\n            category: [1, 18, 41, 49]\r\n        - argenteam:\r\n            force_subtitles: no\r\n```\r\n  \r\n#### Log:\r\n<details>\r\n <summary>(click to expand)</summary>\r\n\r\n\r\nDebug Log - https://pastebin.com/bTr4qX6a\r\n```\r\n2019-03-16 05:40 VERBOSE  trakt_list    get shows       Retrieving `shows` list `720p_list`\r\n2019-03-16 05:40 VERBOSE  discover      get shows       Discovering 26 titles ...\r\n2019-03-16 05:40 INFO     discover      get shows       Ignoring interval because of --discover-now\r\n2019-03-16 05:40 INFO     task          get shows       Plugin next_series_episodes has requested task to be ran again after execution has completed. Reason: Look for next season\r\n2019-03-16 05:40 VERBOSE  discover      get shows       The Big Bang Theory (2007) S12E18 hasn't been released yet (Expected: 2019-04-04 00:00:00)\r\n2019-03-16 05:40 VERBOSE  discover      get shows       Modern Family (2009) S10E18 hasn't been released yet (Expected: 2019-03-20 00:00:00)\r\n2019-03-16 05:40 VERBOSE  discover      get shows       Game of Thrones (2011) S08E01 hasn't been released yet (Expected: 2019-04-14 00:00:00)\r\n2019-03-16 05:40 VERBOSE  discover      get shows       The Goldbergs (2013) S06E19 hasn't been released yet (Expected: 2019-03-20 00:00:00)\r\n2019-03-16 05:40 VERBOSE  discover      get shows       Schooled (2019) S01E09 hasn't been released yet (Expected: 2019-03-20 00:00:00)\r\n2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `piratebay` (1 of 10)\r\n2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `limetorrents` (1 of 10)\r\n2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `rarbg` (1 of 10)\r\n2019-03-16 05:41 VERBOSE  discover      get shows       Searching for `Shameless (2011) S04E04` with plugin `argenteam` (1 of 10)\r\n2019-03-16 05:41 CRITICAL task          get shows       BUG: Unhandled error in plugin discover: list index out of range\r\n2019-03-16 05:41 CRITICAL manager       get shows       An unexpected crash has occurred. Writing crash report to C:\\Users\\Amishman\\flexget\\crash_report.2019.03.16.054135803000.log. Please verify you are running the latest version of flexget by using \"flexget -V\" from CLI or by using version_checker plugin at http://flexget.com/wiki/Plugins/version_checker. You are currently using version 2.20.12\r\n2019-03-16 05:41 WARNING  task          get shows       Aborting task (plugin: discover)\r\n```\r\n</details>\r\n\r\n### Additional information:\r\n\r\n- FlexGet version: 2.20.12\r\n- Python version: 2.7.13\r\n- Installation method: pip\r\n- Using daemon (yes/no): no\r\n- OS and version: Windows 7 Pro\r\n- Link to crash log:\r\n[crash_report.2019.03.16.054135803000.log](https://github.com/Flexget/Flexget/files/2973746/crash_report.2019.03.16.054135803000.log)\r\n\r\n\r\n<!---\r\nIn config and debug/crash logs, remember to redact any personal or sensitive information such as passwords, API keys, private URLs and so on.\r\n\r\nPlease verify that the following data is present before submitting your issue:\r\n\r\n- Link to a paste service or paste above the relevant config (preferably full config, including templates if present). Please make sure the paste does not expire, if possible.\r\n- Link to a paste service or paste above debug-level logs of the relevant task/s (use `flexget -L debug execute --tasks <Task_name>`).\r\n- FlexGet version (use `flexget -V` to get it).\r\n- Full Python version, for example `2.7.11` (use `python -V` to get it). Note that FlexGet is not supported for use with Python v3.0, 3.1, 3.2 or 3.6.\r\n- Installation method (pip, git install, etc).\r\n- Whether or not you're running FlexGet as a daemon.\r\n- OS and version.\r\n- Attach crash log if one was generated, in addition to the debug-level log. It can be found in the directory with your config file.\r\n--->\r\n\n", "before_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nfrom builtins import *  # noqa pylint: disable=unused-import, redefined-builtin\n\nimport logging\n\nfrom requests import RequestException\n\nfrom flexget import plugin\nfrom flexget.entry import Entry\nfrom flexget.event import event\nfrom flexget.components.sites.utils import normalize_scene\n\nlog = logging.getLogger('argenteam')\n\n\nclass SearchArgenteam(object):\n    \"\"\" Argenteam\n    Search plugin which gives results from www.argenteam.net, latin american (Argentina) web.\n\n    Configuration:\n      - force_subtitles: [yes/no] #Force download release with subtitles made by aRGENTeaM. Default is yes\n\n    Example\n      argenteam:\n        force_subtitles: yes\n    \"\"\"\n\n    schema = {\n        'type': 'object',\n        'properties': {'force_subtitles': {'type': 'boolean', 'default': True}},\n        \"additionalProperties\": False,\n    }\n\n    base_url = 'http://www.argenteam.net/api/v1/'\n\n    @plugin.internet(log)\n    def search(self, task, entry, config):\n        \"\"\"\n            Search for releases\n        \"\"\"\n\n        entries = set()\n\n        for search_string in entry.get('search_strings', [entry['title']]):\n\n            try:\n                params = {'q': normalize_scene(search_string)}\n                resp = task.requests.get(self.base_url + 'search', params=params)\n                log.debug('Requesting: %s', resp.url)\n                response = resp.json()\n            except RequestException as e:\n                log.error('Argenteam request failed: %s', e)\n                return\n\n            if not response:\n                log.debug('Empty response from Argenteam')\n                continue\n\n            if not response.get('total'):\n                log.debug('No results found for %s', search_string)\n                continue\n\n            results = response.get('results')\n            if results[0]['type'] == 'tvshow':\n                log.error('Argenteam type tvshow not supported yet.')\n                continue\n\n            url = '{}{}?id={}'.format(self.base_url, results[0]['type'], results[0]['id'])\n            try:\n                resp = task.requests.get(url)\n                log.debug('Requesting releases for: %s', url)\n                response = resp.json()\n            except RequestException as e:\n                log.error('Argenteam request failed: %s', e)\n                return\n\n            for release in response['releases']:\n                for torrent in release['torrents']:\n                    if (\n                        config.get('force_subtitles')\n                        and release['subtitles']\n                        or not config.get('force_subtitles')\n                    ):\n                        e = Entry()\n\n                        e['title'] = ' '.join(\n                            (\n                                search_string,\n                                release['source'],\n                                release['codec'],\n                                release['team'],\n                                release['tags'],\n                            )\n                        )\n                        e['url'] = torrent['uri']\n\n                        # Save aRGENTeaM subtitle URL for this release\n                        if 'subtitles' in release:\n                            e['argenteam_subtitle'] = release['subtitles'][0]['uri']\n                            log.debug('Argenteam subtitle found: %s', e['argenteam_subtitle'])\n\n                        if 'tvdb' in response:\n                            e['tvdb_id'] = response['tvdb']\n                        if 'info' in response and 'imdb' in response['info']:\n                            e['imdb_id'] = response['info']['imdb']\n\n                        entries.add(e)\n\n        return entries\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(SearchArgenteam, 'argenteam', interfaces=['search'], api_ver=2)\n", "path": "flexget/components/sites/sites/argenteam.py"}], "after_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nfrom builtins import *  # noqa pylint: disable=unused-import, redefined-builtin\n\nimport logging\n\nfrom requests import RequestException\n\nfrom flexget import plugin\nfrom flexget.entry import Entry\nfrom flexget.event import event\nfrom flexget.components.sites.utils import normalize_scene\n\nlog = logging.getLogger('argenteam')\n\n\nclass SearchArgenteam(object):\n    \"\"\" Argenteam\n    Search plugin which gives results from www.argenteam.net, latin american (Argentina) web.\n\n    Configuration:\n      - force_subtitles: [yes/no] #Force download release with subtitles made by aRGENTeaM. Default is yes\n\n    Example\n      argenteam:\n        force_subtitles: yes\n    \"\"\"\n\n    schema = {\n        'type': 'object',\n        'properties': {'force_subtitles': {'type': 'boolean', 'default': True}},\n        \"additionalProperties\": False,\n    }\n\n    base_url = 'http://www.argenteam.net/api/v1/'\n\n    @plugin.internet(log)\n    def search(self, task, entry, config):\n        \"\"\"\n            Search for releases\n        \"\"\"\n\n        entries = set()\n\n        for search_string in entry.get('search_strings', [entry['title']]):\n\n            try:\n                params = {'q': normalize_scene(search_string)}\n                resp = task.requests.get(self.base_url + 'search', params=params)\n                log.debug('Requesting: %s', resp.url)\n                response = resp.json()\n            except RequestException as e:\n                log.error('Argenteam request failed: %s', e)\n                return\n\n            if not response:\n                log.debug('Empty response from Argenteam')\n                continue\n\n            if not response.get('total'):\n                log.debug('No results found for %s', search_string)\n                continue\n\n            results = response.get('results')\n            if results[0]['type'] == 'tvshow':\n                log.error('Argenteam type tvshow not supported yet.')\n                continue\n\n            url = '{}{}?id={}'.format(self.base_url, results[0]['type'], results[0]['id'])\n            try:\n                resp = task.requests.get(url)\n                log.debug('Requesting releases for: %s', url)\n                response = resp.json()\n            except RequestException as e:\n                log.error('Argenteam request failed: %s', e)\n                return\n\n            log.debug('%s releases found.', len(response['releases']))\n            for release in response['releases']:\n                for torrent in release['torrents']:\n                    if (\n                        config.get('force_subtitles')\n                        and release['subtitles']\n                        or not config.get('force_subtitles')\n                    ):\n                        e = Entry()\n\n                        e['title'] = ' '.join(\n                            (\n                                search_string,\n                                release['source'],\n                                release['codec'],\n                                release['team'],\n                                release['tags'],\n                            )\n                        )\n                        e['url'] = torrent['uri']\n\n                        # Save aRGENTeaM subtitle URL for this release\n                        if 'subtitles' in release and len(release['subtitles']) > 0:\n                            e['argenteam_subtitle'] = release['subtitles'][0]['uri']\n                            log.debug('Argenteam subtitle found: %s', e['argenteam_subtitle'])\n\n                        if 'tvdb' in response:\n                            e['tvdb_id'] = response['tvdb']\n                        if 'info' in response and 'imdb' in response['info']:\n                            e['imdb_id'] = response['info']['imdb']\n\n                        entries.add(e)\n\n        return entries\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(SearchArgenteam, 'argenteam', interfaces=['search'], api_ver=2)\n", "path": "flexget/components/sites/sites/argenteam.py"}]}