# Buggy code
def __init__(self, xml_dom_fragment):
    self.track_type = xml_dom_fragment.attrib["type"]
    for el in xml_dom_fragment:
        node_name = el.tag.lower().strip().strip("_")
        if node_name == "id":
            node_name = "track_id"
        node_value = el.text
        other_node_name = "other_%s" % node_name
        if getattr(self, node_name) is None:
            setattr(self, node_name, node_value)
        else:
            if getattr(self, other_node_name) is None:
                setattr(
                    self,
                    other_node_name,
                    [
                        node_value,
                    ],
                )
            else:
                getattr(self, other_node_name).append(node_value)

    for o in [d for d in self.__dict__.keys() if d.startswith("other_")]:
        try:
            primary = o.replace("other_", "")
            setattr(self, primary, int(getattr(self, primary)))
        except:
            for v in getattr(self, o):
                try:
                    current = getattr(self, primary)
                    setattr(self, primary, int(v))
                    getattr(self, o).append(current)
                    break
                except:
                    pass


# Traceback (UnicodeDecodeError)
2019-06-07 16:18:01 ERROR    Thread_31 :: [6a21a60] Exception generated: 'utf-8' codec can't decode byte 0x94 in position 0: invalid start byte
Traceback (most recent call last):
File "/Users/ovidijus/Apps/Medusa/medusa/server/web/core/base.py", line 261, in async_call
result = function(**kwargs)
File "/Users/ovidijus/Apps/Medusa/medusa/server/web/core/error_logs.py", line 62, in submit_errors
results = self.issue_submitter.submit_github_issue(CheckVersion())
File "/Users/ovidijus/Apps/Medusa/medusa/issue_submitter.py", line 199, in submit_github_issue
return self.submit_issues(github, github_repo, loglines, similar_issues)
File "/Users/ovidijus/Apps/Medusa/medusa/issue_submitter.py", line 216, in submit_issues
gist = cls.create_gist(github, line)
File "/Users/ovidijus/Apps/Medusa/medusa/issue_submitter.py", line 75, in create_gist
context_loglines = logline.get_context_loglines()
File "/Users/ovidijus/Apps/Medusa/medusa/logger/__init__.py", line 448, in get_context_loglines
for logline in read_loglines(modification_time=start_timestamp):
File "/Users/ovidijus/Apps/Medusa/medusa/logger/__init__.py", line 166, in read_loglines
for line in reverse_readlines(f):
File "/Users/ovidijus/Apps/Medusa/medusa/logger/__init__.py", line 281, in reverse_readlines
for block in block_generator(filename, **block_generator_kws):
File "/Users/ovidijus/Apps/Medusa/medusa/logger/__init__.py", line 243, in blocks_r
block = file_obj.read(min(remaining_size, size))
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x94 in position 0: invalid start byte
2019-06-07 08:05:17 ERROR    SHOWQUEUE-REFRESH :: [6a21a60] 305075: Error while refreshing show Bungo Stray Dogs. Error: 'MediaInfo' object has no attribute 'xml_dom'
Traceback (most recent call last):
File "/Users/ovidijus/Apps/Medusa/ext/knowit/api.py", line 64, in know
result = provider.describe(video_path, context)
File "/Users/ovidijus/Apps/Medusa/ext/knowit/providers/mediainfo.py", line 296, in describe
video_path, self.executor.location, debug_data())
File "/Users/ovidijus/Apps/Medusa/ext/knowit/providers/mediainfo.py", line 289, in debug_data
xml = ensure_text(ElementTree.tostring(media_info.xml_dom)).replace('\r', '').replace('\n', '')
AttributeError: 'MediaInfo' object has no attribute 'xml_dom'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ovidijus/Apps/Medusa/medusa/show_queue.py", line 688, in run
self.show.refresh_dir()
File "/Users/ovidijus/Apps/Medusa/medusa/tv/series.py", line 1792, in refresh_dir
self.load_episodes_from_dir()
File "/Users/ovidijus/Apps/Medusa/medusa/tv/series.py", line 1053, in load_episodes_from_dir
cur_episode = self.make_ep_from_file(os.path.join(self.location, media_file))
File "/Users/ovidijus/Apps/Medusa/medusa/tv/series.py", line 1397, in make_ep_from_file
cur_ep.update_status_quality(filepath)
File "/Users/ovidijus/Apps/Medusa/medusa/tv/episode.py", line 2040, in update_status_quality
new_quality = Quality.name_quality(filepath, self.series.is_anime)
File "/Users/ovidijus/Apps/Medusa/medusa/common.py", line 284, in name_quality
return Quality._extend_quality(name)
File "/Users/ovidijus/Apps/Medusa/medusa/common.py", line 383, in _extend_quality
quality = Quality.quality_from_file_meta(file_path)
File "/Users/ovidijus/Apps/Medusa/medusa/common.py", line 405, in quality_from_file_meta
knowledge = knowit.know(file_path)
File "/Users/ovidijus/Apps/Medusa/ext/knowit/api.py", line 70, in know
raise KnowitException(debug_info(context=context, exc_info=True))
File "/Users/ovidijus/Apps/Medusa/ext/knowit/api.py", line 121, in debug_info
lines.append(debug_data())
File "/Users/ovidijus/Apps/Medusa/ext/knowit/providers/mediainfo.py", line 289, in debug_data
xml = ensure_text(ElementTree.tostring(media_info.xml_dom)).replace('\r', '').replace('\n', '')
AttributeError: 'MediaInfo' object has no attribute 'xml_dom'

# Fixed code
def __init__(self, xml_dom_fragment):
    self.xml_dom_fragment = xml_dom_fragment
    self.track_type = xml_dom_fragment.attrib["type"]
    for el in self.xml_dom_fragment:
        node_name = el.tag.lower().strip().strip("_")
        if node_name == "id":
            node_name = "track_id"
        node_value = el.text
        other_node_name = "other_%s" % node_name
        if getattr(self, node_name) is None:
            setattr(self, node_name, node_value)
        else:
            if getattr(self, other_node_name) is None:
                setattr(
                    self,
                    other_node_name,
                    [
                        node_value,
                    ],
                )
            else:
                getattr(self, other_node_name).append(node_value)

    for o in [d for d in self.__dict__.keys() if d.startswith("other_")]:
        try:
            primary = o.replace("other_", "")
            setattr(self, primary, int(getattr(self, primary)))
        except:
            for v in getattr(self, o):
                try:
                    current = getattr(self, primary)
                    setattr(self, primary, int(v))
                    getattr(self, o).append(current)
                    break
                except:
                    pass