We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Use Artist Credits for tag data, but "actual" artist data for filenaming
Currently beets will always normalise [artist credit](https://musicbrainz.org/doc/Artist_Credit) data to the current artist name. However, I want to see when playing the music when, e.g., [Orgi-E](https://musicbrainz.org/artist/345fe3da-b2cb-4ad4-a1a5-43afc903663d) was credited as [Klamfyr](https://musicbrainz.org/release/d09b3568-e9cc-4458-bcf7-0c215cca75ce), but I still like the normalisation for file tree organisation purposes. This should probably be an option though, as other people will likely want to always normalise the name (and others might want to not normalise the name in the path as well).

(Somewhat related morituri issues: thomasvs/morituri#80, thomasvs/morituri#48)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `beets/autotag/__init__.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # This file is part of beets.
3 # Copyright 2016, Adrian Sampson.
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 
16 """Facilities for automatically determining files' correct metadata.
17 """
18 
19 from __future__ import division, absolute_import, print_function
20 
21 from beets import logging
22 from beets import config
23 
24 # Parts of external interface.
25 from .hooks import AlbumInfo, TrackInfo, AlbumMatch, TrackMatch  # noqa
26 from .match import tag_item, tag_album, Proposal  # noqa
27 from .match import Recommendation  # noqa
28 
29 # Global logger.
30 log = logging.getLogger('beets')
31 
32 
33 # Additional utilities for the main interface.
34 
35 def apply_item_metadata(item, track_info):
36     """Set an item's metadata from its matched TrackInfo object.
37     """
38     item.artist = track_info.artist
39     item.artist_sort = track_info.artist_sort
40     item.artist_credit = track_info.artist_credit
41     item.title = track_info.title
42     item.mb_trackid = track_info.track_id
43     if track_info.artist_id:
44         item.mb_artistid = track_info.artist_id
45     if track_info.data_source:
46         item.data_source = track_info.data_source
47 
48     if track_info.lyricist is not None:
49         item.lyricist = track_info.lyricist
50     if track_info.composer is not None:
51         item.composer = track_info.composer
52     if track_info.composer_sort is not None:
53         item.composer_sort = track_info.composer_sort
54     if track_info.arranger is not None:
55         item.arranger = track_info.arranger
56 
57     # At the moment, the other metadata is left intact (including album
58     # and track number). Perhaps these should be emptied?
59 
60 
61 def apply_metadata(album_info, mapping):
62     """Set the items' metadata to match an AlbumInfo object using a
63     mapping from Items to TrackInfo objects.
64     """
65     for item, track_info in mapping.items():
66         # Album, artist, track count.
67         if track_info.artist:
68             item.artist = track_info.artist
69         else:
70             item.artist = album_info.artist
71         item.albumartist = album_info.artist
72         item.album = album_info.album
73 
74         # Artist sort and credit names.
75         item.artist_sort = track_info.artist_sort or album_info.artist_sort
76         item.artist_credit = (track_info.artist_credit or
77                               album_info.artist_credit)
78         item.albumartist_sort = album_info.artist_sort
79         item.albumartist_credit = album_info.artist_credit
80 
81         # Release date.
82         for prefix in '', 'original_':
83             if config['original_date'] and not prefix:
84                 # Ignore specific release date.
85                 continue
86 
87             for suffix in 'year', 'month', 'day':
88                 key = prefix + suffix
89                 value = getattr(album_info, key) or 0
90 
91                 # If we don't even have a year, apply nothing.
92                 if suffix == 'year' and not value:
93                     break
94 
95                 # Otherwise, set the fetched value (or 0 for the month
96                 # and day if not available).
97                 item[key] = value
98 
99                 # If we're using original release date for both fields,
100                 # also set item.year = info.original_year, etc.
101                 if config['original_date']:
102                     item[suffix] = value
103 
104         # Title.
105         item.title = track_info.title
106 
107         if config['per_disc_numbering']:
108             # We want to let the track number be zero, but if the medium index
109             # is not provided we need to fall back to the overall index.
110             if track_info.medium_index is not None:
111                 item.track = track_info.medium_index
112             else:
113                 item.track = track_info.index
114             item.tracktotal = track_info.medium_total or len(album_info.tracks)
115         else:
116             item.track = track_info.index
117             item.tracktotal = len(album_info.tracks)
118 
119         # Disc and disc count.
120         item.disc = track_info.medium
121         item.disctotal = album_info.mediums
122 
123         # MusicBrainz IDs.
124         item.mb_trackid = track_info.track_id
125         item.mb_albumid = album_info.album_id
126         if track_info.artist_id:
127             item.mb_artistid = track_info.artist_id
128         else:
129             item.mb_artistid = album_info.artist_id
130         item.mb_albumartistid = album_info.artist_id
131         item.mb_releasegroupid = album_info.releasegroup_id
132 
133         # Compilation flag.
134         item.comp = album_info.va
135 
136         # Miscellaneous metadata.
137         for field in ('albumtype',
138                       'label',
139                       'asin',
140                       'catalognum',
141                       'script',
142                       'language',
143                       'country',
144                       'albumstatus',
145                       'albumdisambig',
146                       'data_source',):
147             value = getattr(album_info, field)
148             if value is not None:
149                 item[field] = value
150         if track_info.disctitle is not None:
151             item.disctitle = track_info.disctitle
152 
153         if track_info.media is not None:
154             item.media = track_info.media
155 
156         if track_info.lyricist is not None:
157             item.lyricist = track_info.lyricist
158         if track_info.composer is not None:
159             item.composer = track_info.composer
160         if track_info.composer_sort is not None:
161             item.composer_sort = track_info.composer_sort
162         if track_info.arranger is not None:
163             item.arranger = track_info.arranger
164 
165         item.track_alt = track_info.track_alt
166
```
--- 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()

```

diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py
--- a/beets/autotag/__init__.py
+++ b/beets/autotag/__init__.py
@@ -63,12 +63,19 @@
     mapping from Items to TrackInfo objects.
     """
     for item, track_info in mapping.items():
-        # Album, artist, track count.
-        if track_info.artist:
-            item.artist = track_info.artist
+        # Artist or artist credit.
+        if config['artist_credit']:
+            item.artist = (track_info.artist_credit or
+                           track_info.artist or
+                           album_info.artist_credit or
+                           album_info.artist)
+            item.albumartist = (album_info.artist_credit or
+                                album_info.artist)
         else:
-            item.artist = album_info.artist
-        item.albumartist = album_info.artist
+            item.artist = (track_info.artist or album_info.artist)
+            item.albumartist = album_info.artist
+
+        # Album.
         item.album = album_info.album
 
         # Artist sort and credit names.

{"golden_diff": "diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py\n--- a/beets/autotag/__init__.py\n+++ b/beets/autotag/__init__.py\n@@ -63,12 +63,19 @@\n     mapping from Items to TrackInfo objects.\n     \"\"\"\n     for item, track_info in mapping.items():\n-        # Album, artist, track count.\n-        if track_info.artist:\n-            item.artist = track_info.artist\n+        # Artist or artist credit.\n+        if config['artist_credit']:\n+            item.artist = (track_info.artist_credit or\n+                           track_info.artist or\n+                           album_info.artist_credit or\n+                           album_info.artist)\n+            item.albumartist = (album_info.artist_credit or\n+                                album_info.artist)\n         else:\n-            item.artist = album_info.artist\n-        item.albumartist = album_info.artist\n+            item.artist = (track_info.artist or album_info.artist)\n+            item.albumartist = album_info.artist\n+\n+        # Album.\n         item.album = album_info.album\n \n         # Artist sort and credit names.\n", "issue": "Use Artist Credits for tag data, but \"actual\" artist data for filenaming\nCurrently beets will always normalise [artist credit](https://musicbrainz.org/doc/Artist_Credit) data to the current artist name. However, I want to see when playing the music when, e.g., [Orgi-E](https://musicbrainz.org/artist/345fe3da-b2cb-4ad4-a1a5-43afc903663d) was credited as [Klamfyr](https://musicbrainz.org/release/d09b3568-e9cc-4458-bcf7-0c215cca75ce), but I still like the normalisation for file tree organisation purposes. This should probably be an option though, as other people will likely want to always normalise the name (and others might want to not normalise the name in the path as well).\n\n(Somewhat related morituri issues: thomasvs/morituri#80, thomasvs/morituri#48)\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# This file is part of beets.\n# Copyright 2016, Adrian Sampson.\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\n\"\"\"Facilities for automatically determining files' correct metadata.\n\"\"\"\n\nfrom __future__ import division, absolute_import, print_function\n\nfrom beets import logging\nfrom beets import config\n\n# Parts of external interface.\nfrom .hooks import AlbumInfo, TrackInfo, AlbumMatch, TrackMatch  # noqa\nfrom .match import tag_item, tag_album, Proposal  # noqa\nfrom .match import Recommendation  # noqa\n\n# Global logger.\nlog = logging.getLogger('beets')\n\n\n# Additional utilities for the main interface.\n\ndef apply_item_metadata(item, track_info):\n    \"\"\"Set an item's metadata from its matched TrackInfo object.\n    \"\"\"\n    item.artist = track_info.artist\n    item.artist_sort = track_info.artist_sort\n    item.artist_credit = track_info.artist_credit\n    item.title = track_info.title\n    item.mb_trackid = track_info.track_id\n    if track_info.artist_id:\n        item.mb_artistid = track_info.artist_id\n    if track_info.data_source:\n        item.data_source = track_info.data_source\n\n    if track_info.lyricist is not None:\n        item.lyricist = track_info.lyricist\n    if track_info.composer is not None:\n        item.composer = track_info.composer\n    if track_info.composer_sort is not None:\n        item.composer_sort = track_info.composer_sort\n    if track_info.arranger is not None:\n        item.arranger = track_info.arranger\n\n    # At the moment, the other metadata is left intact (including album\n    # and track number). Perhaps these should be emptied?\n\n\ndef apply_metadata(album_info, mapping):\n    \"\"\"Set the items' metadata to match an AlbumInfo object using a\n    mapping from Items to TrackInfo objects.\n    \"\"\"\n    for item, track_info in mapping.items():\n        # Album, artist, track count.\n        if track_info.artist:\n            item.artist = track_info.artist\n        else:\n            item.artist = album_info.artist\n        item.albumartist = album_info.artist\n        item.album = album_info.album\n\n        # Artist sort and credit names.\n        item.artist_sort = track_info.artist_sort or album_info.artist_sort\n        item.artist_credit = (track_info.artist_credit or\n                              album_info.artist_credit)\n        item.albumartist_sort = album_info.artist_sort\n        item.albumartist_credit = album_info.artist_credit\n\n        # Release date.\n        for prefix in '', 'original_':\n            if config['original_date'] and not prefix:\n                # Ignore specific release date.\n                continue\n\n            for suffix in 'year', 'month', 'day':\n                key = prefix + suffix\n                value = getattr(album_info, key) or 0\n\n                # If we don't even have a year, apply nothing.\n                if suffix == 'year' and not value:\n                    break\n\n                # Otherwise, set the fetched value (or 0 for the month\n                # and day if not available).\n                item[key] = value\n\n                # If we're using original release date for both fields,\n                # also set item.year = info.original_year, etc.\n                if config['original_date']:\n                    item[suffix] = value\n\n        # Title.\n        item.title = track_info.title\n\n        if config['per_disc_numbering']:\n            # We want to let the track number be zero, but if the medium index\n            # is not provided we need to fall back to the overall index.\n            if track_info.medium_index is not None:\n                item.track = track_info.medium_index\n            else:\n                item.track = track_info.index\n            item.tracktotal = track_info.medium_total or len(album_info.tracks)\n        else:\n            item.track = track_info.index\n            item.tracktotal = len(album_info.tracks)\n\n        # Disc and disc count.\n        item.disc = track_info.medium\n        item.disctotal = album_info.mediums\n\n        # MusicBrainz IDs.\n        item.mb_trackid = track_info.track_id\n        item.mb_albumid = album_info.album_id\n        if track_info.artist_id:\n            item.mb_artistid = track_info.artist_id\n        else:\n            item.mb_artistid = album_info.artist_id\n        item.mb_albumartistid = album_info.artist_id\n        item.mb_releasegroupid = album_info.releasegroup_id\n\n        # Compilation flag.\n        item.comp = album_info.va\n\n        # Miscellaneous metadata.\n        for field in ('albumtype',\n                      'label',\n                      'asin',\n                      'catalognum',\n                      'script',\n                      'language',\n                      'country',\n                      'albumstatus',\n                      'albumdisambig',\n                      'data_source',):\n            value = getattr(album_info, field)\n            if value is not None:\n                item[field] = value\n        if track_info.disctitle is not None:\n            item.disctitle = track_info.disctitle\n\n        if track_info.media is not None:\n            item.media = track_info.media\n\n        if track_info.lyricist is not None:\n            item.lyricist = track_info.lyricist\n        if track_info.composer is not None:\n            item.composer = track_info.composer\n        if track_info.composer_sort is not None:\n            item.composer_sort = track_info.composer_sort\n        if track_info.arranger is not None:\n            item.arranger = track_info.arranger\n\n        item.track_alt = track_info.track_alt\n", "path": "beets/autotag/__init__.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# This file is part of beets.\n# Copyright 2016, Adrian Sampson.\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\n\"\"\"Facilities for automatically determining files' correct metadata.\n\"\"\"\n\nfrom __future__ import division, absolute_import, print_function\n\nfrom beets import logging\nfrom beets import config\n\n# Parts of external interface.\nfrom .hooks import AlbumInfo, TrackInfo, AlbumMatch, TrackMatch  # noqa\nfrom .match import tag_item, tag_album, Proposal  # noqa\nfrom .match import Recommendation  # noqa\n\n# Global logger.\nlog = logging.getLogger('beets')\n\n\n# Additional utilities for the main interface.\n\ndef apply_item_metadata(item, track_info):\n    \"\"\"Set an item's metadata from its matched TrackInfo object.\n    \"\"\"\n    item.artist = track_info.artist\n    item.artist_sort = track_info.artist_sort\n    item.artist_credit = track_info.artist_credit\n    item.title = track_info.title\n    item.mb_trackid = track_info.track_id\n    if track_info.artist_id:\n        item.mb_artistid = track_info.artist_id\n    if track_info.data_source:\n        item.data_source = track_info.data_source\n\n    if track_info.lyricist is not None:\n        item.lyricist = track_info.lyricist\n    if track_info.composer is not None:\n        item.composer = track_info.composer\n    if track_info.composer_sort is not None:\n        item.composer_sort = track_info.composer_sort\n    if track_info.arranger is not None:\n        item.arranger = track_info.arranger\n\n    # At the moment, the other metadata is left intact (including album\n    # and track number). Perhaps these should be emptied?\n\n\ndef apply_metadata(album_info, mapping):\n    \"\"\"Set the items' metadata to match an AlbumInfo object using a\n    mapping from Items to TrackInfo objects.\n    \"\"\"\n    for item, track_info in mapping.items():\n        # Artist or artist credit.\n        if config['artist_credit']:\n            item.artist = (track_info.artist_credit or\n                           track_info.artist or\n                           album_info.artist_credit or\n                           album_info.artist)\n            item.albumartist = (album_info.artist_credit or\n                                album_info.artist)\n        else:\n            item.artist = (track_info.artist or album_info.artist)\n            item.albumartist = album_info.artist\n\n        # Album.\n        item.album = album_info.album\n\n        # Artist sort and credit names.\n        item.artist_sort = track_info.artist_sort or album_info.artist_sort\n        item.artist_credit = (track_info.artist_credit or\n                              album_info.artist_credit)\n        item.albumartist_sort = album_info.artist_sort\n        item.albumartist_credit = album_info.artist_credit\n\n        # Release date.\n        for prefix in '', 'original_':\n            if config['original_date'] and not prefix:\n                # Ignore specific release date.\n                continue\n\n            for suffix in 'year', 'month', 'day':\n                key = prefix + suffix\n                value = getattr(album_info, key) or 0\n\n                # If we don't even have a year, apply nothing.\n                if suffix == 'year' and not value:\n                    break\n\n                # Otherwise, set the fetched value (or 0 for the month\n                # and day if not available).\n                item[key] = value\n\n                # If we're using original release date for both fields,\n                # also set item.year = info.original_year, etc.\n                if config['original_date']:\n                    item[suffix] = value\n\n        # Title.\n        item.title = track_info.title\n\n        if config['per_disc_numbering']:\n            # We want to let the track number be zero, but if the medium index\n            # is not provided we need to fall back to the overall index.\n            if track_info.medium_index is not None:\n                item.track = track_info.medium_index\n            else:\n                item.track = track_info.index\n            item.tracktotal = track_info.medium_total or len(album_info.tracks)\n        else:\n            item.track = track_info.index\n            item.tracktotal = len(album_info.tracks)\n\n        # Disc and disc count.\n        item.disc = track_info.medium\n        item.disctotal = album_info.mediums\n\n        # MusicBrainz IDs.\n        item.mb_trackid = track_info.track_id\n        item.mb_albumid = album_info.album_id\n        if track_info.artist_id:\n            item.mb_artistid = track_info.artist_id\n        else:\n            item.mb_artistid = album_info.artist_id\n        item.mb_albumartistid = album_info.artist_id\n        item.mb_releasegroupid = album_info.releasegroup_id\n\n        # Compilation flag.\n        item.comp = album_info.va\n\n        # Miscellaneous metadata.\n        for field in ('albumtype',\n                      'label',\n                      'asin',\n                      'catalognum',\n                      'script',\n                      'language',\n                      'country',\n                      'albumstatus',\n                      'albumdisambig',\n                      'data_source',):\n            value = getattr(album_info, field)\n            if value is not None:\n                item[field] = value\n        if track_info.disctitle is not None:\n            item.disctitle = track_info.disctitle\n\n        if track_info.media is not None:\n            item.media = track_info.media\n\n        if track_info.lyricist is not None:\n            item.lyricist = track_info.lyricist\n        if track_info.composer is not None:\n            item.composer = track_info.composer\n        if track_info.composer_sort is not None:\n            item.composer_sort = track_info.composer_sort\n        if track_info.arranger is not None:\n            item.arranger = track_info.arranger\n\n        item.track_alt = track_info.track_alt\n", "path": "beets/autotag/__init__.py"}]}