prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  importfeeds: name of m3u_multi playlist get messed up when both m3u* options are on
  activate both m3u output formats   
  
  ```
   importfeeds:
          formats: m3u m3u_multi
  ```
  
  Result : m3u_multi filename is not `<date> <track/album name>` as expected
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `beetsplug/importfeeds.py`
  Content:
  ```
  1 # This file is part of beets.
  2 # Copyright 2015, Fabrice Laporte.
  3 #
  4 # Permission is hereby granted, free of charge, to any person obtaining
  5 # a copy of this software and associated documentation files (the
  6 # "Software"), to deal in the Software without restriction, including
  7 # without limitation the rights to use, copy, modify, merge, publish,
  8 # distribute, sublicense, and/or sell copies of the Software, and to
  9 # permit persons to whom the Software is furnished to do so, subject to
  10 # the following conditions:
  11 #
  12 # The above copyright notice and this permission notice shall be
  13 # included in all copies or substantial portions of the Software.
  14 
  15 from __future__ import (division, absolute_import, print_function,
  16                         unicode_literals)
  17 
  18 """Write paths of imported files in various formats to ease later import in a
  19 music player. Also allow printing the new file locations to stdout in case
  20 one wants to manually add music to a player by its path.
  21 """
  22 import datetime
  23 import os
  24 import re
  25 
  26 from beets.plugins import BeetsPlugin
  27 from beets.util import mkdirall, normpath, syspath, bytestring_path
  28 from beets import config
  29 
  30 M3U_DEFAULT_NAME = 'imported.m3u'
  31 
  32 
  33 def _get_feeds_dir(lib):
  34     """Given a Library object, return the path to the feeds directory to be
  35     used (either in the library directory or an explicitly configured
  36     path). Ensures that the directory exists.
  37     """
  38     # Inside library directory.
  39     dirpath = lib.directory
  40 
  41     # Ensure directory exists.
  42     if not os.path.exists(syspath(dirpath)):
  43         os.makedirs(syspath(dirpath))
  44     return dirpath
  45 
  46 
  47 def _build_m3u_filename(basename):
  48     """Builds unique m3u filename by appending given basename to current
  49     date."""
  50 
  51     basename = re.sub(r"[\s,/\\'\"]", '_', basename)
  52     date = datetime.datetime.now().strftime("%Y%m%d_%Hh%M")
  53     path = normpath(os.path.join(
  54         config['importfeeds']['dir'].as_filename(),
  55         date + '_' + basename + '.m3u'
  56     ))
  57     return path
  58 
  59 
  60 def _write_m3u(m3u_path, items_paths):
  61     """Append relative paths to items into m3u file.
  62     """
  63     mkdirall(m3u_path)
  64     with open(syspath(m3u_path), 'a') as f:
  65         for path in items_paths:
  66             f.write(path + b'\n')
  67 
  68 
  69 class ImportFeedsPlugin(BeetsPlugin):
  70     def __init__(self):
  71         super(ImportFeedsPlugin, self).__init__()
  72 
  73         self.config.add({
  74             'formats': [],
  75             'm3u_name': u'imported.m3u',
  76             'dir': None,
  77             'relative_to': None,
  78             'absolute_path': False,
  79         })
  80 
  81         feeds_dir = self.config['dir'].get()
  82         if feeds_dir:
  83             feeds_dir = os.path.expanduser(bytestring_path(feeds_dir))
  84             self.config['dir'] = feeds_dir
  85             if not os.path.exists(syspath(feeds_dir)):
  86                 os.makedirs(syspath(feeds_dir))
  87 
  88         relative_to = self.config['relative_to'].get()
  89         if relative_to:
  90             self.config['relative_to'] = normpath(relative_to)
  91         else:
  92             self.config['relative_to'] = feeds_dir
  93 
  94         self.register_listener('library_opened', self.library_opened)
  95         self.register_listener('album_imported', self.album_imported)
  96         self.register_listener('item_imported', self.item_imported)
  97 
  98     def _record_items(self, lib, basename, items):
  99         """Records relative paths to the given items for each feed format
  100         """
  101         feedsdir = bytestring_path(self.config['dir'].as_filename())
  102         formats = self.config['formats'].as_str_seq()
  103         relative_to = self.config['relative_to'].get() \
  104             or self.config['dir'].as_filename()
  105         relative_to = bytestring_path(relative_to)
  106 
  107         paths = []
  108         for item in items:
  109             if self.config['absolute_path']:
  110                 paths.append(item.path)
  111             else:
  112                 try:
  113                     relpath = os.path.relpath(item.path, relative_to)
  114                 except ValueError:
  115                     # On Windows, it is sometimes not possible to construct a
  116                     # relative path (if the files are on different disks).
  117                     relpath = item.path
  118                 paths.append(relpath)
  119 
  120         if 'm3u' in formats:
  121             basename = bytestring_path(
  122                 self.config['m3u_name'].get(unicode)
  123             )
  124             m3u_path = os.path.join(feedsdir, basename)
  125             _write_m3u(m3u_path, paths)
  126 
  127         if 'm3u_multi' in formats:
  128             m3u_path = _build_m3u_filename(basename)
  129             _write_m3u(m3u_path, paths)
  130 
  131         if 'link' in formats:
  132             for path in paths:
  133                 dest = os.path.join(feedsdir, os.path.basename(path))
  134                 if not os.path.exists(syspath(dest)):
  135                     os.symlink(syspath(path), syspath(dest))
  136 
  137         if 'echo' in formats:
  138             self._log.info("Location of imported music:")
  139             for path in paths:
  140                 self._log.info("  {0}", path)
  141 
  142     def library_opened(self, lib):
  143         if self.config['dir'].get() is None:
  144             self.config['dir'] = _get_feeds_dir(lib)
  145 
  146     def album_imported(self, lib, album):
  147         self._record_items(lib, album.album, album.items())
  148 
  149     def item_imported(self, lib, item):
  150         self._record_items(lib, item.title, [item])
  151
  ```
  --- 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/beetsplug/importfeeds.py b/beetsplug/importfeeds.py
  --- a/beetsplug/importfeeds.py
  +++ b/beetsplug/importfeeds.py
  @@ -118,10 +118,9 @@
                   paths.append(relpath)
   
           if 'm3u' in formats:
  -            basename = bytestring_path(
  -                self.config['m3u_name'].get(unicode)
  -            )
  -            m3u_path = os.path.join(feedsdir, basename)
  +            m3u_basename = bytestring_path(
  +                self.config['m3u_name'].get(unicode))
  +            m3u_path = os.path.join(feedsdir, m3u_basename)
               _write_m3u(m3u_path, paths)
   
           if 'm3u_multi' in formats:
  
