Got it working.

(I did not understand the CRC algorithm used.)
This commit is contained in:
The Wobbler 2025-03-30 17:00:31 +02:00
parent de1594cf50
commit 5a693f2771
2 changed files with 10 additions and 6 deletions

View file

@ -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

View file

@ -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