prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  FINDSUBTITLES :: [3824246] Failed to refine video Traceback (most recent call last)
  ### Before submitting your issue:
  
  Enable debug logging in SickRage settings, reproduce the error (be sure to disable after the bug is fixed)
  
  Branch/Commit: develop/3824246
  OS: Linux
  What you did: nothing
  What happened: ~~rato appeared~~ warning
  What you expected: no warning
  Logs:
  
  ```
  2016-09-05 17:55:06 WARNING  FINDSUBTITLES :: [3824246] Failed to refine video
  Traceback (most recent call last):
    File "/home/**********/.sickrage/lib/subliminal/core.py", line 543, in refine
      refiner_manager[refiner].plugin(video, **kwargs)
    File "/home/**********/.sickrage/sickbeard/refiners/tvepisode.py", line 62, in refine
      enrich({'resolution': guess['screen_size'], 'format': guess['format']}, video, overwrite=False)
  KeyError: u'screen_size'
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `sickbeard/refiners/tvepisode.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 """TVEpisode refiner."""
  3 from __future__ import unicode_literals
  4 
  5 import logging
  6 import re
  7 
  8 from subliminal.video import Episode
  9 
  10 from ..common import Quality
  11 
  12 logger = logging.getLogger(__name__)
  13 
  14 SHOW_MAPPING = {
  15     'series_tvdb_id': 'tvdb_id',
  16     'series_imdb_id': 'imdbid',
  17     'year': 'startyear'
  18 }
  19 
  20 EPISODE_MAPPING = {
  21     'tvdb_id': 'tvdb_id',
  22     'episode': 'episode',
  23     'season': 'season',
  24     'size': 'file_size',
  25     'title': 'name',
  26 }
  27 
  28 series_re = re.compile(r'^(?P<series>.*?)(?: \((?:(?P<year>\d{4})|(?P<country>[A-Z]{2}))\))?$')
  29 
  30 
  31 def refine(video, tv_episode=None, **kwargs):
  32     """Refine a video by using TVEpisode information.
  33 
  34     :param video: the video to refine.
  35     :type video: Episode
  36     :param tv_episode: the TVEpisode to be used.
  37     :type tv_episode: sickbeard.tv.TVEpisode
  38     :param kwargs:
  39     """
  40     if video.series_tvdb_id and video.tvdb_id:
  41         logger.debug('No need to refine with TVEpisode')
  42         return
  43 
  44     if not tv_episode:
  45         logger.debug('No TVEpisode to be used to refine')
  46         return
  47 
  48     if not isinstance(video, Episode):
  49         logger.debug('Video {name} is not an episode. Skipping refiner...', name=video.name)
  50         return
  51 
  52     if tv_episode.show:
  53         logger.debug('Refining using TVShow information.')
  54         series, year, country = series_re.match(tv_episode.show.name).groups()
  55         enrich({'series': series, 'year': int(year) if year else None}, video)
  56         enrich(SHOW_MAPPING, video, tv_episode.show)
  57 
  58     logger.debug('Refining using TVEpisode information.')
  59     enrich(EPISODE_MAPPING, video, tv_episode)
  60     enrich({'release_group': tv_episode.release_group}, video, overwrite=False)
  61     guess = Quality.to_guessit(tv_episode.status)
  62     enrich({'resolution': guess['screen_size'], 'format': guess['format']}, video, overwrite=False)
  63 
  64 
  65 def enrich(attributes, target, source=None, overwrite=True):
  66     """Copy attributes from source to target.
  67 
  68     :param attributes: the attributes mapping
  69     :type attributes: dict(str -> str)
  70     :param target: the target object
  71     :param source: the source object. If None, the value in attributes dict will be used as new_value
  72     :param overwrite: if source field should be overwritten if not already set
  73     :type overwrite: bool
  74     """
  75     for key, value in attributes.items():
  76         old_value = getattr(target, key)
  77         if old_value and not overwrite:
  78             continue
  79 
  80         new_value = getattr(source, value) if source else value
  81 
  82         if new_value and old_value != new_value:
  83             setattr(target, key, new_value)
  84             logger.debug('Attribute {key} changed from {old} to {new}', key=key, old=old_value, new=new_value)
  85
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/sickbeard/refiners/tvepisode.py b/sickbeard/refiners/tvepisode.py
  --- a/sickbeard/refiners/tvepisode.py
  +++ b/sickbeard/refiners/tvepisode.py
  @@ -59,7 +59,7 @@
       enrich(EPISODE_MAPPING, video, tv_episode)
       enrich({'release_group': tv_episode.release_group}, video, overwrite=False)
       guess = Quality.to_guessit(tv_episode.status)
  -    enrich({'resolution': guess['screen_size'], 'format': guess['format']}, video, overwrite=False)
  +    enrich({'resolution': guess.get('screen_size'), 'format': guess.get('format')}, video, overwrite=False)
   
   
   def enrich(attributes, target, source=None, overwrite=True):
  