verification_info: {"golden_diff": "diff --git a/beetsplug/importfeeds.py b/beetsplug/importfeeds.py\n--- a/beetsplug/importfeeds.py\n+++ b/beetsplug/importfeeds.py\n@@ -118,10 +118,9 @@\n                 paths.append(relpath)\n \n         if 'm3u' in formats:\n-            basename = bytestring_path(\n-                self.config['m3u_name'].get(unicode)\n-            )\n-            m3u_path = os.path.join(feedsdir, basename)\n+            m3u_basename = bytestring_path(\n+                self.config['m3u_name'].get(unicode))\n+            m3u_path = os.path.join(feedsdir, m3u_basename)\n             _write_m3u(m3u_path, paths)\n \n         if 'm3u_multi' in formats:\n", "issue": "importfeeds: name of m3u_multi playlist get messed up when both m3u* options are on\nactivate both m3u output formats   \n\n```\n importfeeds:\n        formats: m3u m3u_multi\n```\n\nResult : m3u_multi filename is not `<date> <track/album name>` as expected\n\n", "before_files": [{"content": "# This file is part of beets.\n# Copyright 2015, Fabrice Laporte.\n#\n# Permission is hereby granted, free of charge, to any person obtaining\n# a copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the Software, and to\n# permit persons to whom the Software is furnished to do so, subject to\n# the following conditions:\n#\n# The above copyright notice and this permission notice shall be\n# included in all copies or substantial portions of the Software.\n\nfrom __future__ import (division, absolute_import, print_function,\n                        unicode_literals)\n\n\"\"\"Write paths of imported files in various formats to ease later import in a\nmusic player. Also allow printing the new file locations to stdout in case\none wants to manually add music to a player by its path.\n\"\"\"\nimport datetime\nimport os\nimport re\n\nfrom beets.plugins import BeetsPlugin\nfrom beets.util import mkdirall, normpath, syspath, bytestring_path\nfrom beets import config\n\nM3U_DEFAULT_NAME = 'imported.m3u'\n\n\ndef _get_feeds_dir(lib):\n    \"\"\"Given a Library object, return the path to the feeds directory to be\n    used (either in the library directory or an explicitly configured\n    path). Ensures that the directory exists.\n    \"\"\"\n    # Inside library directory.\n    dirpath = lib.directory\n\n    # Ensure directory exists.\n    if not os.path.exists(syspath(dirpath)):\n        os.makedirs(syspath(dirpath))\n    return dirpath\n\n\ndef _build_m3u_filename(basename):\n    \"\"\"Builds unique m3u filename by appending given basename to current\n    date.\"\"\"\n\n    basename = re.sub(r\"[\\s,/\\\\'\\\"]\", '_', basename)\n    date = datetime.datetime.now().strftime(\"%Y%m%d_%Hh%M\")\n    path = normpath(os.path.join(\n        config['importfeeds']['dir'].as_filename(),\n        date + '_' + basename + '.m3u'\n    ))\n    return path\n\n\ndef _write_m3u(m3u_path, items_paths):\n    \"\"\"Append relative paths to items into m3u file.\n    \"\"\"\n    mkdirall(m3u_path)\n    with open(syspath(m3u_path), 'a') as f:\n        for path in items_paths:\n            f.write(path + b'\\n')\n\n\nclass ImportFeedsPlugin(BeetsPlugin):\n    def __init__(self):\n        super(ImportFeedsPlugin, self).__init__()\n\n        self.config.add({\n            'formats': [],\n            'm3u_name': u'imported.m3u',\n            'dir': None,\n            'relative_to': None,\n            'absolute_path': False,\n        })\n\n        feeds_dir = self.config['dir'].get()\n        if feeds_dir:\n            feeds_dir = os.path.expanduser(bytestring_path(feeds_dir))\n            self.config['dir'] = feeds_dir\n            if not os.path.exists(syspath(feeds_dir)):\n                os.makedirs(syspath(feeds_dir))\n\n        relative_to = self.config['relative_to'].get()\n        if relative_to:\n            self.config['relative_to'] = normpath(relative_to)\n        else:\n            self.config['relative_to'] = feeds_dir\n\n        self.register_listener('library_opened', self.library_opened)\n        self.register_listener('album_imported', self.album_imported)\n        self.register_listener('item_imported', self.item_imported)\n\n    def _record_items(self, lib, basename, items):\n        \"\"\"Records relative paths to the given items for each feed format\n        \"\"\"\n        feedsdir = bytestring_path(self.config['dir'].as_filename())\n        formats = self.config['formats'].as_str_seq()\n        relative_to = self.config['relative_to'].get() \\\n            or self.config['dir'].as_filename()\n        relative_to = bytestring_path(relative_to)\n\n        paths = []\n        for item in items:\n            if self.config['absolute_path']:\n                paths.append(item.path)\n            else:\n                try:\n                    relpath = os.path.relpath(item.path, relative_to)\n                except ValueError:\n                    # On Windows, it is sometimes not possible to construct a\n                    # relative path (if the files are on different disks).\n                    relpath = item.path\n                paths.append(relpath)\n\n        if 'm3u' in formats:\n            basename = bytestring_path(\n                self.config['m3u_name'].get(unicode)\n            )\n            m3u_path = os.path.join(feedsdir, basename)\n            _write_m3u(m3u_path, paths)\n\n        if 'm3u_multi' in formats:\n            m3u_path = _build_m3u_filename(basename)\n            _write_m3u(m3u_path, paths)\n\n        if 'link' in formats:\n            for path in paths:\n                dest = os.path.join(feedsdir, os.path.basename(path))\n                if not os.path.exists(syspath(dest)):\n                    os.symlink(syspath(path), syspath(dest))\n\n        if 'echo' in formats:\n            self._log.info(\"Location of imported music:\")\n            for path in paths:\n                self._log.info(\"  {0}\", path)\n\n    def library_opened(self, lib):\n        if self.config['dir'].get() is None:\n            self.config['dir'] = _get_feeds_dir(lib)\n\n    def album_imported(self, lib, album):\n        self._record_items(lib, album.album, album.items())\n\n    def item_imported(self, lib, item):\n        self._record_items(lib, item.title, [item])\n", "path": "beetsplug/importfeeds.py"}], "after_files": [{"content": "# This file is part of beets.\n# Copyright 2015, Fabrice Laporte.\n#\n# Permission is hereby granted, free of charge, to any person obtaining\n# a copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the Software, and to\n# permit persons to whom the Software is furnished to do so, subject to\n# the following conditions:\n#\n# The above copyright notice and this permission notice shall be\n# included in all copies or substantial portions of the Software.\n\nfrom __future__ import (division, absolute_import, print_function,\n                        unicode_literals)\n\n\"\"\"Write paths of imported files in various formats to ease later import in a\nmusic player. Also allow printing the new file locations to stdout in case\none wants to manually add music to a player by its path.\n\"\"\"\nimport datetime\nimport os\nimport re\n\nfrom beets.plugins import BeetsPlugin\nfrom beets.util import mkdirall, normpath, syspath, bytestring_path\nfrom beets import config\n\nM3U_DEFAULT_NAME = 'imported.m3u'\n\n\ndef _get_feeds_dir(lib):\n    \"\"\"Given a Library object, return the path to the feeds directory to be\n    used (either in the library directory or an explicitly configured\n    path). Ensures that the directory exists.\n    \"\"\"\n    # Inside library directory.\n    dirpath = lib.directory\n\n    # Ensure directory exists.\n    if not os.path.exists(syspath(dirpath)):\n        os.makedirs(syspath(dirpath))\n    return dirpath\n\n\ndef _build_m3u_filename(basename):\n    \"\"\"Builds unique m3u filename by appending given basename to current\n    date.\"\"\"\n\n    basename = re.sub(r\"[\\s,/\\\\'\\\"]\", '_', basename)\n    date = datetime.datetime.now().strftime(\"%Y%m%d_%Hh%M\")\n    path = normpath(os.path.join(\n        config['importfeeds']['dir'].as_filename(),\n        date + '_' + basename + '.m3u'\n    ))\n    return path\n\n\ndef _write_m3u(m3u_path, items_paths):\n    \"\"\"Append relative paths to items into m3u file.\n    \"\"\"\n    mkdirall(m3u_path)\n    with open(syspath(m3u_path), 'a') as f:\n        for path in items_paths:\n            f.write(path + b'\\n')\n\n\nclass ImportFeedsPlugin(BeetsPlugin):\n    def __init__(self):\n        super(ImportFeedsPlugin, self).__init__()\n\n        self.config.add({\n            'formats': [],\n            'm3u_name': u'imported.m3u',\n            'dir': None,\n            'relative_to': None,\n            'absolute_path': False,\n        })\n\n        feeds_dir = self.config['dir'].get()\n        if feeds_dir:\n            feeds_dir = os.path.expanduser(bytestring_path(feeds_dir))\n            self.config['dir'] = feeds_dir\n            if not os.path.exists(syspath(feeds_dir)):\n                os.makedirs(syspath(feeds_dir))\n\n        relative_to = self.config['relative_to'].get()\n        if relative_to:\n            self.config['relative_to'] = normpath(relative_to)\n        else:\n            self.config['relative_to'] = feeds_dir\n\n        self.register_listener('library_opened', self.library_opened)\n        self.register_listener('album_imported', self.album_imported)\n        self.register_listener('item_imported', self.item_imported)\n\n    def _record_items(self, lib, basename, items):\n        \"\"\"Records relative paths to the given items for each feed format\n        \"\"\"\n        feedsdir = bytestring_path(self.config['dir'].as_filename())\n        formats = self.config['formats'].as_str_seq()\n        relative_to = self.config['relative_to'].get() \\\n            or self.config['dir'].as_filename()\n        relative_to = bytestring_path(relative_to)\n\n        paths = []\n        for item in items:\n            if self.config['absolute_path']:\n                paths.append(item.path)\n            else:\n                try:\n                    relpath = os.path.relpath(item.path, relative_to)\n                except ValueError:\n                    # On Windows, it is sometimes not possible to construct a\n                    # relative path (if the files are on different disks).\n                    relpath = item.path\n                paths.append(relpath)\n\n        if 'm3u' in formats:\n            m3u_basename = bytestring_path(\n                self.config['m3u_name'].get(unicode))\n            m3u_path = os.path.join(feedsdir, m3u_basename)\n            _write_m3u(m3u_path, paths)\n\n        if 'm3u_multi' in formats:\n            m3u_path = _build_m3u_filename(basename)\n            _write_m3u(m3u_path, paths)\n\n        if 'link' in formats:\n            for path in paths:\n                dest = os.path.join(feedsdir, os.path.basename(path))\n                if not os.path.exists(syspath(dest)):\n                    os.symlink(syspath(path), syspath(dest))\n\n        if 'echo' in formats:\n            self._log.info(\"Location of imported music:\")\n            for path in paths:\n                self._log.info(\"  {0}\", path)\n\n    def library_opened(self, lib):\n        if self.config['dir'].get() is None:\n            self.config['dir'] = _get_feeds_dir(lib)\n\n    def album_imported(self, lib, album):\n        self._record_items(lib, album.album, album.items())\n\n    def item_imported(self, lib, item):\n        self._record_items(lib, item.title, [item])\n", "path": "beetsplug/importfeeds.py"}]}