This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (c) Copyright 2020 tripulse. | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bitstring import Bits | |
class SIGIO: | |
"""SIGIO is a binary-like format used by a person named 5IGI0 to interchange feelings. | |
The format is really limited to them and has no specification, with efforts of digging | |
it made this implementation possible.""" | |
@staticmethod | |
def encode(s): | |
return ''.join("'" if b else '-' for b in Bits(s.encode('ascii'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import zip_longest | |
from functools import partial | |
def grouper(iterable, n, fillvalue=None): | |
args = [iter(iterable)] * n | |
return zip_longest(*args, fillvalue=fillvalue) | |
def morsedec(s, bits=8, chars='.-') -> str: | |
return ''.join(chr(int(''.join(b), base=2)) for b in | |
grouper(map(lambda b: str(chars.index(b)), s), bits, '0')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
from functools import partial | |
def isbinaryfile(f, mode) -> bool: | |
"""Is a given file-like object `f` capable of handling | |
binary operations a given mode (read='r' or write='w').""" | |
if mode == 'r': | |
try: | |
return f.read(0) == b'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A reference implementation of the RKPI2 format based on the specification, | |
this module operates on NumPy arrays to input/output of samples. | |
This is a trivial example would be like this: | |
``` | |
>>> import rkpio | |
>>> import numpy as np | |
>>> out = rkpio.File('sine.rkp', 'w', | |
rkpio.Header(rkpio.Format.F32, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A high-level wrapper over libmp3lame C API (a high-quality | |
production grade MPEG Layer-III encoder). This excludes some | |
useless and undocumented routines which don't affect encoding | |
at all or not used often. | |
""" | |
from enum import IntEnum | |
from array import array | |
from os import name as _os_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import re | |
def _extract_client_id(): | |
for scrsrc in reversed(re.findall(r'<script[^>]+src="([^"]+)"', | |
requests.get('https://soundcloud.com').text)): | |
if (clid := re.search(r'client_id\s*:\s*"(?P<id>[0-9a-zA-Z]{32})"', | |
requests.get(scrsrc).text)): | |
return clid.groupdict()['id'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DCT is required for quantising coefficients, this always | |
# performs a orthonormal DCT and IDCT. | |
from scipy.fftpack import dctn,idctn | |
from numpy import any, clip, floor, array, asarray, zeros, round, resize | |
from functools import partial | |
# Explicitly specify that Type-II DCT is required. | |
dctn = partial(dctn, type=2, norm='ortho') | |
idctn = partial(idctn, type=2, norm='ortho') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Plugin for both encoding and decoding Suckless Farbfeld files | |
for the PIL library (compression not supported). | |
""" | |
from PIL import Image | |
from PIL.ImageFile import ImageFile | |
from struct import unpack, pack | |
class FarbfeldImageFile(ImageFile): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numpy==1.18.2 | |
zstandard==0.13.0 |