diff --git a/smalltag/_formats/_ogg.py b/smalltag/_formats/_ogg.py index 20aa72e..a67daa8 100644 --- a/smalltag/_formats/_ogg.py +++ b/smalltag/_formats/_ogg.py @@ -198,10 +198,13 @@ class _Ogg(SmallTag, tinytag._Ogg): def _crc_checksum(self, data: bytes) -> int: generator_polynomial = 0x04c11db7 crc = 0 + bitmask = 0xffffffff for byte in data: - byte ^= crc - crc = byte % generator_polynomial - - return crc + for i in range(8): + b = bitmask if byte & (1 << 7) != 0 else 0 + divide = bitmask if (crc & (1 << 31)) != 0 else 0 + crc = (crc << 1) ^ (generator_polynomial & (b ^ divide)) + byte <<= 1 + return crc & bitmask diff --git a/smalltag/smalltag.py b/smalltag/smalltag.py index 31d04ce..a2eebbd 100644 --- a/smalltag/smalltag.py +++ b/smalltag/smalltag.py @@ -15,7 +15,7 @@ UnsupportedFormatError = tinytag.UnsupportedFormatError class SmallTag(TinyTag): _file_extension_mapping: dict[tuple[str, ...], type[SmallTag]]= { (".mp1", ".mp2", ".mp3"): None, - ('.oga', '.ogg', '.opus', '.spx'): tinytag._Ogg, + ('.oga', '.ogg', '.opus', '.spx'): None, ('.wav',): tinytag._Wave, ('.flac',): tinytag._Flac, ('.wma',): tinytag._Wma, @@ -116,7 +116,8 @@ class SmallTag(TinyTag): # import formats after SmallTag definition to avoid circular imports # (this solution is stupid, but I don't know anything better.) -from ._formats import _ID3 # noqa +from ._formats import _ID3, _Ogg # noqa SmallTag._file_extension_mapping[(".mp1", ".mp2", ".mp3")] = _ID3 +SmallTag._file_extension_mapping[('.oga', '.ogg', '.opus', '.spx')] = _Ogg