prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [add] jinja split: Adds split into jinja filters
  Sorry about this, I found the solution
  
  </issue>
  <code>
  [start of flexget/plugins/input/trakt_emit.py]
  1 from __future__ import unicode_literals, division, absolute_import
  2 import hashlib
  3 import logging
  4 from urlparse import urljoin
  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.utils import json
  12 from flexget.utils.trakt import API_URL, get_session, make_list_slug, get_api_url
  13 
  14 log = logging.getLogger('trakt_emit')
  15 
  16 
  17 class TraktEmit(object):
  18     """
  19     Creates an entry for the latest or the next item in your watched or collected
  20     episodes in your trakt account.
  21 
  22     Syntax:
  23 
  24     trakt_emit:
  25       username: <value>
  26       position: <last|next>
  27       context: <collect|collected|watch|watched>
  28       list: <value>
  29 
  30     Options username, password and api_key are required.
  31 
  32     """
  33 
  34     schema = {
  35         'type': 'object',
  36         'properties': {
  37             'username': {'type': 'string'},
  38             'password': {'type': 'string'},
  39             'position': {'type': 'string', 'enum': ['last', 'next'], 'default': 'next'},
  40             'context': {'type': 'string', 'enum': ['watched', 'collected'], 'default': 'watched'},
  41             'list': {'type': 'string'}
  42         },
  43         'required': ['username'],
  44         'additionalProperties': False
  45     }
  46 
  47     def on_task_input(self, task, config):
  48         session = get_session(config['username'], config.get('password'))
  49         listed_series = {}
  50         if config.get('list'):
  51             url = urljoin(API_URL, 'users/%s/' % config['username'])
  52             if config['list'] in ['collection', 'watchlist', 'watched']:
  53                 url = urljoin(url, '%s/shows' % config['list'])
  54             else:
  55                 url = urljoin(url, 'lists/%s/items' % make_list_slug(config['list']))
  56             try:
  57                 data = session.get(url).json()
  58             except RequestException as e:
  59                 raise plugin.PluginError('Unable to get trakt list `%s`: %s' % (config['list'], e))
  60             if not data:
  61                 log.warning('The list "%s" is empty.' % config['list'])
  62                 return
  63             for item in data:
  64                 if item['show'] is not None:
  65                     if not item['show']['title']:
  66                         # Seems we can get entries with a blank show title sometimes
  67                         log.warning('Found trakt list show with no series name.')
  68                         continue
  69                     trakt_id = item['show']['ids']['trakt']
  70                     listed_series[trakt_id] = {
  71                         'series_name': item['show']['title'],
  72                         'trakt_id': trakt_id,
  73                         'tvdb_id': item['show']['ids']['tvdb']}
  74         context = config['context']
  75         if context == 'collected':
  76             context = 'collection'
  77         entries = []
  78         for trakt_id, fields in listed_series.iteritems():
  79             url = get_api_url('shows', trakt_id, 'progress', context)
  80             try:
  81                 data = session.get(url).json()
  82             except RequestException as e:
  83                 raise plugin.PluginError('TODO: error message')
  84             if config['position'] == 'next' and data.get('next_episode'):
  85                 # If the next episode is already in the trakt database, we'll get it here
  86                 eps = data['next_episode']['season']
  87                 epn = data['next_episode']['number']
  88             else:
  89                 # If we need last ep, or next_episode was not provided, search for last ep
  90                 for seas in reversed(data['seasons']):
  91                     # Find the first season with collected/watched episodes
  92                     if seas['completed'] > 0:
  93                         eps = seas['number']
  94                         # Pick the highest collected/watched episode
  95                         epn = max(item['number'] for item in seas['episodes'] if item['completed'])
  96                         # If we are in next episode mode, we have to increment this number
  97                         if config['position'] == 'next':
  98                             if seas['completed'] >= seas['aired']:
  99                                 # TODO: next_episode doesn't count unaired episodes right now, this will skip to next
  100                                 # season too early when there are episodes left to air this season.
  101                                 eps += 1
  102                                 epn = 1
  103                             else:
  104                                 epn += 1
  105                         break
  106             if eps and epn:
  107                 entry = self.make_entry(fields, eps, epn)
  108                 entries.append(entry)
  109         return entries
  110 
  111     def make_entry(self, fields, season, episode):
  112         entry = Entry()
  113         entry.update(fields)
  114         entry['series_season'] = season
  115         entry['series_episode'] = episode
  116         entry['series_id_type'] = 'ep'
  117         entry['series_id'] = 'S%02dE%02d' % (season, episode)
  118         entry['title'] = entry['series_name'] + ' ' + entry['series_id']
  119         entry['url'] = 'http://trakt.tv/shows/%s/seasons/%s/episodes/%s' % (fields['trakt_id'], season, episode)
  120         return entry
  121 
  122 
  123 @event('plugin.register')
  124 def register_plugin():
  125     plugin.register(TraktEmit, 'trakt_emit', api_ver=2)
  126
  [end of flexget/plugins/input/trakt_emit.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/flexget/plugins/input/trakt_emit.py b/flexget/plugins/input/trakt_emit.py
  --- a/flexget/plugins/input/trakt_emit.py
  +++ b/flexget/plugins/input/trakt_emit.py
  @@ -1,5 +1,4 @@
   from __future__ import unicode_literals, division, absolute_import
  -import hashlib
   import logging
   from urlparse import urljoin
   
  @@ -8,7 +7,6 @@
   from flexget import plugin
   from flexget.entry import Entry
   from flexget.event import event
  -from flexget.utils import json
   from flexget.utils.trakt import API_URL, get_session, make_list_slug, get_api_url
   
   log = logging.getLogger('trakt_emit')
  @@ -103,6 +101,12 @@
                               else:
                                   epn += 1
                           break
  +                else:
  +                  if config['position'] == 'next':
  +                    eps = epn = 1
  +                  else:
  +                    # There were no watched/collected episodes, nothing to emit in 'last' mode
  +                    continue
               if eps and epn:
                   entry = self.make_entry(fields, eps, epn)
                   entries.append(entry)
  
verification_info: {"golden_diff": "diff --git a/flexget/plugins/input/trakt_emit.py b/flexget/plugins/input/trakt_emit.py\n--- a/flexget/plugins/input/trakt_emit.py\n+++ b/flexget/plugins/input/trakt_emit.py\n@@ -1,5 +1,4 @@\n from __future__ import unicode_literals, division, absolute_import\n-import hashlib\n import logging\n from urlparse import urljoin\n \n@@ -8,7 +7,6 @@\n from flexget import plugin\n from flexget.entry import Entry\n from flexget.event import event\n-from flexget.utils import json\n from flexget.utils.trakt import API_URL, get_session, make_list_slug, get_api_url\n \n log = logging.getLogger('trakt_emit')\n@@ -103,6 +101,12 @@\n                             else:\n                                 epn += 1\n                         break\n+                else:\n+                  if config['position'] == 'next':\n+                    eps = epn = 1\n+                  else:\n+                    # There were no watched/collected episodes, nothing to emit in 'last' mode\n+                    continue\n             if eps and epn:\n                 entry = self.make_entry(fields, eps, epn)\n                 entries.append(entry)\n", "issue": "[add] jinja split: Adds split into jinja filters\nSorry about this, I found the solution\n", "before_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nimport hashlib\nimport logging\nfrom urlparse import urljoin\n\nfrom requests import RequestException\n\nfrom flexget import plugin\nfrom flexget.entry import Entry\nfrom flexget.event import event\nfrom flexget.utils import json\nfrom flexget.utils.trakt import API_URL, get_session, make_list_slug, get_api_url\n\nlog = logging.getLogger('trakt_emit')\n\n\nclass TraktEmit(object):\n    \"\"\"\n    Creates an entry for the latest or the next item in your watched or collected\n    episodes in your trakt account.\n\n    Syntax:\n\n    trakt_emit:\n      username: <value>\n      position: <last|next>\n      context: <collect|collected|watch|watched>\n      list: <value>\n\n    Options username, password and api_key are required.\n\n    \"\"\"\n\n    schema = {\n        'type': 'object',\n        'properties': {\n            'username': {'type': 'string'},\n            'password': {'type': 'string'},\n            'position': {'type': 'string', 'enum': ['last', 'next'], 'default': 'next'},\n            'context': {'type': 'string', 'enum': ['watched', 'collected'], 'default': 'watched'},\n            'list': {'type': 'string'}\n        },\n        'required': ['username'],\n        'additionalProperties': False\n    }\n\n    def on_task_input(self, task, config):\n        session = get_session(config['username'], config.get('password'))\n        listed_series = {}\n        if config.get('list'):\n            url = urljoin(API_URL, 'users/%s/' % config['username'])\n            if config['list'] in ['collection', 'watchlist', 'watched']:\n                url = urljoin(url, '%s/shows' % config['list'])\n            else:\n                url = urljoin(url, 'lists/%s/items' % make_list_slug(config['list']))\n            try:\n                data = session.get(url).json()\n            except RequestException as e:\n                raise plugin.PluginError('Unable to get trakt list `%s`: %s' % (config['list'], e))\n            if not data:\n                log.warning('The list \"%s\" is empty.' % config['list'])\n                return\n            for item in data:\n                if item['show'] is not None:\n                    if not item['show']['title']:\n                        # Seems we can get entries with a blank show title sometimes\n                        log.warning('Found trakt list show with no series name.')\n                        continue\n                    trakt_id = item['show']['ids']['trakt']\n                    listed_series[trakt_id] = {\n                        'series_name': item['show']['title'],\n                        'trakt_id': trakt_id,\n                        'tvdb_id': item['show']['ids']['tvdb']}\n        context = config['context']\n        if context == 'collected':\n            context = 'collection'\n        entries = []\n        for trakt_id, fields in listed_series.iteritems():\n            url = get_api_url('shows', trakt_id, 'progress', context)\n            try:\n                data = session.get(url).json()\n            except RequestException as e:\n                raise plugin.PluginError('TODO: error message')\n            if config['position'] == 'next' and data.get('next_episode'):\n                # If the next episode is already in the trakt database, we'll get it here\n                eps = data['next_episode']['season']\n                epn = data['next_episode']['number']\n            else:\n                # If we need last ep, or next_episode was not provided, search for last ep\n                for seas in reversed(data['seasons']):\n                    # Find the first season with collected/watched episodes\n                    if seas['completed'] > 0:\n                        eps = seas['number']\n                        # Pick the highest collected/watched episode\n                        epn = max(item['number'] for item in seas['episodes'] if item['completed'])\n                        # If we are in next episode mode, we have to increment this number\n                        if config['position'] == 'next':\n                            if seas['completed'] >= seas['aired']:\n                                # TODO: next_episode doesn't count unaired episodes right now, this will skip to next\n                                # season too early when there are episodes left to air this season.\n                                eps += 1\n                                epn = 1\n                            else:\n                                epn += 1\n                        break\n            if eps and epn:\n                entry = self.make_entry(fields, eps, epn)\n                entries.append(entry)\n        return entries\n\n    def make_entry(self, fields, season, episode):\n        entry = Entry()\n        entry.update(fields)\n        entry['series_season'] = season\n        entry['series_episode'] = episode\n        entry['series_id_type'] = 'ep'\n        entry['series_id'] = 'S%02dE%02d' % (season, episode)\n        entry['title'] = entry['series_name'] + ' ' + entry['series_id']\n        entry['url'] = 'http://trakt.tv/shows/%s/seasons/%s/episodes/%s' % (fields['trakt_id'], season, episode)\n        return entry\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(TraktEmit, 'trakt_emit', api_ver=2)\n", "path": "flexget/plugins/input/trakt_emit.py"}]}