verification_info: {"golden_diff": "diff --git a/sickbeard/refiners/tvepisode.py b/sickbeard/refiners/tvepisode.py\n--- a/sickbeard/refiners/tvepisode.py\n+++ b/sickbeard/refiners/tvepisode.py\n@@ -59,7 +59,7 @@\n     enrich(EPISODE_MAPPING, video, tv_episode)\n     enrich({'release_group': tv_episode.release_group}, video, overwrite=False)\n     guess = Quality.to_guessit(tv_episode.status)\n-    enrich({'resolution': guess['screen_size'], 'format': guess['format']}, video, overwrite=False)\n+    enrich({'resolution': guess.get('screen_size'), 'format': guess.get('format')}, video, overwrite=False)\n \n \n def enrich(attributes, target, source=None, overwrite=True):\n", "issue": "FINDSUBTITLES :: [3824246] Failed to refine video Traceback (most recent call last)\n### Before submitting your issue:\n\nEnable debug logging in SickRage settings, reproduce the error (be sure to disable after the bug is fixed)\n\nBranch/Commit: develop/3824246\nOS: Linux\nWhat you did: nothing\nWhat happened: ~~rato appeared~~ warning\nWhat you expected: no warning\nLogs:\n\n```\n2016-09-05 17:55:06 WARNING  FINDSUBTITLES :: [3824246] Failed to refine video\nTraceback (most recent call last):\n  File \"/home/**********/.sickrage/lib/subliminal/core.py\", line 543, in refine\n    refiner_manager[refiner].plugin(video, **kwargs)\n  File \"/home/**********/.sickrage/sickbeard/refiners/tvepisode.py\", line 62, in refine\n    enrich({'resolution': guess['screen_size'], 'format': guess['format']}, video, overwrite=False)\nKeyError: u'screen_size'\n```\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"TVEpisode refiner.\"\"\"\nfrom __future__ import unicode_literals\n\nimport logging\nimport re\n\nfrom subliminal.video import Episode\n\nfrom ..common import Quality\n\nlogger = logging.getLogger(__name__)\n\nSHOW_MAPPING = {\n    'series_tvdb_id': 'tvdb_id',\n    'series_imdb_id': 'imdbid',\n    'year': 'startyear'\n}\n\nEPISODE_MAPPING = {\n    'tvdb_id': 'tvdb_id',\n    'episode': 'episode',\n    'season': 'season',\n    'size': 'file_size',\n    'title': 'name',\n}\n\nseries_re = re.compile(r'^(?P<series>.*?)(?: \\((?:(?P<year>\\d{4})|(?P<country>[A-Z]{2}))\\))?$')\n\n\ndef refine(video, tv_episode=None, **kwargs):\n    \"\"\"Refine a video by using TVEpisode information.\n\n    :param video: the video to refine.\n    :type video: Episode\n    :param tv_episode: the TVEpisode to be used.\n    :type tv_episode: sickbeard.tv.TVEpisode\n    :param kwargs:\n    \"\"\"\n    if video.series_tvdb_id and video.tvdb_id:\n        logger.debug('No need to refine with TVEpisode')\n        return\n\n    if not tv_episode:\n        logger.debug('No TVEpisode to be used to refine')\n        return\n\n    if not isinstance(video, Episode):\n        logger.debug('Video {name} is not an episode. Skipping refiner...', name=video.name)\n        return\n\n    if tv_episode.show:\n        logger.debug('Refining using TVShow information.')\n        series, year, country = series_re.match(tv_episode.show.name).groups()\n        enrich({'series': series, 'year': int(year) if year else None}, video)\n        enrich(SHOW_MAPPING, video, tv_episode.show)\n\n    logger.debug('Refining using TVEpisode information.')\n    enrich(EPISODE_MAPPING, video, tv_episode)\n    enrich({'release_group': tv_episode.release_group}, video, overwrite=False)\n    guess = Quality.to_guessit(tv_episode.status)\n    enrich({'resolution': guess['screen_size'], 'format': guess['format']}, video, overwrite=False)\n\n\ndef enrich(attributes, target, source=None, overwrite=True):\n    \"\"\"Copy attributes from source to target.\n\n    :param attributes: the attributes mapping\n    :type attributes: dict(str -> str)\n    :param target: the target object\n    :param source: the source object. If None, the value in attributes dict will be used as new_value\n    :param overwrite: if source field should be overwritten if not already set\n    :type overwrite: bool\n    \"\"\"\n    for key, value in attributes.items():\n        old_value = getattr(target, key)\n        if old_value and not overwrite:\n            continue\n\n        new_value = getattr(source, value) if source else value\n\n        if new_value and old_value != new_value:\n            setattr(target, key, new_value)\n            logger.debug('Attribute {key} changed from {old} to {new}', key=key, old=old_value, new=new_value)\n", "path": "sickbeard/refiners/tvepisode.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"TVEpisode refiner.\"\"\"\nfrom __future__ import unicode_literals\n\nimport logging\nimport re\n\nfrom subliminal.video import Episode\n\nfrom ..common import Quality\n\nlogger = logging.getLogger(__name__)\n\nSHOW_MAPPING = {\n    'series_tvdb_id': 'tvdb_id',\n    'series_imdb_id': 'imdbid',\n    'year': 'startyear'\n}\n\nEPISODE_MAPPING = {\n    'tvdb_id': 'tvdb_id',\n    'episode': 'episode',\n    'season': 'season',\n    'size': 'file_size',\n    'title': 'name',\n}\n\nseries_re = re.compile(r'^(?P<series>.*?)(?: \\((?:(?P<year>\\d{4})|(?P<country>[A-Z]{2}))\\))?$')\n\n\ndef refine(video, tv_episode=None, **kwargs):\n    \"\"\"Refine a video by using TVEpisode information.\n\n    :param video: the video to refine.\n    :type video: Episode\n    :param tv_episode: the TVEpisode to be used.\n    :type tv_episode: sickbeard.tv.TVEpisode\n    :param kwargs:\n    \"\"\"\n    if video.series_tvdb_id and video.tvdb_id:\n        logger.debug('No need to refine with TVEpisode')\n        return\n\n    if not tv_episode:\n        logger.debug('No TVEpisode to be used to refine')\n        return\n\n    if not isinstance(video, Episode):\n        logger.debug('Video {name} is not an episode. Skipping refiner...', name=video.name)\n        return\n\n    if tv_episode.show:\n        logger.debug('Refining using TVShow information.')\n        series, year, country = series_re.match(tv_episode.show.name).groups()\n        enrich({'series': series, 'year': int(year) if year else None}, video)\n        enrich(SHOW_MAPPING, video, tv_episode.show)\n\n    logger.debug('Refining using TVEpisode information.')\n    enrich(EPISODE_MAPPING, video, tv_episode)\n    enrich({'release_group': tv_episode.release_group}, video, overwrite=False)\n    guess = Quality.to_guessit(tv_episode.status)\n    enrich({'resolution': guess.get('screen_size'), 'format': guess.get('format')}, video, overwrite=False)\n\n\ndef enrich(attributes, target, source=None, overwrite=True):\n    \"\"\"Copy attributes from source to target.\n\n    :param attributes: the attributes mapping\n    :type attributes: dict(str -> str)\n    :param target: the target object\n    :param source: the source object. If None, the value in attributes dict will be used as new_value\n    :param overwrite: if source field should be overwritten if not already set\n    :type overwrite: bool\n    \"\"\"\n    for key, value in attributes.items():\n        old_value = getattr(target, key)\n        if old_value and not overwrite:\n            continue\n\n        new_value = getattr(source, value) if source else value\n\n        if new_value and old_value != new_value:\n            setattr(target, key, new_value)\n            logger.debug('Attribute {key} changed from {old} to {new}', key=key, old=old_value, new=new_value)\n", "path": "sickbeard/refiners/tvepisode.py"}]}