Skip to content

Instantly share code, notes, and snippets.

@eliask
Created November 1, 2018 15:28
Show Gist options
  • Save eliask/64bfa506fb38da80a79df21a34a1015d to your computer and use it in GitHub Desktop.
Save eliask/64bfa506fb38da80a79df21a34a1015d to your computer and use it in GitHub Desktop.
Extract audio/video parts from a HAR file
import sys
import base64
import json
def main(path):
with open(path, 'rt') as fh:
j = json.load(fh)
for entry in j['log']['entries']:
if not 200 <= entry['response']['status'] < 300:
continue
content = entry['response']['content']
mime = content['mimeType']
print(entry['request']['url'], mime)
if mime.startswith('video/') or mime.startswith('audio/'):
yield content
if __name__ == '__main__':
for i,c in enumerate(main(sys.argv[-1])):
assert c['encoding'] == 'base64', c['encoding']
content = base64.b64decode(c['text'])
with open('%05d.bin' % i, 'wb') as fh:
fh.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment