prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Input plugin "imdb_list" currently failing to fetch lists behind authentication
  Message: `There was an error during imdb_list input (Unable to get imdb list: 404 Client Error: Not Found), using cache instead."`
  
  Same issue as, http://flexget.com/ticket/2313 but even with the most recent fix applied it still fails.
  
  
  </issue>
  <code>
  [start of flexget/plugins/input/imdb_list.py]
  1 from __future__ import unicode_literals, division, absolute_import
  2 import logging
  3 import csv
  4 import re
  5 from cgi import parse_header
  6 
  7 from flexget import plugin
  8 from flexget.event import event
  9 from flexget.utils import requests
  10 from flexget.utils.imdb import make_url
  11 from flexget.utils.cached_input import cached
  12 from flexget.utils.tools import decode_html
  13 from flexget.entry import Entry
  14 from flexget.utils.soup import get_soup
  15 
  16 log = logging.getLogger('imdb_list')
  17 
  18 USER_ID_RE = r'^ur\d{7,8}$'
  19 
  20 
  21 class ImdbList(object):
  22     """"Creates an entry for each movie in your imdb list."""
  23 
  24     schema = {
  25         'type': 'object',
  26         'properties': {
  27             'user_id': {
  28                 'type': 'string',
  29                 'pattern': USER_ID_RE,
  30                 'error_pattern': 'user_id must be in the form urXXXXXXX'
  31             },
  32             'username': {'type': 'string'},
  33             'password': {'type': 'string'},
  34             'list': {'type': 'string'}
  35         },
  36         'required': ['list'],
  37         'additionalProperties': False
  38     }
  39 
  40     @cached('imdb_list', persist='2 hours')
  41     def on_task_input(self, task, config):
  42         sess = requests.Session()
  43         if config.get('username') and config.get('password'):
  44 
  45             log.verbose('Logging in ...')
  46 
  47             # Log in to imdb with our handler
  48             params = {'login': config['username'], 'password': config['password']}
  49             try:
  50                 # First get the login page so we can get the hidden input value
  51                 soup = get_soup(sess.get('https://secure.imdb.com/register-imdb/login').content)
  52 
  53                 # Fix for bs4 bug. see #2313 and github#118
  54                 auxsoup = soup.find('div', id='nb20').next_sibling.next_sibling
  55                 tag = auxsoup.find('input', attrs={'name': '49e6c'})
  56                 if tag:
  57                     params['49e6c'] = tag['value']
  58                 else:
  59                     log.warning('Unable to find required info for imdb login, maybe their login method has changed.')
  60                 # Now we do the actual login with appropriate parameters
  61                 r = sess.post('https://secure.imdb.com/register-imdb/login', data=params, raise_status=False)
  62             except requests.RequestException as e:
  63                 raise plugin.PluginError('Unable to login to imdb: %s' % e.message)
  64 
  65             # IMDb redirects us upon a successful login.
  66             # removed - doesn't happen always?
  67             # if r.status_code != 302:
  68             #     log.warning('It appears logging in to IMDb was unsuccessful.')
  69 
  70             # try to automatically figure out user_id from watchlist redirect url
  71             if not 'user_id' in config:
  72                 log.verbose('Getting user_id ...')
  73                 try:
  74                     response = sess.get('http://www.imdb.com/list/watchlist')
  75                 except requests.RequestException as e:
  76                     log.error('Error retrieving user ID from imdb: %s' % e.message)
  77                     user_id = ''
  78                 else:
  79                     log.debug('redirected to %s' % response.url)
  80                     user_id = response.url.split('/')[-2]
  81                 if re.match(USER_ID_RE, user_id):
  82                     config['user_id'] = user_id
  83                 else:
  84                     raise plugin.PluginError('Couldn\'t figure out user_id, please configure it manually.')
  85 
  86         if not 'user_id' in config:
  87             raise plugin.PluginError('Configuration option `user_id` required.')
  88 
  89         log.verbose('Retrieving list %s ...' % config['list'])
  90 
  91         # Get the imdb list in csv format
  92         try:
  93             url = 'http://www.imdb.com/list/export'
  94             params = {'list_id': config['list'], 'author_id': config['user_id']}
  95             log.debug('Requesting %s' % url)
  96             opener = sess.get(url, params=params)
  97             mime_type = parse_header(opener.headers['content-type'])[0]
  98             log.debug('mime_type: %s' % mime_type)
  99             if mime_type != 'text/csv':
  100                 raise plugin.PluginError('Didn\'t get CSV export as response. Probably specified list `%s` '
  101                                          'does not exist.' % config['list'])
  102             csv_rows = csv.reader(opener.iter_lines())
  103         except requests.RequestException as e:
  104             raise plugin.PluginError('Unable to get imdb list: %s' % e.message)
  105 
  106         # Create an Entry for each movie in the list
  107         entries = []
  108         for row in csv_rows:
  109             if not row or row[0] == 'position':
  110                 # Don't use blank rows or the headings row
  111                 continue
  112             try:
  113                 title = decode_html(row[5]).decode('utf-8')
  114                 entries.append(Entry(title=title, url=make_url(row[1]), imdb_id=row[1], imdb_name=title))
  115             except IndexError:
  116                 log.critical('IndexError! Unable to handle row: %s' % row)
  117         return entries
  118 
  119 
  120 @event('plugin.register')
  121 def register_plugin():
  122     plugin.register(ImdbList, 'imdb_list', api_ver=2)
  123
  [end of flexget/plugins/input/imdb_list.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/imdb_list.py b/flexget/plugins/input/imdb_list.py
  --- a/flexget/plugins/input/imdb_list.py
  +++ b/flexget/plugins/input/imdb_list.py
  @@ -1,13 +1,13 @@
   from __future__ import unicode_literals, division, absolute_import
   import logging
  -import csv
  +import feedparser
   import re
   from cgi import parse_header
   
   from flexget import plugin
   from flexget.event import event
   from flexget.utils import requests
  -from flexget.utils.imdb import make_url
  +from flexget.utils.imdb import make_url, extract_id
   from flexget.utils.cached_input import cached
   from flexget.utils.tools import decode_html
   from flexget.entry import Entry
  @@ -88,32 +88,27 @@
   
           log.verbose('Retrieving list %s ...' % config['list'])
   
  -        # Get the imdb list in csv format
  +        # Get the imdb list in RSS format
           try:
  -            url = 'http://www.imdb.com/list/export'
  -            params = {'list_id': config['list'], 'author_id': config['user_id']}
  +            if config['list'] in ['watchlist', 'ratings', 'checkins']:
  +                url = 'http://rss.imdb.com/user/%s/%s' % (config['user_id'], config['list'])
  +            else:
  +                url = 'http://rss.imdb.com/list/%s' % config['list']
               log.debug('Requesting %s' % url)
  -            opener = sess.get(url, params=params)
  -            mime_type = parse_header(opener.headers['content-type'])[0]
  -            log.debug('mime_type: %s' % mime_type)
  -            if mime_type != 'text/csv':
  -                raise plugin.PluginError('Didn\'t get CSV export as response. Probably specified list `%s` '
  -                                         'does not exist.' % config['list'])
  -            csv_rows = csv.reader(opener.iter_lines())
  +            try:
  +                rss = feedparser.parse(url)
  +            except LookupError as e:
  +                raise plugin.PluginError('Failed to parse RSS feed for list `%s` correctly: %s' % (config['list'], e))
           except requests.RequestException as e:
               raise plugin.PluginError('Unable to get imdb list: %s' % e.message)
   
           # Create an Entry for each movie in the list
           entries = []
  -        for row in csv_rows:
  -            if not row or row[0] == 'position':
  -                # Don't use blank rows or the headings row
  -                continue
  +        for entry in rss.entries:
               try:
  -                title = decode_html(row[5]).decode('utf-8')
  -                entries.append(Entry(title=title, url=make_url(row[1]), imdb_id=row[1], imdb_name=title))
  +                entries.append(Entry(title=entry.title, url=entry.link, imdb_id=extract_id(entry.link), imdb_name=entry.title))
               except IndexError:
  -                log.critical('IndexError! Unable to handle row: %s' % row)
  +                log.critical('IndexError! Unable to handle RSS entry: %s' % entry)
           return entries
  
verification_info: {"golden_diff": "diff --git a/flexget/plugins/input/imdb_list.py b/flexget/plugins/input/imdb_list.py\n--- a/flexget/plugins/input/imdb_list.py\n+++ b/flexget/plugins/input/imdb_list.py\n@@ -1,13 +1,13 @@\n from __future__ import unicode_literals, division, absolute_import\n import logging\n-import csv\n+import feedparser\n import re\n from cgi import parse_header\n \n from flexget import plugin\n from flexget.event import event\n from flexget.utils import requests\n-from flexget.utils.imdb import make_url\n+from flexget.utils.imdb import make_url, extract_id\n from flexget.utils.cached_input import cached\n from flexget.utils.tools import decode_html\n from flexget.entry import Entry\n@@ -88,32 +88,27 @@\n \n         log.verbose('Retrieving list %s ...' % config['list'])\n \n-        # Get the imdb list in csv format\n+        # Get the imdb list in RSS format\n         try:\n-            url = 'http://www.imdb.com/list/export'\n-            params = {'list_id': config['list'], 'author_id': config['user_id']}\n+            if config['list'] in ['watchlist', 'ratings', 'checkins']:\n+                url = 'http://rss.imdb.com/user/%s/%s' % (config['user_id'], config['list'])\n+            else:\n+                url = 'http://rss.imdb.com/list/%s' % config['list']\n             log.debug('Requesting %s' % url)\n-            opener = sess.get(url, params=params)\n-            mime_type = parse_header(opener.headers['content-type'])[0]\n-            log.debug('mime_type: %s' % mime_type)\n-            if mime_type != 'text/csv':\n-                raise plugin.PluginError('Didn\\'t get CSV export as response. Probably specified list `%s` '\n-                                         'does not exist.' % config['list'])\n-            csv_rows = csv.reader(opener.iter_lines())\n+            try:\n+                rss = feedparser.parse(url)\n+            except LookupError as e:\n+                raise plugin.PluginError('Failed to parse RSS feed for list `%s` correctly: %s' % (config['list'], e))\n         except requests.RequestException as e:\n             raise plugin.PluginError('Unable to get imdb list: %s' % e.message)\n \n         # Create an Entry for each movie in the list\n         entries = []\n-        for row in csv_rows:\n-            if not row or row[0] == 'position':\n-                # Don't use blank rows or the headings row\n-                continue\n+        for entry in rss.entries:\n             try:\n-                title = decode_html(row[5]).decode('utf-8')\n-                entries.append(Entry(title=title, url=make_url(row[1]), imdb_id=row[1], imdb_name=title))\n+                entries.append(Entry(title=entry.title, url=entry.link, imdb_id=extract_id(entry.link), imdb_name=entry.title))\n             except IndexError:\n-                log.critical('IndexError! Unable to handle row: %s' % row)\n+                log.critical('IndexError! Unable to handle RSS entry: %s' % entry)\n         return entries\n", "issue": "Input plugin \"imdb_list\" currently failing to fetch lists behind authentication\nMessage: `There was an error during imdb_list input (Unable to get imdb list: 404 Client Error: Not Found), using cache instead.\"`\n\nSame issue as, http://flexget.com/ticket/2313 but even with the most recent fix applied it still fails.\n\n", "before_files": [{"content": "from __future__ import unicode_literals, division, absolute_import\nimport logging\nimport csv\nimport re\nfrom cgi import parse_header\n\nfrom flexget import plugin\nfrom flexget.event import event\nfrom flexget.utils import requests\nfrom flexget.utils.imdb import make_url\nfrom flexget.utils.cached_input import cached\nfrom flexget.utils.tools import decode_html\nfrom flexget.entry import Entry\nfrom flexget.utils.soup import get_soup\n\nlog = logging.getLogger('imdb_list')\n\nUSER_ID_RE = r'^ur\\d{7,8}$'\n\n\nclass ImdbList(object):\n    \"\"\"\"Creates an entry for each movie in your imdb list.\"\"\"\n\n    schema = {\n        'type': 'object',\n        'properties': {\n            'user_id': {\n                'type': 'string',\n                'pattern': USER_ID_RE,\n                'error_pattern': 'user_id must be in the form urXXXXXXX'\n            },\n            'username': {'type': 'string'},\n            'password': {'type': 'string'},\n            'list': {'type': 'string'}\n        },\n        'required': ['list'],\n        'additionalProperties': False\n    }\n\n    @cached('imdb_list', persist='2 hours')\n    def on_task_input(self, task, config):\n        sess = requests.Session()\n        if config.get('username') and config.get('password'):\n\n            log.verbose('Logging in ...')\n\n            # Log in to imdb with our handler\n            params = {'login': config['username'], 'password': config['password']}\n            try:\n                # First get the login page so we can get the hidden input value\n                soup = get_soup(sess.get('https://secure.imdb.com/register-imdb/login').content)\n\n                # Fix for bs4 bug. see #2313 and github#118\n                auxsoup = soup.find('div', id='nb20').next_sibling.next_sibling\n                tag = auxsoup.find('input', attrs={'name': '49e6c'})\n                if tag:\n                    params['49e6c'] = tag['value']\n                else:\n                    log.warning('Unable to find required info for imdb login, maybe their login method has changed.')\n                # Now we do the actual login with appropriate parameters\n                r = sess.post('https://secure.imdb.com/register-imdb/login', data=params, raise_status=False)\n            except requests.RequestException as e:\n                raise plugin.PluginError('Unable to login to imdb: %s' % e.message)\n\n            # IMDb redirects us upon a successful login.\n            # removed - doesn't happen always?\n            # if r.status_code != 302:\n            #     log.warning('It appears logging in to IMDb was unsuccessful.')\n\n            # try to automatically figure out user_id from watchlist redirect url\n            if not 'user_id' in config:\n                log.verbose('Getting user_id ...')\n                try:\n                    response = sess.get('http://www.imdb.com/list/watchlist')\n                except requests.RequestException as e:\n                    log.error('Error retrieving user ID from imdb: %s' % e.message)\n                    user_id = ''\n                else:\n                    log.debug('redirected to %s' % response.url)\n                    user_id = response.url.split('/')[-2]\n                if re.match(USER_ID_RE, user_id):\n                    config['user_id'] = user_id\n                else:\n                    raise plugin.PluginError('Couldn\\'t figure out user_id, please configure it manually.')\n\n        if not 'user_id' in config:\n            raise plugin.PluginError('Configuration option `user_id` required.')\n\n        log.verbose('Retrieving list %s ...' % config['list'])\n\n        # Get the imdb list in csv format\n        try:\n            url = 'http://www.imdb.com/list/export'\n            params = {'list_id': config['list'], 'author_id': config['user_id']}\n            log.debug('Requesting %s' % url)\n            opener = sess.get(url, params=params)\n            mime_type = parse_header(opener.headers['content-type'])[0]\n            log.debug('mime_type: %s' % mime_type)\n            if mime_type != 'text/csv':\n                raise plugin.PluginError('Didn\\'t get CSV export as response. Probably specified list `%s` '\n                                         'does not exist.' % config['list'])\n            csv_rows = csv.reader(opener.iter_lines())\n        except requests.RequestException as e:\n            raise plugin.PluginError('Unable to get imdb list: %s' % e.message)\n\n        # Create an Entry for each movie in the list\n        entries = []\n        for row in csv_rows:\n            if not row or row[0] == 'position':\n                # Don't use blank rows or the headings row\n                continue\n            try:\n                title = decode_html(row[5]).decode('utf-8')\n                entries.append(Entry(title=title, url=make_url(row[1]), imdb_id=row[1], imdb_name=title))\n            except IndexError:\n                log.critical('IndexError! Unable to handle row: %s' % row)\n        return entries\n\n\n@event('plugin.register')\ndef register_plugin():\n    plugin.register(ImdbList, 'imdb_list', api_ver=2)\n", "path": "flexget/plugins/input/imdb_list.py"}]}