prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  UnicodeEncodeError: 'ascii' codec can't encode character u'\u014d' in position 31: ordinal not in range(128)
  ```
  Traceback (most recent call last):
    File "/home/orangepi/.sickrage/lib/subliminal/core.py", line 543, in refine
      refiner_manager[refiner].plugin(video, **kwargs)
    File "/home/orangepi/.sickrage/sickbeard/refiners/release.py", line 54, in refine
      release_file = get_release_file(dirpath, fileroot, extension) or release_file
    File "/home/orangepi/.sickrage/sickbeard/refiners/release.py", line 90, in get_release_file
      if os.path.isfile(release_file):
    File "/usr/lib/python2.7/genericpath.py", line 37, in isfile
      st = os.stat(path)
  UnicodeEncodeError: 'ascii' codec can't encode character u'\u014d' in position 31: ordinal not in range(128)
  ```
  
  This happens because the subtitle contains a non-ascii char and my locale is set to None.
  To fix this we would need to use ek() for isfile() or (better imo) use a similar solution to what we du in subtitles.py. What do you think @ratoaq2?
  
  
  --- 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/release.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 """Release refiner."""
  3 from __future__ import unicode_literals
  4 
  5 import logging
  6 import os
  7 
  8 from guessit import guessit
  9 
  10 logger = logging.getLogger(__name__)
  11 
  12 MOVIE_ATTRIBUTES = {'title': 'title', 'year': 'year', 'format': 'format', 'release_group': 'release_group',
  13                     'resolution': 'screen_size',  'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}
  14 EPISODE_ATTRIBUTES = {'series': 'title', 'season': 'season', 'episode': 'episode', 'title': 'episode_title',
  15                       'year': 'year', 'format': 'format', 'release_group': 'release_group', 'resolution': 'screen_size',
  16                       'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}
  17 
  18 
  19 def refine(video, release_name=None, release_file=None, extension='release', **kwargs):
  20     """Refine a video by using the original release name.
  21 
  22     The refiner will first try:
  23     - Read the file video_name.<extension> seeking for a release name
  24     - If no release name, it will read the release_file seeking for a release name
  25     - If no release name, it will use the release_name passed as an argument
  26     - If no release name, then no change in the video object is made
  27 
  28     When a release name is found, the video object will be enhanced using the guessit properties extracted from it.
  29 
  30     Several :class:`~subliminal.video.Video` attributes can be found:
  31 
  32       * :attr:`~subliminal.video.Video.title`
  33       * :attr:`~subliminal.video.Video.series`
  34       * :attr:`~subliminal.video.Video.season`
  35       * :attr:`~subliminal.video.Video.episode`
  36       * :attr:`~subliminal.video.Video.year`
  37       * :attr:`~subliminal.video.Video.format`
  38       * :attr:`~subliminal.video.Video.release_group`
  39       * :attr:`~subliminal.video.Video.resolution`
  40       * :attr:`~subliminal.video.Video.video_codec`
  41       * :attr:`~subliminal.video.Video.audio_codec`
  42 
  43     :param video: the video to refine.
  44     :type video: subliminal.video.Video
  45     :param str release_name: the release name to be used.
  46     :param str release_file: the release file to be used
  47     :param str extension: the release file extension.
  48     """
  49     logger.debug('Starting release refiner [extension={extension}, release_name={name}, release_file={file}]',
  50                  extension=extension, name=release_name, file=release_file)
  51     dirpath, filename = os.path.split(video.name)
  52     dirpath = dirpath or '.'
  53     fileroot, fileext = os.path.splitext(filename)
  54     release_file = get_release_file(dirpath, fileroot, extension) or release_file
  55     release_name = get_release_name(release_file) or release_name
  56 
  57     if not release_name:
  58         logger.debug('No release name for {video}', video=video.name)
  59         return
  60 
  61     release_path = os.path.join(dirpath, release_name + fileext)
  62     logger.debug('Guessing using {path}', path=release_path)
  63 
  64     guess = guessit(release_path)
  65     attributes = MOVIE_ATTRIBUTES if guess.get('type') == 'movie' else EPISODE_ATTRIBUTES
  66     for key, value in attributes.items():
  67         old_value = getattr(video, key)
  68         new_value = guess.get(value)
  69 
  70         if new_value and old_value != new_value:
  71             setattr(video, key, new_value)
  72             logger.debug('Attribute {key} changed from {old} to {new}', key=key, old=old_value, new=new_value)
  73 
  74 
  75 def get_release_file(dirpath, filename, extension):
  76     """Return the release file that should contain the release name for a given a `dirpath`, `filename` and `extension`.
  77 
  78     :param dirpath: the file base folder
  79     :type dirpath: str
  80     :param filename: the file name without extension
  81     :type filename: str
  82     :param extension:
  83     :type extension: the file extension
  84     :return: the release file if the file exists
  85     :rtype: str
  86     """
  87     release_file = os.path.join(dirpath, filename + '.' + extension)
  88 
  89     # skip if info file doesn't exist
  90     if os.path.isfile(release_file):
  91         logger.debug('Found release file {file}', file=release_file)
  92         return release_file
  93 
  94 
  95 def get_release_name(release_file):
  96     """Given a `release_file` it will return the release name.
  97 
  98     :param release_file: the text file that contains the release name
  99     :type release_file: str
  100     :return: the release name
  101     :rtype: str
  102     """
  103     if not release_file:
  104         return
  105 
  106     with open(release_file, 'r') as f:
  107         release_name = f.read().strip()
  108 
  109     # skip if no release name was found
  110     if not release_name:
  111         logger.warning('Release file {file} does not contain a release name', file=release_file)
  112 
  113     return release_name
  114
  ```
  --- 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/release.py b/sickbeard/refiners/release.py
  --- a/sickbeard/refiners/release.py
  +++ b/sickbeard/refiners/release.py
  @@ -1,6 +1,5 @@
   # -*- coding: utf-8 -*-
   """Release refiner."""
  -from __future__ import unicode_literals
   
   import logging
   import os
  @@ -10,7 +9,7 @@
   logger = logging.getLogger(__name__)
   
   MOVIE_ATTRIBUTES = {'title': 'title', 'year': 'year', 'format': 'format', 'release_group': 'release_group',
  -                    'resolution': 'screen_size',  'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}
  +                    'resolution': 'screen_size', 'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}
   EPISODE_ATTRIBUTES = {'series': 'title', 'season': 'season', 'episode': 'episode', 'title': 'episode_title',
                         'year': 'year', 'format': 'format', 'release_group': 'release_group', 'resolution': 'screen_size',
                         'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}
  
verification_info: {"golden_diff": "diff --git a/sickbeard/refiners/release.py b/sickbeard/refiners/release.py\n--- a/sickbeard/refiners/release.py\n+++ b/sickbeard/refiners/release.py\n@@ -1,6 +1,5 @@\n # -*- coding: utf-8 -*-\n \"\"\"Release refiner.\"\"\"\n-from __future__ import unicode_literals\n \n import logging\n import os\n@@ -10,7 +9,7 @@\n logger = logging.getLogger(__name__)\n \n MOVIE_ATTRIBUTES = {'title': 'title', 'year': 'year', 'format': 'format', 'release_group': 'release_group',\n-                    'resolution': 'screen_size',  'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}\n+                    'resolution': 'screen_size', 'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}\n EPISODE_ATTRIBUTES = {'series': 'title', 'season': 'season', 'episode': 'episode', 'title': 'episode_title',\n                       'year': 'year', 'format': 'format', 'release_group': 'release_group', 'resolution': 'screen_size',\n                       'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}\n", "issue": "UnicodeEncodeError: 'ascii' codec can't encode character u'\\u014d' in position 31: ordinal not in range(128)\n```\nTraceback (most recent call last):\n  File \"/home/orangepi/.sickrage/lib/subliminal/core.py\", line 543, in refine\n    refiner_manager[refiner].plugin(video, **kwargs)\n  File \"/home/orangepi/.sickrage/sickbeard/refiners/release.py\", line 54, in refine\n    release_file = get_release_file(dirpath, fileroot, extension) or release_file\n  File \"/home/orangepi/.sickrage/sickbeard/refiners/release.py\", line 90, in get_release_file\n    if os.path.isfile(release_file):\n  File \"/usr/lib/python2.7/genericpath.py\", line 37, in isfile\n    st = os.stat(path)\nUnicodeEncodeError: 'ascii' codec can't encode character u'\\u014d' in position 31: ordinal not in range(128)\n```\n\nThis happens because the subtitle contains a non-ascii char and my locale is set to None.\nTo fix this we would need to use ek() for isfile() or (better imo) use a similar solution to what we du in subtitles.py. What do you think @ratoaq2?\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Release refiner.\"\"\"\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\n\nfrom guessit import guessit\n\nlogger = logging.getLogger(__name__)\n\nMOVIE_ATTRIBUTES = {'title': 'title', 'year': 'year', 'format': 'format', 'release_group': 'release_group',\n                    'resolution': 'screen_size',  'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}\nEPISODE_ATTRIBUTES = {'series': 'title', 'season': 'season', 'episode': 'episode', 'title': 'episode_title',\n                      'year': 'year', 'format': 'format', 'release_group': 'release_group', 'resolution': 'screen_size',\n                      'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}\n\n\ndef refine(video, release_name=None, release_file=None, extension='release', **kwargs):\n    \"\"\"Refine a video by using the original release name.\n\n    The refiner will first try:\n    - Read the file video_name.<extension> seeking for a release name\n    - If no release name, it will read the release_file seeking for a release name\n    - If no release name, it will use the release_name passed as an argument\n    - If no release name, then no change in the video object is made\n\n    When a release name is found, the video object will be enhanced using the guessit properties extracted from it.\n\n    Several :class:`~subliminal.video.Video` attributes can be found:\n\n      * :attr:`~subliminal.video.Video.title`\n      * :attr:`~subliminal.video.Video.series`\n      * :attr:`~subliminal.video.Video.season`\n      * :attr:`~subliminal.video.Video.episode`\n      * :attr:`~subliminal.video.Video.year`\n      * :attr:`~subliminal.video.Video.format`\n      * :attr:`~subliminal.video.Video.release_group`\n      * :attr:`~subliminal.video.Video.resolution`\n      * :attr:`~subliminal.video.Video.video_codec`\n      * :attr:`~subliminal.video.Video.audio_codec`\n\n    :param video: the video to refine.\n    :type video: subliminal.video.Video\n    :param str release_name: the release name to be used.\n    :param str release_file: the release file to be used\n    :param str extension: the release file extension.\n    \"\"\"\n    logger.debug('Starting release refiner [extension={extension}, release_name={name}, release_file={file}]',\n                 extension=extension, name=release_name, file=release_file)\n    dirpath, filename = os.path.split(video.name)\n    dirpath = dirpath or '.'\n    fileroot, fileext = os.path.splitext(filename)\n    release_file = get_release_file(dirpath, fileroot, extension) or release_file\n    release_name = get_release_name(release_file) or release_name\n\n    if not release_name:\n        logger.debug('No release name for {video}', video=video.name)\n        return\n\n    release_path = os.path.join(dirpath, release_name + fileext)\n    logger.debug('Guessing using {path}', path=release_path)\n\n    guess = guessit(release_path)\n    attributes = MOVIE_ATTRIBUTES if guess.get('type') == 'movie' else EPISODE_ATTRIBUTES\n    for key, value in attributes.items():\n        old_value = getattr(video, key)\n        new_value = guess.get(value)\n\n        if new_value and old_value != new_value:\n            setattr(video, key, new_value)\n            logger.debug('Attribute {key} changed from {old} to {new}', key=key, old=old_value, new=new_value)\n\n\ndef get_release_file(dirpath, filename, extension):\n    \"\"\"Return the release file that should contain the release name for a given a `dirpath`, `filename` and `extension`.\n\n    :param dirpath: the file base folder\n    :type dirpath: str\n    :param filename: the file name without extension\n    :type filename: str\n    :param extension:\n    :type extension: the file extension\n    :return: the release file if the file exists\n    :rtype: str\n    \"\"\"\n    release_file = os.path.join(dirpath, filename + '.' + extension)\n\n    # skip if info file doesn't exist\n    if os.path.isfile(release_file):\n        logger.debug('Found release file {file}', file=release_file)\n        return release_file\n\n\ndef get_release_name(release_file):\n    \"\"\"Given a `release_file` it will return the release name.\n\n    :param release_file: the text file that contains the release name\n    :type release_file: str\n    :return: the release name\n    :rtype: str\n    \"\"\"\n    if not release_file:\n        return\n\n    with open(release_file, 'r') as f:\n        release_name = f.read().strip()\n\n    # skip if no release name was found\n    if not release_name:\n        logger.warning('Release file {file} does not contain a release name', file=release_file)\n\n    return release_name\n", "path": "sickbeard/refiners/release.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Release refiner.\"\"\"\n\nimport logging\nimport os\n\nfrom guessit import guessit\n\nlogger = logging.getLogger(__name__)\n\nMOVIE_ATTRIBUTES = {'title': 'title', 'year': 'year', 'format': 'format', 'release_group': 'release_group',\n                    'resolution': 'screen_size', 'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}\nEPISODE_ATTRIBUTES = {'series': 'title', 'season': 'season', 'episode': 'episode', 'title': 'episode_title',\n                      'year': 'year', 'format': 'format', 'release_group': 'release_group', 'resolution': 'screen_size',\n                      'video_codec': 'video_codec', 'audio_codec': 'audio_codec'}\n\n\ndef refine(video, release_name=None, release_file=None, extension='release', **kwargs):\n    \"\"\"Refine a video by using the original release name.\n\n    The refiner will first try:\n    - Read the file video_name.<extension> seeking for a release name\n    - If no release name, it will read the release_file seeking for a release name\n    - If no release name, it will use the release_name passed as an argument\n    - If no release name, then no change in the video object is made\n\n    When a release name is found, the video object will be enhanced using the guessit properties extracted from it.\n\n    Several :class:`~subliminal.video.Video` attributes can be found:\n\n      * :attr:`~subliminal.video.Video.title`\n      * :attr:`~subliminal.video.Video.series`\n      * :attr:`~subliminal.video.Video.season`\n      * :attr:`~subliminal.video.Video.episode`\n      * :attr:`~subliminal.video.Video.year`\n      * :attr:`~subliminal.video.Video.format`\n      * :attr:`~subliminal.video.Video.release_group`\n      * :attr:`~subliminal.video.Video.resolution`\n      * :attr:`~subliminal.video.Video.video_codec`\n      * :attr:`~subliminal.video.Video.audio_codec`\n\n    :param video: the video to refine.\n    :type video: subliminal.video.Video\n    :param str release_name: the release name to be used.\n    :param str release_file: the release file to be used\n    :param str extension: the release file extension.\n    \"\"\"\n    logger.debug('Starting release refiner [extension={extension}, release_name={name}, release_file={file}]',\n                 extension=extension, name=release_name, file=release_file)\n    dirpath, filename = os.path.split(video.name)\n    dirpath = dirpath or '.'\n    fileroot, fileext = os.path.splitext(filename)\n    release_file = get_release_file(dirpath, fileroot, extension) or release_file\n    release_name = get_release_name(release_file) or release_name\n\n    if not release_name:\n        logger.debug('No release name for {video}', video=video.name)\n        return\n\n    release_path = os.path.join(dirpath, release_name + fileext)\n    logger.debug('Guessing using {path}', path=release_path)\n\n    guess = guessit(release_path)\n    attributes = MOVIE_ATTRIBUTES if guess.get('type') == 'movie' else EPISODE_ATTRIBUTES\n    for key, value in attributes.items():\n        old_value = getattr(video, key)\n        new_value = guess.get(value)\n\n        if new_value and old_value != new_value:\n            setattr(video, key, new_value)\n            logger.debug('Attribute {key} changed from {old} to {new}', key=key, old=old_value, new=new_value)\n\n\ndef get_release_file(dirpath, filename, extension):\n    \"\"\"Return the release file that should contain the release name for a given a `dirpath`, `filename` and `extension`.\n\n    :param dirpath: the file base folder\n    :type dirpath: str\n    :param filename: the file name without extension\n    :type filename: str\n    :param extension:\n    :type extension: the file extension\n    :return: the release file if the file exists\n    :rtype: str\n    \"\"\"\n    release_file = os.path.join(dirpath, filename + '.' + extension)\n\n    # skip if info file doesn't exist\n    if os.path.isfile(release_file):\n        logger.debug('Found release file {file}', file=release_file)\n        return release_file\n\n\ndef get_release_name(release_file):\n    \"\"\"Given a `release_file` it will return the release name.\n\n    :param release_file: the text file that contains the release name\n    :type release_file: str\n    :return: the release name\n    :rtype: str\n    \"\"\"\n    if not release_file:\n        return\n\n    with open(release_file, 'r') as f:\n        release_name = f.read().strip()\n\n    # skip if no release name was found\n    if not release_name:\n        logger.warning('Release file {file} does not contain a release name', file=release_file)\n\n    return release_name\n", "path": "sickbeard/refiners/release.py"}]}