""" riffogg.py Extract embedded OGG files from RIFF/WAVE files. Works on both Python 2 and Python 3. Usage: riffogg.py input.wav output.ogg Copyright (C) 2014 Shiz Released under the terms of the WTFPL: see http://www.wtfpl.net/txt/copying/ for details. """ from __future__ import print_function import sys import os import struct RIFF_MAGIC = b'RIFF' WAVE_MAGIC = b'WAVE' OGG_MAGIC = b'OggS' # Chunks that contain chunks. META_CHUNKS = (b'RIFF', b'LIST') # Chunks that don't contain anything. GARBAGE_CHUNKS = (b'WAVE', b'INFO', b'adtl') def validate_header(f): """ Make sure opened file is a RIFF WAVE file and return its full length, or -1 if it isn't. """ f.seek(0, os.SEEK_SET) magic = f.read(4) if magic != RIFF_MAGIC: print('RIFF magic: expected {}, got {}'.format(RIFF_MAGIC, magic)) return -1 length = struct.unpack('