Skip to content

Commit

Permalink
mod: Inherit MagicBytes directly from bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Dec 30, 2022
1 parent 03c30fd commit 5d1bbd7
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions plugins/mod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,13 @@ class StaticField:
fillchar: str = ' '


@dataclass
class MagicBytes:
id: bytes
class MagicBytes(bytes):
offset: int = 0

def __len__(self):
return len(self.id)

def __eq__(self, other) -> bool:
return self.id == other
def __new__(cls, value, offset: int=0):
self = super().__new__(cls, value)
self.offset = offset
return self


class ModuleFile(File):
Expand Down Expand Up @@ -251,7 +248,7 @@ class MEDFile(ModuleFile):
def _parse_file(self, f: RawIOBase, metadata: Metadata, magic: MagicBytes):
# TODO: Extract songname
super()._parse_file(f, metadata, magic)
format = self._decode_text(magic.id)
format = self._decode_text(magic)
metadata['~format'] = self.NAME + ' (' + format + ')'


Expand Down Expand Up @@ -296,7 +293,7 @@ class ULTFile(ModuleFile):

def _parse_file(self, f: RawIOBase, metadata: Metadata, magic: MagicBytes):
super()._parse_file(f, metadata, magic)
format = self._decode_text(magic.id)
format = self._decode_text(magic)
metadata['~format'] = self.NAME + ' (' + format + ')'


Expand Down

0 comments on commit 5d1bbd7

Please sign in to comment.