diff --git a/acoustid.py b/acoustid.py index c7cb8d8..31be692 100644 --- a/acoustid.py +++ b/acoustid.py @@ -21,6 +21,9 @@ import requests import contextlib import errno +import sys +if sys.byteorder == 'big': + import struct try: import audioread @@ -206,6 +209,17 @@ def _api_request(url, params, timeout=None): except ValueError: raise WebServiceError('response is not valid JSON') +def byteswap(s): + """Swaps the endianness of the bytestring s, which must be an array + of shorts (16-bit signed integers). + """ + assert len(s) % 2 == 0 + parts = [] + for i in range(0, len(s), 2): + chunk = s[i:i + 2] + newchunk = struct.pack('>h', *struct.unpack('= endposition: break