"""Bounded documentary capture, never a recording/bug-fix test.""" import hashlib import json import math import os from pathlib import Path import struct import subprocess import time import urllib.request import wave from datetime import datetime, timezone from PIL import Image root = Path.cwd() scratch = Path(os.environ['RUNNER_TEMP']) / 'techanmeldelser-audacity402-capture' scratch.mkdir() base = 'https://github.com/audacity/audacity/releases/download/Audacity-4.0.2/' binary_name = 'audacity-linux-4.0.2-x86_64.AppImage' binary_sha = 'a5f8787aa13cdb500a60fc013403b986776876b960cca962bc6e7fff066172f3' source_name = 'audacity-sources-4.0.2.tar.xz' source_sha = '4799c2ce2deabacf2be8d6d6b3c5a5621bcd3aacf7c1c38bd0a3f2598f1034c0' source_commit = '7472497768314bcd4c641ef6dc91e366d92b2fcc' output = root / 'src/assets/article-heroes/audacity-402-autosave-projektfiler' output.mkdir(parents=True, exist_ok=True) def now(): return datetime.now(timezone.utc).isoformat() def download(url, limit): with urllib.request.urlopen(url, timeout=60) as response: assert response.status == 200 raw = response.read(limit + 1) assert len(raw) <= limit return raw manifest = download(base + 'CHECKSUMS.txt', 200_000) assert hashlib.sha256(manifest).hexdigest() == '215366182477b8917880fd050f6e6efa634e0aa6383f460d01486a05122364c6' assert any(binary_sha in line and binary_name in line for line in manifest.decode().splitlines()) assert any(source_sha in line and source_name in line for line in manifest.decode().splitlines()) binary = download(base + binary_name, 100_000_000) assert len(binary) == 73726456 and hashlib.sha256(binary).hexdigest() == binary_sha appimage = scratch / binary_name appimage.write_bytes(binary) appimage.chmod(0o755) subprocess.run([str(appimage), '--appimage-extract'], cwd=scratch, stdout=subprocess.DEVNULL, check=True) exe = scratch / 'squashfs-root/AppRun' with urllib.request.urlopen(urllib.request.Request(base + source_name, method='HEAD'), timeout=60) as response: assert response.status == 200 source_available_at = now() license_url = f'https://raw.githubusercontent.com/audacity/audacity/{source_commit}/LICENSE.txt' license_raw = download(license_url, 200_000) assert hashlib.sha1(b'blob ' + str(len(license_raw)).encode() + b'\0' + license_raw).hexdigest() == 'da463be6f109f2b2ba8540b84694c59cfe8d2c9f' license_path = root / 'docs/editorial/image-rights/audacity-402-LICENSE-original.txt' license_path.write_bytes(license_raw) notices = [] for p in sorted((scratch / 'squashfs-root').rglob('*')): if p.is_file() and not p.is_symlink() and any(s in p.name.lower() for s in ('license', 'copying', 'copyright', 'notice')): raw = p.read_bytes() if len(raw) < 2_000_000: try: notices.append({'path': str(p.relative_to(scratch / 'squashfs-root')), 'sha256': hashlib.sha256(raw).hexdigest(), 'text': raw.decode('utf-8')}) except UnicodeDecodeError: pass notices_path = root / 'docs/editorial/image-rights/audacity-402-bundled-notices.json' notices_path.write_text(json.dumps(notices, indent=2) + '\n') framework_license_url = 'https://raw.githubusercontent.com/musescore/muse_framework/dc29e8c4dde7bb7de379f74f19a71034e889099f/LICENSE.txt' framework_license = download(framework_license_url, 200_000) assert hashlib.sha256(framework_license).hexdigest() == '7929094812b45ce65aa5fd3dee2332be18533b3d69bc11d876602226d30c82cc' framework_path = root / 'docs/editorial/image-rights/audacity-402-framework-LICENSE-original.txt' framework_path.write_bytes(framework_license) font_match = subprocess.check_output(['fc-match', '-f', '%{family} | %{style} | %{file}\n', 'sans-serif'], text=True) font_notices = [] for p in sorted(Path('/usr/share/doc').glob('fonts*/copyright')): raw = p.read_bytes() font_notices.append({'path': str(p), 'sha256': hashlib.sha256(raw).hexdigest(), 'text': raw.decode('utf-8')}) assert font_notices font_notices_path = root / 'docs/editorial/image-rights/audacity-402-capture-system-font-notices.json' font_notices_path.write_text(json.dumps({'fontconfigSansResolution': font_match, 'notices': font_notices}, indent=2) + '\n') # Our own deterministic local tone, not microphone input, speech or copyrighted music. example = scratch / 'Lokalt-lydeksempel.wav' with wave.open(str(example), 'wb') as wav: wav.setnchannels(1) wav.setsampwidth(2) wav.setframerate(48000) samples = bytearray() for i in range(48000 * 12): t = i / 48000 envelope = 0.25 * (0.6 + 0.4 * math.sin(2 * math.pi * 0.7 * t)) sample = int(32767 * envelope * (math.sin(2 * math.pi * 220 * t) + 0.3 * math.sin(2 * math.pi * 440 * t))) samples.extend(struct.pack('