#!/usr/bin/env python3 """Tests every stream in tools/stations.txt with ffprobe and lists the ones that don't play. Exit status 1 if any failed. Run with: python3 -I tools/check.py """ import os import subprocess import sys from concurrent.futures import ThreadPoolExecutor sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from build import stations # noqa: E402 def probe(station): chno, name, _, _, url = station cmd = ['ffprobe', '-v', 'error', '-rw_timeout', '15000000', '-user_agent', 'Kodi/21.2', '-show_entries', 'stream=codec_name,bit_rate', '-of', 'csv=p=0', url] try: r = subprocess.run(cmd, capture_output=True, text=True, timeout=30) out = (r.stdout + r.stderr).strip().splitlines() except subprocess.TimeoutExpired: out = ['timeout'] ok = bool(out) and out[0].split(',')[0] in ('aac', 'mp3', 'vorbis', 'opus', 'flac') return ok, '{:>6} {:<28} {}'.format(chno, name, out[0] if out else 'no output') def main(): with ThreadPoolExecutor(16) as pool: results = list(pool.map(probe, stations())) failed = [line for ok, line in results if not ok] for ok, line in results: print(('ok ' if ok else 'FAIL ') + line) print('{} of {} streams play'.format(len(results) - len(failed), len(results))) sys.exit(1 if failed else 0) if __name__ == '__main__': main()